add manual and timer for reset project
Browse files
app.py
CHANGED
|
@@ -24,13 +24,24 @@ def category_radio(cat):
|
|
| 24 |
return 'cs.RO'
|
| 25 |
|
| 26 |
def comment_radio(com):
|
| 27 |
-
if com == '
|
| 28 |
-
return 'CVPR'
|
| 29 |
-
else:
|
| 30 |
return None
|
|
|
|
|
|
|
| 31 |
|
| 32 |
-
def
|
| 33 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 34 |
|
| 35 |
with gr.Blocks() as demo:
|
| 36 |
|
|
@@ -45,7 +56,7 @@ with gr.Blocks() as demo:
|
|
| 45 |
radio_arxiv_category_name.change(fn = category_radio, inputs= radio_arxiv_category_name, outputs= arxiv_category_name)
|
| 46 |
|
| 47 |
arxiv_comment_query = gr.State([])
|
| 48 |
-
radio_arxiv_comment_query = gr.Radio(['CVPR', 'None'], label="ArXiv Comment Query")
|
| 49 |
radio_arxiv_comment_query.change(fn = comment_radio, inputs= radio_arxiv_comment_query, outputs= arxiv_comment_query)
|
| 50 |
|
| 51 |
threshold = gr.Slider(minimum= 0.70, maximum= 0.99, label="Similarity Score Threshold")
|
|
@@ -54,10 +65,19 @@ with gr.Blocks() as demo:
|
|
| 54 |
|
| 55 |
rec_output = gr.Markdown(label = "Recommended Papers")
|
| 56 |
|
|
|
|
|
|
|
| 57 |
init_btn = gr.Button("Initialize")
|
| 58 |
|
| 59 |
rec_btn = gr.Button("Recommend")
|
| 60 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
@init_btn.click(inputs= [zotero_api_key, zotero_library_id, zotero_tag], outputs= [init_output])
|
| 62 |
def init(zotero_api_key, zotero_library_id, zotero_tag, hf_api_key = HF_API_KEY, pinecone_api_key = PINECONE_API_KEY, index_name = INDEX_NAME, namespace_name = NAMESPACE_NAME):
|
| 63 |
|
|
@@ -95,16 +115,4 @@ with gr.Blocks() as demo:
|
|
| 95 |
|
| 96 |
return results
|
| 97 |
|
| 98 |
-
file_path = 'arxiv-scrape.csv'
|
| 99 |
-
if os.path.exists(file_path):
|
| 100 |
-
os.remove(file_path)
|
| 101 |
-
logging.info(f"{file_path} has been deleted. Delete this part of the code if you want to persist recommended papers.")
|
| 102 |
-
|
| 103 |
-
api_key = os.getenv('PINECONE_API_KEY')
|
| 104 |
-
index = os.getenv('INDEX_NAME')
|
| 105 |
-
pc = Pinecone(api_key = api_key)
|
| 106 |
-
if index in pc.list_indexes().names():
|
| 107 |
-
pc.delete_index(index)
|
| 108 |
-
logging.info(f"{index} index has been deleted from the vectordb. Delete this part of the code if you want to persist recommended papers.")
|
| 109 |
-
|
| 110 |
demo.launch(share = True)
|
|
|
|
| 24 |
return 'cs.RO'
|
| 25 |
|
| 26 |
def comment_radio(com):
|
| 27 |
+
if com == 'None':
|
|
|
|
|
|
|
| 28 |
return None
|
| 29 |
+
else:
|
| 30 |
+
return com
|
| 31 |
|
| 32 |
+
def reset_project():
|
| 33 |
+
file_path = 'arxiv-scrape.csv'
|
| 34 |
+
if os.path.exists(file_path):
|
| 35 |
+
os.remove(file_path)
|
| 36 |
+
logging.info(f"{file_path} has been deleted. Delete reset_project() if you want to persist recommended papers.")
|
| 37 |
+
|
| 38 |
+
api_key = os.getenv('PINECONE_API_KEY')
|
| 39 |
+
index = os.getenv('INDEX_NAME')
|
| 40 |
+
pc = Pinecone(api_key = api_key)
|
| 41 |
+
if index in pc.list_indexes().names():
|
| 42 |
+
pc.delete_index(index)
|
| 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 |
|
|
|
|
| 56 |
radio_arxiv_category_name.change(fn = category_radio, inputs= radio_arxiv_category_name, outputs= arxiv_category_name)
|
| 57 |
|
| 58 |
arxiv_comment_query = gr.State([])
|
| 59 |
+
radio_arxiv_comment_query = gr.Radio(['CVPR', 'ACL', 'TACL', 'JAIR', 'IJRR', 'None'], label="ArXiv Comment Query")
|
| 60 |
radio_arxiv_comment_query.change(fn = comment_radio, inputs= radio_arxiv_comment_query, outputs= arxiv_comment_query)
|
| 61 |
|
| 62 |
threshold = gr.Slider(minimum= 0.70, maximum= 0.99, label="Similarity Score Threshold")
|
|
|
|
| 65 |
|
| 66 |
rec_output = gr.Markdown(label = "Recommended Papers")
|
| 67 |
|
| 68 |
+
reset_output = gr.Markdown(label = "Reset Declaration")
|
| 69 |
+
|
| 70 |
init_btn = gr.Button("Initialize")
|
| 71 |
|
| 72 |
rec_btn = gr.Button("Recommend")
|
| 73 |
|
| 74 |
+
reset_btn = gr.Button("Reset")
|
| 75 |
+
|
| 76 |
+
timer = gr.Timer(interval=600)
|
| 77 |
+
timer.tick(reset_project)
|
| 78 |
+
|
| 79 |
+
reset_btn.click(fn = reset_project, inputs= [], outputs= [reset_output])
|
| 80 |
+
|
| 81 |
@init_btn.click(inputs= [zotero_api_key, zotero_library_id, zotero_tag], outputs= [init_output])
|
| 82 |
def init(zotero_api_key, zotero_library_id, zotero_tag, hf_api_key = HF_API_KEY, pinecone_api_key = PINECONE_API_KEY, index_name = INDEX_NAME, namespace_name = NAMESPACE_NAME):
|
| 83 |
|
|
|
|
| 115 |
|
| 116 |
return results
|
| 117 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 118 |
demo.launch(share = True)
|