Spaces:
Runtime error
Runtime error
ivan-savchuk
commited on
Commit
β’
7eec8cd
1
Parent(s):
a8e52be
Update app.py
Browse files
app.py
CHANGED
@@ -15,17 +15,23 @@ class DocumentSearch:
|
|
15 |
sbert: encoder
|
16 |
sbert: cross_encoder
|
17 |
'''
|
18 |
-
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
20 |
# loading docs and corresponding urls
|
21 |
with open(labels_path, 'r') as json_file:
|
22 |
-
self.docs = json.load(
|
23 |
# loading sbert encoder model
|
24 |
-
self.encoder = SentenceTransformer(
|
25 |
# loading faiss index
|
26 |
-
self.index = faiss.read_index(
|
27 |
# loading sbert cross_encoder
|
28 |
-
self.cross_encoder = CrossEncoder(
|
29 |
|
30 |
def search(self, query: str, k: int) -> list:
|
31 |
# get vector representation of text query
|
@@ -45,25 +51,9 @@ class DocumentSearch:
|
|
45 |
return sorted(results, key=lambda x: x['score'], reverse=True)[:k]
|
46 |
|
47 |
|
48 |
-
@st.cache(suppress_st_warning=True)
|
49 |
-
def get_surfer():
|
50 |
-
enc_path = "ivan-savchuk/msmarco-distilbert-dot-v5-tuned-full-v1"
|
51 |
-
idx_path = "idx_vectors.index"
|
52 |
-
cross_enc_path = "ivan-savchuk/cross-encoder-ms-marco-MiniLM-L-12-v2-tuned_mediqa-v1"
|
53 |
-
docs_path = "docs.json"
|
54 |
-
# get instance of DocumentSearch class
|
55 |
-
surfer = DocumentSearch(
|
56 |
-
labels_path=docs_path,
|
57 |
-
encoder_path=enc_path,
|
58 |
-
index_path=idx_path,
|
59 |
-
cross_encoder_path=cross_enc_path
|
60 |
-
)
|
61 |
-
return surfer
|
62 |
-
|
63 |
-
|
64 |
if __name__ == "__main__":
|
65 |
# get instance of DocumentSearch class
|
66 |
-
surfer =
|
67 |
# streamlit part starts here with title
|
68 |
st.title('Medical Search')
|
69 |
# input form
|
|
|
15 |
sbert: encoder
|
16 |
sbert: cross_encoder
|
17 |
'''
|
18 |
+
# we mention pass to every file that needed to run models
|
19 |
+
# and search over our data
|
20 |
+
enc_path = "ivan-savchuk/msmarco-distilbert-dot-v5-tuned-full-v1"
|
21 |
+
idx_path = "idx_vectors.index"
|
22 |
+
cross_enc_path = "ivan-savchuk/cross-encoder-ms-marco-MiniLM-L-12-v2-tuned_mediqa-v1"
|
23 |
+
docs_path = "docs.json"
|
24 |
+
|
25 |
+
def __init__(self):
|
26 |
# loading docs and corresponding urls
|
27 |
with open(labels_path, 'r') as json_file:
|
28 |
+
self.docs = json.load(DocumentSearch.docs_path)
|
29 |
# loading sbert encoder model
|
30 |
+
self.encoder = SentenceTransformer(DocumentSearch.enc_path)
|
31 |
# loading faiss index
|
32 |
+
self.index = faiss.read_index(DocumentSearch.idx_path)
|
33 |
# loading sbert cross_encoder
|
34 |
+
self.cross_encoder = CrossEncoder(DocumentSearch.cross_enc_path)
|
35 |
|
36 |
def search(self, query: str, k: int) -> list:
|
37 |
# get vector representation of text query
|
|
|
51 |
return sorted(results, key=lambda x: x['score'], reverse=True)[:k]
|
52 |
|
53 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
54 |
if __name__ == "__main__":
|
55 |
# get instance of DocumentSearch class
|
56 |
+
surfer = DocumentSearch()
|
57 |
# streamlit part starts here with title
|
58 |
st.title('Medical Search')
|
59 |
# input form
|