pratikshahp commited on
Commit
dd80727
·
verified ·
1 Parent(s): 224354c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -2,34 +2,30 @@ import gradio as gr
2
  import os
3
  import zipfile
4
  import uuid
5
- from langchain_huggingface import HuggingFaceEmbeddings
6
- from pinecone import Pinecone, ServerlessSpec
7
- from langchain_community.document_loaders import WhatsAppChatLoader
8
  from langchain.text_splitter import RecursiveCharacterTextSplitter
9
  from dotenv import load_dotenv
 
10
 
11
  load_dotenv()
12
 
13
  # Initialize Pinecone and the index outside the function
14
  pinecone_key = os.getenv("PINECONE_API_KEY")
15
- pc = Pinecone(api_key=pinecone_key)
16
  index_name = "whatsapp-chat-index"
17
 
18
- if index_name not in pc.list_indexes().names():
19
- pc.create_index(
20
  name=index_name,
21
- dimension=768, # change as per embedding model
22
- metric="cosine",
23
- spec=ServerlessSpec(
24
- cloud='aws',
25
- region='us-east-1'
26
- )
27
  )
28
 
29
- index = pc.Index(index_name)
30
 
31
  # Initialize Hugging Face embeddings
32
- embeddings = HuggingFaceEmbeddings()
33
 
34
  # Maximum allowed chunk size in bytes (4MB)
35
  MAX_CHUNK_SIZE = 4 * 1024 * 1024
@@ -109,4 +105,4 @@ interface = gr.Interface(
109
  )
110
 
111
  if __name__ == "__main__":
112
- interface.launch()
 
2
  import os
3
  import zipfile
4
  import uuid
5
+ from langchain.embeddings import HuggingFaceEmbeddings
6
+ from langchain.document_loaders import WhatsAppChatLoader
 
7
  from langchain.text_splitter import RecursiveCharacterTextSplitter
8
  from dotenv import load_dotenv
9
+ import pinecone
10
 
11
  load_dotenv()
12
 
13
  # Initialize Pinecone and the index outside the function
14
  pinecone_key = os.getenv("PINECONE_API_KEY")
15
+ pinecone.init(api_key=pinecone_key, environment='us-west1-gcp')
16
  index_name = "whatsapp-chat-index"
17
 
18
+ if index_name not in pinecone.list_indexes():
19
+ pinecone.create_index(
20
  name=index_name,
21
+ dimension=384, # change as per embedding model
22
+ metric="cosine"
 
 
 
 
23
  )
24
 
25
+ index = pinecone.Index(index_name)
26
 
27
  # Initialize Hugging Face embeddings
28
+ embeddings = HuggingFaceEmbeddings(model_name="sentence-transformers/all-MiniLM-L6-v2")
29
 
30
  # Maximum allowed chunk size in bytes (4MB)
31
  MAX_CHUNK_SIZE = 4 * 1024 * 1024
 
105
  )
106
 
107
  if __name__ == "__main__":
108
+ interface.launch()