Pijush2023 commited on
Commit
b1c78f7
·
verified ·
1 Parent(s): 663f47f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -3
app.py CHANGED
@@ -36,6 +36,33 @@ pc = Pinecone(api_key=os.environ['PINECONE_API_KEY'])
36
  # Define index name and parameters
37
  index_name = "italy-kg"
38
  vectorstore = PineconeVectorStore(index_name=index_name, embedding=embeddings)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
39
  llm=OpenAI(temperature=0,openai_api_key=openai_api_key)
40
 
41
 
@@ -179,10 +206,15 @@ def process_pdf(pdf_file, uploaded_documents):
179
  return table_data, f"Uploaded {len(chunks)} chunks to the vector database."
180
 
181
  # Gradio Interface
182
- with gr.Blocks() as demo:
183
- gr.Markdown("# PDF Uploader to Pinecone with Query Response")
184
-
185
  with gr.Row():
 
 
 
 
 
 
 
186
  with gr.Column():
187
  response_output = gr.Textbox(label="Response:", lines=10, max_lines=10)
188
  query_input = gr.Textbox(label="Enter your query:")
 
36
  # Define index name and parameters
37
  index_name = "italy-kg"
38
  vectorstore = PineconeVectorStore(index_name=index_name, embedding=embeddings)
39
+
40
+ #Dynamic Pinecone Creation
41
+
42
+ # Function to initialize Pinecone dynamically and create index if it doesn't exist
43
+ def init_pinecone(api_key, index_name):
44
+ pinecone.init(api_key=api_key, environment="us-east-1")
45
+ pc = Pinecone(api_key=api_key)
46
+
47
+ # Check if index exists, create if not
48
+ if index_name not in pc.list_indexes():
49
+ pc.create_index(
50
+ name=index_name,
51
+ dimension=1536,
52
+ metric="cosine",
53
+ spec=ServerlessSpec(
54
+ cloud="aws",
55
+ region="us-east-1"
56
+ ),
57
+ deletion_protection="disabled"
58
+ )
59
+ vectorstore = PineconeVectorStore(index_name=index_name, embedding=embeddings)
60
+ return vectorstore
61
+
62
+
63
+
64
+
65
+
66
  llm=OpenAI(temperature=0,openai_api_key=openai_api_key)
67
 
68
 
 
206
  return table_data, f"Uploaded {len(chunks)} chunks to the vector database."
207
 
208
  # Gradio Interface
209
+ with gr.Blocks() as demo:
 
 
210
  with gr.Row():
211
+ with gr.Column():
212
+ # Add Pinecone Index and API Key fields side by side
213
+ pinecone_index_input = gr.Textbox(label="Pinecone Index Name", placeholder="Enter Pinecone Index Name")
214
+ with gr.Column():
215
+ pinecone_api_key_input = gr.Textbox(label="Pinecone API Key", placeholder="Enter Pinecone API Key")
216
+
217
+ with gr.Row():
218
  with gr.Column():
219
  response_output = gr.Textbox(label="Response:", lines=10, max_lines=10)
220
  query_input = gr.Textbox(label="Enter your query:")