Weedoo commited on
Commit
868658d
1 Parent(s): e632772

add deletion of csv file and index created during a session

Browse files
Files changed (2) hide show
  1. app.py +13 -0
  2. utils.py +2 -1
app.py CHANGED
@@ -2,6 +2,7 @@ import logging
2
  import os
3
  import gradio as gr
4
  import pandas as pd
 
5
  from utils import get_zotero_ids, get_arxiv_papers, get_hf_embeddings, upload_to_pinecone, get_new_papers, recommend_papers
6
 
7
  HF_API_KEY = os.getenv('HF_API_KEY')
@@ -94,4 +95,16 @@ with gr.Blocks() as demo:
94
 
95
  return results
96
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  demo.launch(share = True)
 
2
  import os
3
  import gradio as gr
4
  import pandas as pd
5
+ from pinecone import Pinecone
6
  from utils import get_zotero_ids, get_arxiv_papers, get_hf_embeddings, upload_to_pinecone, get_new_papers, recommend_papers
7
 
8
  HF_API_KEY = os.getenv('HF_API_KEY')
 
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)
utils.py CHANGED
@@ -60,7 +60,7 @@ def get_hf_embeddings(api_key, df):
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
- print(str(response.status_code) + 'This part needs an update, causing KeyError 0')
64
  if response.status_code == 503:
65
  response = requests.post(API_URL, headers=headers, json={"inputs": title_abs, "wait_for_model": True})
66
 
@@ -82,6 +82,7 @@ def upload_to_pinecone(api_key, index, namespace, embeddings, dim, df):
82
  name=index,
83
  dimension=dim,
84
  metric="cosine",
 
85
  spec=ServerlessSpec(
86
  cloud='aws',
87
  region='us-east-1'
 
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
+ print(str(response.status_code) + 'This part needs an update, causing KeyError 0 ')
64
  if response.status_code == 503:
65
  response = requests.post(API_URL, headers=headers, json={"inputs": title_abs, "wait_for_model": True})
66
 
 
82
  name=index,
83
  dimension=dim,
84
  metric="cosine",
85
+ deletion_protection="disabled",
86
  spec=ServerlessSpec(
87
  cloud='aws',
88
  region='us-east-1'