Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -15,18 +15,19 @@ import pinecone
|
|
15 |
import streamlit as st
|
16 |
import shutil
|
17 |
|
|
|
18 |
OPENAI_API_KEY = ''
|
19 |
PINECONE_API_KEY = ''
|
20 |
PINECONE_API_ENV = ''
|
21 |
pinecone_index_name = ''
|
22 |
chroma_collection_name = ''
|
23 |
persist_directory = ''
|
24 |
-
chat_history = []
|
25 |
docsearch_ready = False
|
26 |
directory_name = 'tmp_docs'
|
27 |
langchain.verbose = False
|
28 |
|
29 |
|
|
|
30 |
def save_file(files):
|
31 |
# Remove existing files in the directory
|
32 |
if os.path.exists(directory_name):
|
@@ -46,6 +47,7 @@ def save_file(files):
|
|
46 |
shutil.copyfileobj(file, f)
|
47 |
|
48 |
|
|
|
49 |
def load_files():
|
50 |
all_texts = []
|
51 |
n_files = 0
|
@@ -76,13 +78,14 @@ def load_files():
|
|
76 |
return all_texts, n_texts
|
77 |
|
78 |
|
79 |
-
|
|
|
80 |
if use_pinecone:
|
81 |
docsearch = Pinecone.from_texts(
|
82 |
-
[t.page_content for t in
|
83 |
else:
|
84 |
docsearch = Chroma.from_documents(
|
85 |
-
|
86 |
return docsearch
|
87 |
|
88 |
|
@@ -165,6 +168,7 @@ with col3:
|
|
165 |
persist_directory = "./vectorstore"
|
166 |
|
167 |
if pinecone_index_name or chroma_collection_name:
|
|
|
168 |
if r_ingest.lower() == 'yes':
|
169 |
files = st.file_uploader('Upload Files', accept_multiple_files=True)
|
170 |
if files:
|
@@ -188,7 +192,8 @@ if docsearch_ready:
|
|
188 |
|
189 |
st.title('Chatbot')
|
190 |
# Get user input
|
191 |
-
query = st.
|
|
|
192 |
if query:
|
193 |
# Generate a reply based on the user input and chat history
|
194 |
reply, source = get_response(query, chat_history)
|
|
|
15 |
import streamlit as st
|
16 |
import shutil
|
17 |
|
18 |
+
|
19 |
OPENAI_API_KEY = ''
|
20 |
PINECONE_API_KEY = ''
|
21 |
PINECONE_API_ENV = ''
|
22 |
pinecone_index_name = ''
|
23 |
chroma_collection_name = ''
|
24 |
persist_directory = ''
|
|
|
25 |
docsearch_ready = False
|
26 |
directory_name = 'tmp_docs'
|
27 |
langchain.verbose = False
|
28 |
|
29 |
|
30 |
+
@st.cache_data()
|
31 |
def save_file(files):
|
32 |
# Remove existing files in the directory
|
33 |
if os.path.exists(directory_name):
|
|
|
47 |
shutil.copyfileobj(file, f)
|
48 |
|
49 |
|
50 |
+
@st.cache_data()
|
51 |
def load_files():
|
52 |
all_texts = []
|
53 |
n_files = 0
|
|
|
78 |
return all_texts, n_texts
|
79 |
|
80 |
|
81 |
+
@st.cache_resource()
|
82 |
+
def ingest(_all_texts, use_pinecone, _embeddings, pinecone_index_name, chroma_collection_name, persist_directory):
|
83 |
if use_pinecone:
|
84 |
docsearch = Pinecone.from_texts(
|
85 |
+
[t.page_content for t in _all_texts], _embeddings, index_name=pinecone_index_name) # add namespace=pinecone_namespace if provided
|
86 |
else:
|
87 |
docsearch = Chroma.from_documents(
|
88 |
+
_all_texts, _embeddings, collection_name=chroma_collection_name, persist_directory=persist_directory)
|
89 |
return docsearch
|
90 |
|
91 |
|
|
|
168 |
persist_directory = "./vectorstore"
|
169 |
|
170 |
if pinecone_index_name or chroma_collection_name:
|
171 |
+
chat_history = []
|
172 |
if r_ingest.lower() == 'yes':
|
173 |
files = st.file_uploader('Upload Files', accept_multiple_files=True)
|
174 |
if files:
|
|
|
192 |
|
193 |
st.title('Chatbot')
|
194 |
# Get user input
|
195 |
+
query = st.text_area('Enter your question:', height=10,
|
196 |
+
placeholder='Summarize the context.')
|
197 |
if query:
|
198 |
# Generate a reply based on the user input and chat history
|
199 |
reply, source = get_response(query, chat_history)
|