Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -4,16 +4,14 @@ import uuid
|
|
4 |
import streamlit as st
|
5 |
from dotenv import load_dotenv
|
6 |
from qdrant_client import models
|
7 |
-
from langchain_community.vectorstores import Qdrant
|
8 |
|
9 |
-
|
10 |
-
from utils import setup_openai_embeddings,setup_qdrant_client,delete_collection,is_document_embedded
|
11 |
from embed import embed_documents_into_qdrant
|
12 |
-
from preprocess import split_documents,update_metadata,load_documents_OCR
|
13 |
-
from retrieve import retrieve_documents,retrieve_documents_from_collection
|
14 |
from summarize import summarize_documents
|
15 |
|
16 |
-
|
17 |
load_dotenv()
|
18 |
|
19 |
def main():
|
@@ -23,6 +21,12 @@ def main():
|
|
23 |
if 'uploaded_collection_name' not in st.session_state:
|
24 |
st.session_state['uploaded_collection_name'] = None
|
25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
if uploaded_files:
|
27 |
if st.sidebar.button("Add Docs to Data Bank"):
|
28 |
files_info = save_uploaded_files(uploaded_files)
|
@@ -34,7 +38,7 @@ def main():
|
|
34 |
|
35 |
pages = {
|
36 |
"Lex Document Summarization": page_summarization,
|
37 |
-
"Chat with
|
38 |
"Chat with Uploaded Docs": page_chat_with_uploaded_docs
|
39 |
}
|
40 |
|
@@ -75,7 +79,10 @@ def page_summarization(uploaded_files):
|
|
75 |
st.session_state['summaries'][original_name] = summary # Store summary in session state
|
76 |
except Exception as e:
|
77 |
st.error(f"Failed to summarize {original_name}: {str(e)}")
|
78 |
-
|
|
|
|
|
|
|
79 |
|
80 |
def page_qna(uploaded_files):
|
81 |
"""Page for Q&A functionality."""
|
@@ -84,10 +91,14 @@ def page_qna(uploaded_files):
|
|
84 |
if st.button('Get Answer'):
|
85 |
if user_query:
|
86 |
answer = handle_query(user_query)
|
|
|
87 |
st.write(answer)
|
88 |
else:
|
89 |
st.error("Please enter a question to get an answer.")
|
90 |
-
|
|
|
|
|
|
|
91 |
def page_chat_with_uploaded_docs(uploaded_files):
|
92 |
"""Page for chatting with uploaded documents."""
|
93 |
st.title("Chat with Uploaded Documents")
|
@@ -95,9 +106,13 @@ def page_chat_with_uploaded_docs(uploaded_files):
|
|
95 |
if st.button('Get Answer'):
|
96 |
if user_query:
|
97 |
answer = handle_uploaded_docs_query(user_query, st.session_state['uploaded_collection_name'])
|
|
|
98 |
st.write(answer)
|
99 |
else:
|
100 |
st.error("Please enter a question to get an answer.")
|
|
|
|
|
|
|
101 |
|
102 |
if st.session_state['uploaded_collection_name']:
|
103 |
if st.button('Delete Embedded Collection'):
|
@@ -179,4 +194,4 @@ def delete_collection(collection_name, qdrant_url, qdrant_api_key):
|
|
179 |
print("Failed to delete collection:", e)
|
180 |
|
181 |
if __name__ == "__main__":
|
182 |
-
main()
|
|
|
4 |
import streamlit as st
|
5 |
from dotenv import load_dotenv
|
6 |
from qdrant_client import models
|
|
|
7 |
|
8 |
+
from utils import setup_openai_embeddings, setup_qdrant_client, delete_collection, is_document_embedded
|
|
|
9 |
from embed import embed_documents_into_qdrant
|
10 |
+
from preprocess import split_documents, update_metadata, load_documents_OCR
|
11 |
+
from retrieve import retrieve_documents, retrieve_documents_from_collection
|
12 |
from summarize import summarize_documents
|
13 |
|
14 |
+
# Load environment variables
|
15 |
load_dotenv()
|
16 |
|
17 |
def main():
|
|
|
21 |
if 'uploaded_collection_name' not in st.session_state:
|
22 |
st.session_state['uploaded_collection_name'] = None
|
23 |
|
24 |
+
# Initialize session state for storing answers if not already set
|
25 |
+
if 'data_bank_answer' not in st.session_state:
|
26 |
+
st.session_state['data_bank_answer'] = None
|
27 |
+
if 'uploaded_docs_answer' not in st.session_state:
|
28 |
+
st.session_state['uploaded_docs_answer'] = None
|
29 |
+
|
30 |
if uploaded_files:
|
31 |
if st.sidebar.button("Add Docs to Data Bank"):
|
32 |
files_info = save_uploaded_files(uploaded_files)
|
|
|
38 |
|
39 |
pages = {
|
40 |
"Lex Document Summarization": page_summarization,
|
41 |
+
"Chat with Data Bank": page_qna,
|
42 |
"Chat with Uploaded Docs": page_chat_with_uploaded_docs
|
43 |
}
|
44 |
|
|
|
79 |
st.session_state['summaries'][original_name] = summary # Store summary in session state
|
80 |
except Exception as e:
|
81 |
st.error(f"Failed to summarize {original_name}: {str(e)}")
|
82 |
+
if original_name in st.session_state['summaries']:
|
83 |
+
st.text_area("", value=st.session_state['summaries'][original_name], height=1000, key=f"summary_{original_name}")
|
84 |
+
else:
|
85 |
+
st.error(f"No summary found for {original_name}. Please click the summarize button.")
|
86 |
|
87 |
def page_qna(uploaded_files):
|
88 |
"""Page for Q&A functionality."""
|
|
|
91 |
if st.button('Get Answer'):
|
92 |
if user_query:
|
93 |
answer = handle_query(user_query)
|
94 |
+
st.session_state['data_bank_answer'] = answer # Store the answer in session state
|
95 |
st.write(answer)
|
96 |
else:
|
97 |
st.error("Please enter a question to get an answer.")
|
98 |
+
# Display stored answer if it exists
|
99 |
+
if st.session_state['data_bank_answer']:
|
100 |
+
st.write(st.session_state['data_bank_answer'])
|
101 |
+
|
102 |
def page_chat_with_uploaded_docs(uploaded_files):
|
103 |
"""Page for chatting with uploaded documents."""
|
104 |
st.title("Chat with Uploaded Documents")
|
|
|
106 |
if st.button('Get Answer'):
|
107 |
if user_query:
|
108 |
answer = handle_uploaded_docs_query(user_query, st.session_state['uploaded_collection_name'])
|
109 |
+
st.session_state['uploaded_docs_answer'] = answer # Store the answer in session state
|
110 |
st.write(answer)
|
111 |
else:
|
112 |
st.error("Please enter a question to get an answer.")
|
113 |
+
# Display stored answer if it exists
|
114 |
+
if st.session_state['uploaded_docs_answer']:
|
115 |
+
st.write(st.session_state['uploaded_docs_answer'])
|
116 |
|
117 |
if st.session_state['uploaded_collection_name']:
|
118 |
if st.button('Delete Embedded Collection'):
|
|
|
194 |
print("Failed to delete collection:", e)
|
195 |
|
196 |
if __name__ == "__main__":
|
197 |
+
main()
|