Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -2,34 +2,30 @@ import gradio as gr
|
|
2 |
import os
|
3 |
import zipfile
|
4 |
import uuid
|
5 |
-
from
|
6 |
-
from
|
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 |
-
|
16 |
index_name = "whatsapp-chat-index"
|
17 |
|
18 |
-
if index_name not in
|
19 |
-
|
20 |
name=index_name,
|
21 |
-
dimension=
|
22 |
-
metric="cosine"
|
23 |
-
spec=ServerlessSpec(
|
24 |
-
cloud='aws',
|
25 |
-
region='us-east-1'
|
26 |
-
)
|
27 |
)
|
28 |
|
29 |
-
index =
|
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()
|