Spaces:
Running
Running
Update app.py
#2
by
DrugKnowledge
- opened
app.py
CHANGED
|
@@ -20,6 +20,24 @@ os.makedirs(EMB_DIR, exist_ok=True)
|
|
| 20 |
MODEL_NAME = "all-MiniLM-L6-v2"
|
| 21 |
model = SentenceTransformer(MODEL_NAME)
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
# ================== ุชุญู
ูู ู
ู Drive ==================
|
| 24 |
def download_from_drive(file_id, output):
|
| 25 |
if not os.path.exists(output):
|
|
|
|
| 20 |
MODEL_NAME = "all-MiniLM-L6-v2"
|
| 21 |
model = SentenceTransformer(MODEL_NAME)
|
| 22 |
|
| 23 |
+
def build_or_load_embeddings(df, name):
|
| 24 |
+
path = embeddings_path(name)
|
| 25 |
+
if os.path.exists(path):
|
| 26 |
+
try:
|
| 27 |
+
with open(path,"rb") as f:
|
| 28 |
+
emb = pickle.load(f)
|
| 29 |
+
if len(emb) == len(df):
|
| 30 |
+
return emb
|
| 31 |
+
except Exception:
|
| 32 |
+
pass
|
| 33 |
+
texts = df["Title"].astype(str).tolist()
|
| 34 |
+
emb = model.encode(texts, convert_to_numpy=True, show_progress_bar=True)
|
| 35 |
+
with open(path,"wb") as f:
|
| 36 |
+
pickle.dump(emb,f)
|
| 37 |
+
return emb
|
| 38 |
+
|
| 39 |
+
books_embeddings = build_or_load_embeddings(books_df,"books")
|
| 40 |
+
theses_embeddings = build_or_load_embeddings(theses_df,"theses")
|
| 41 |
# ================== ุชุญู
ูู ู
ู Drive ==================
|
| 42 |
def download_from_drive(file_id, output):
|
| 43 |
if not os.path.exists(output):
|