update options input for huggingface and update exception handling for app.py
Browse files
app.py
CHANGED
|
@@ -43,6 +43,12 @@ def reset_project():
|
|
| 43 |
logging.info(f"{index} index has been deleted from the vectordb. Delete reset_project() if you want to persist recommended papers.")
|
| 44 |
return f"{file_path} has been deleted.<br />{index} index has been deleted from the vectordb.<br />"
|
| 45 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
with gr.Blocks() as demo:
|
| 47 |
|
| 48 |
zotero_api_key = gr.Textbox(label="Zotero API Key")
|
|
@@ -87,13 +93,8 @@ with gr.Blocks() as demo:
|
|
| 87 |
ids = get_zotero_ids(zotero_api_key, zotero_library_id, zotero_tag)
|
| 88 |
|
| 89 |
df = get_arxiv_papers(ids)
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
except KeyError as e:
|
| 93 |
-
print(e)
|
| 94 |
-
print('\n Resetting project...')
|
| 95 |
-
reset_project()
|
| 96 |
-
exit()
|
| 97 |
|
| 98 |
feedback = upload_to_pinecone(pinecone_api_key, index_name, namespace_name, embeddings, dim, df)
|
| 99 |
|
|
|
|
| 43 |
logging.info(f"{index} index has been deleted from the vectordb. Delete reset_project() if you want to persist recommended papers.")
|
| 44 |
return f"{file_path} has been deleted.<br />{index} index has been deleted from the vectordb.<br />"
|
| 45 |
|
| 46 |
+
def reset_csv():
|
| 47 |
+
file_path = 'arxiv-scrape.csv'
|
| 48 |
+
if os.path.exists(file_path):
|
| 49 |
+
os.remove(file_path)
|
| 50 |
+
logging.info(f"{file_path} has been deleted. Delete reset_project() if you want to persist recommended papers.")
|
| 51 |
+
|
| 52 |
with gr.Blocks() as demo:
|
| 53 |
|
| 54 |
zotero_api_key = gr.Textbox(label="Zotero API Key")
|
|
|
|
| 93 |
ids = get_zotero_ids(zotero_api_key, zotero_library_id, zotero_tag)
|
| 94 |
|
| 95 |
df = get_arxiv_papers(ids)
|
| 96 |
+
|
| 97 |
+
embeddings, dim = get_hf_embeddings(hf_api_key, df)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
feedback = upload_to_pinecone(pinecone_api_key, index_name, namespace_name, embeddings, dim, df)
|
| 100 |
|
utils.py
CHANGED
|
@@ -59,10 +59,10 @@ def get_hf_embeddings(api_key, df):
|
|
| 59 |
API_URL = "https://api-inference.huggingface.co/models/malteos/scincl"
|
| 60 |
headers = {"Authorization": f"Bearer {api_key}"}
|
| 61 |
|
| 62 |
-
response = requests.post(API_URL, headers=headers, json={"inputs": title_abs, "wait_for_model": False})
|
| 63 |
-
|
| 64 |
if response.status_code == 503:
|
| 65 |
-
response = requests.post(API_URL, headers=headers, json={"inputs": title_abs, "wait_for_model": True})
|
| 66 |
|
| 67 |
embeddings = response.json()
|
| 68 |
|
|
@@ -102,9 +102,9 @@ def get_new_papers(df):
|
|
| 102 |
if df.empty:
|
| 103 |
return 'No New Papers Found'
|
| 104 |
else:
|
| 105 |
-
df_main = pd.concat([df_main, df], ignore_index= True)
|
| 106 |
-
df_main.drop_duplicates(inplace= True)
|
| 107 |
-
df_main.to_csv('arxiv-scrape.csv', index = False)
|
| 108 |
return df
|
| 109 |
|
| 110 |
def recommend_papers(api_key, index, namespace, embeddings, df, threshold):
|
|
|
|
| 59 |
API_URL = "https://api-inference.huggingface.co/models/malteos/scincl"
|
| 60 |
headers = {"Authorization": f"Bearer {api_key}"}
|
| 61 |
|
| 62 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": title_abs, "options": {"wait_for_model": False}})
|
| 63 |
+
|
| 64 |
if response.status_code == 503:
|
| 65 |
+
response = requests.post(API_URL, headers=headers, json={"inputs": title_abs, "options": {"wait_for_model": True}})
|
| 66 |
|
| 67 |
embeddings = response.json()
|
| 68 |
|
|
|
|
| 102 |
if df.empty:
|
| 103 |
return 'No New Papers Found'
|
| 104 |
else:
|
| 105 |
+
# df_main = pd.concat([df_main, df], ignore_index= True) #persistence of recommended paper removed for demo
|
| 106 |
+
# df_main.drop_duplicates(inplace= True)
|
| 107 |
+
# df_main.to_csv('arxiv-scrape.csv', index = False)
|
| 108 |
return df
|
| 109 |
|
| 110 |
def recommend_papers(api_key, index, namespace, embeddings, df, threshold):
|