Pijush2023 commited on
Commit
c4f331d
·
verified ·
1 Parent(s): e0a04c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -42
app.py CHANGED
@@ -32,32 +32,11 @@ embeddings = OpenAIEmbeddings(api_key=openai_api_key)
32
 
33
  # Initialize Pinecone with PineconeGRPC
34
  from pinecone import Pinecone
35
- # 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
 
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
 
@@ -207,13 +186,7 @@ def process_pdf(pdf_file, uploaded_documents):
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)
@@ -230,14 +203,4 @@ with gr.Blocks() as demo:
230
  process_button = gr.Button("Process PDF and Upload")
231
  process_button.click(fn=process_pdf, inputs=[file_input, gr.State([])], outputs=[document_table, output_textbox])
232
 
233
-
234
- # When the process button is clicked, dynamically initialize Pinecone with API key and index name
235
- def process_with_dynamic_pinecone(pdf_file, uploaded_documents, pinecone_index_name, pinecone_api_key):
236
- vectorstore = init_pinecone(pinecone_api_key, pinecone_index_name)
237
- return process_pdf(pdf_file, uploaded_documents, vectorstore)
238
-
239
- process_button.click(fn=process_with_dynamic_pinecone,
240
- inputs=[file_input, gr.State([]), pinecone_index_input, pinecone_api_key_input],
241
- outputs=[document_table, output_textbox])
242
-
243
  demo.launch(show_error=True)
 
32
 
33
  # Initialize Pinecone with PineconeGRPC
34
  from pinecone import Pinecone
35
+ 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
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
 
41
 
42
 
 
186
 
187
  # Gradio Interface
188
  with gr.Blocks() as demo:
189
+
 
 
 
 
 
 
190
  with gr.Row():
191
  with gr.Column():
192
  response_output = gr.Textbox(label="Response:", lines=10, max_lines=10)
 
203
  process_button = gr.Button("Process PDF and Upload")
204
  process_button.click(fn=process_pdf, inputs=[file_input, gr.State([])], outputs=[document_table, output_textbox])
205
 
 
 
 
 
 
 
 
 
 
 
206
  demo.launch(show_error=True)