Spaces:
Sleeping
Sleeping
viboognesh-doaz
commited on
Commit
·
5c3777d
1
Parent(s):
fbd44bb
Fixed some errors
Browse files
app.py
CHANGED
@@ -7,22 +7,31 @@ from dotenv import load_dotenv
|
|
7 |
load_dotenv()
|
8 |
|
9 |
def upload_file():
|
10 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
11 |
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
12 |
if uploaded_file is None:
|
13 |
-
|
|
|
14 |
else:
|
15 |
st.info(f"Uploaded PDF: {uploaded_file.name}")
|
16 |
if st.button("Process PDF"):
|
17 |
with st.spinner("Processing PDF..."):
|
18 |
-
st.session_state.
|
19 |
st.success("PDF processed successfully!")
|
|
|
|
|
20 |
|
21 |
def ask_question():
|
22 |
-
if st.session_state.
|
|
|
23 |
if user_question := st.chat_input("Ask a question"):
|
24 |
with st.spinner("Retrieving information..."):
|
25 |
-
response, retrieved_image_path_list = retrieve_and_query(user_question, st.session_state.
|
26 |
print(retrieved_image_path_list)
|
27 |
st.write("Retrieved Context:")
|
28 |
for node in response.source_nodes:
|
@@ -40,8 +49,8 @@ def ask_question():
|
|
40 |
|
41 |
|
42 |
def main():
|
43 |
-
if "
|
44 |
-
st.session_state.
|
45 |
page_names_to_funcs = {
|
46 |
"Upload File": upload_file,
|
47 |
"Chat": ask_question
|
|
|
7 |
load_dotenv()
|
8 |
|
9 |
def upload_file():
|
10 |
+
if not st.session_state.filename_and_retriever_engine:
|
11 |
+
st.title("Upload File to chat with file")
|
12 |
+
else:
|
13 |
+
st.title(f"File {st.session_state.filename_and_retriever_engine[0]} loaded.")
|
14 |
+
st.info("Click on Chat in sidebar")
|
15 |
+
st.info("Upload another file if you want to chat with a different pdf")
|
16 |
uploaded_file = st.file_uploader("Choose a PDF file", type="pdf")
|
17 |
if uploaded_file is None:
|
18 |
+
if not st.session_state.filename_and_retriever_engine:
|
19 |
+
st.info("Please upload a PDF file.")
|
20 |
else:
|
21 |
st.info(f"Uploaded PDF: {uploaded_file.name}")
|
22 |
if st.button("Process PDF"):
|
23 |
with st.spinner("Processing PDF..."):
|
24 |
+
st.session_state.filename_and_retriever_engine = uploaded_file.name, process_pdf(uploaded_file)
|
25 |
st.success("PDF processed successfully!")
|
26 |
+
st.success("Click on Chat in sidebar")
|
27 |
+
|
28 |
|
29 |
def ask_question():
|
30 |
+
if st.session_state.filename_and_retriever_engine :
|
31 |
+
st.title(f"Chat with {st.session_state.filename_and_retriever_engine[0]}")
|
32 |
if user_question := st.chat_input("Ask a question"):
|
33 |
with st.spinner("Retrieving information..."):
|
34 |
+
response, retrieved_image_path_list = retrieve_and_query(user_question, st.session_state.filename_and_retriever_engine[1])
|
35 |
print(retrieved_image_path_list)
|
36 |
st.write("Retrieved Context:")
|
37 |
for node in response.source_nodes:
|
|
|
49 |
|
50 |
|
51 |
def main():
|
52 |
+
if "filename_and_retriever_engine" not in st.session_state:
|
53 |
+
st.session_state.filename_and_retriever_engine = None
|
54 |
page_names_to_funcs = {
|
55 |
"Upload File": upload_file,
|
56 |
"Chat": ask_question
|