Waseem771 commited on
Commit
878a75a
·
verified ·
1 Parent(s): 36ae953

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -3,7 +3,7 @@ import streamlit as st
3
  import fitz # PyMuPDF
4
  import openai
5
  from dotenv import load_dotenv
6
- import pinecone
7
 
8
  # Load the environment variables from the .env file
9
  load_dotenv()
@@ -12,7 +12,7 @@ pinecone_api_key = os.getenv('PINECONE_API_KEY')
12
  pinecone_environment = os.getenv('PINECONE_ENVIRONMENT')
13
 
14
  # Initialize Pinecone
15
- pinecone.init(api_key=pinecone_api_key, environment=pinecone_environment)
16
 
17
  # Streamlit app
18
  st.title("Chat with Your Document")
@@ -34,9 +34,14 @@ if uploaded_file is not None:
34
 
35
  # Create a Pinecone vector store
36
  index_name = "pdf-analysis"
37
- if index_name not in pinecone.list_indexes():
38
- pinecone.create_index(index_name, dimension=512)
39
- vector_store = pinecone.Index(index_name)
 
 
 
 
 
40
 
41
  # Add the PDF text to the vector store
42
  vector_store.upsert([(str(i), openai.Embedding.create(input=pdf_text)["data"][0]["embedding"]) for i in range(len(pdf_text))])
 
3
  import fitz # PyMuPDF
4
  import openai
5
  from dotenv import load_dotenv
6
+ from pinecone import Pinecone, ServerlessSpec
7
 
8
  # Load the environment variables from the .env file
9
  load_dotenv()
 
12
  pinecone_environment = os.getenv('PINECONE_ENVIRONMENT')
13
 
14
  # Initialize Pinecone
15
+ pc = Pinecone(api_key=pinecone_api_key)
16
 
17
  # Streamlit app
18
  st.title("Chat with Your Document")
 
34
 
35
  # Create a Pinecone vector store
36
  index_name = "pdf-analysis"
37
+ if index_name not in pc.list_indexes().names():
38
+ pc.create_index(
39
+ name=index_name,
40
+ dimension=512,
41
+ metric='euclidean',
42
+ spec=ServerlessSpec(cloud='aws', region=pinecone_environment)
43
+ )
44
+ vector_store = pc.Index(index_name)
45
 
46
  # Add the PDF text to the vector store
47
  vector_store.upsert([(str(i), openai.Embedding.create(input=pdf_text)["data"][0]["embedding"]) for i in range(len(pdf_text))])