Spaces:
Running
Running
bardicreels
commited on
Commit
•
0574041
1
Parent(s):
1f06e31
Update app.py
Browse files
app.py
CHANGED
@@ -76,34 +76,17 @@ def handle_query(query):
|
|
76 |
st.title("(PDF) Information and Inference")
|
77 |
st.markdown("Retrieval-Augmented Generation")
|
78 |
|
79 |
-
|
80 |
-
|
81 |
-
st.
|
|
|
|
|
82 |
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
if pdf_source == "Upload":
|
88 |
-
uploaded_file = st.file_uploader("Upload your PDF Files and Click on the Submit & Process Button")
|
89 |
-
if st.button("Submit & Process"):
|
90 |
-
with st.spinner("Processing..."):
|
91 |
-
filepath = os.path.join(DATA_DIR, "uploaded_pdf.pdf")
|
92 |
-
with open(filepath, "wb") as f:
|
93 |
-
f.write(uploaded_file.getbuffer())
|
94 |
-
displayPDF(filepath) # Display the uploaded PDF
|
95 |
-
data_ingestion() # Process PDF every time new file is uploaded
|
96 |
-
st.success("Done")
|
97 |
-
else:
|
98 |
-
selected_pdf = st.selectbox("Choose a preloaded PDF", PRELOADED_PDFS)
|
99 |
-
if st.button("Load Selected PDF"):
|
100 |
-
with st.spinner("Processing..."):
|
101 |
-
filepath = os.path.join(DATA_DIR, selected_pdf)
|
102 |
-
displayPDF(filepath) # Display the selected PDF
|
103 |
-
data_ingestion() # Process the selected PDF
|
104 |
-
st.success("Done")
|
105 |
|
106 |
-
user_prompt = st.chat_input("Ask me anything about the content of the
|
107 |
if user_prompt:
|
108 |
st.session_state.messages.append({'role': 'user', "content": user_prompt})
|
109 |
response = handle_query(user_prompt)
|
|
|
76 |
st.title("(PDF) Information and Inference")
|
77 |
st.markdown("Retrieval-Augmented Generation")
|
78 |
|
79 |
+
# Automatically load all PDFs from the data directory
|
80 |
+
if 'pdfs_loaded' not in st.session_state:
|
81 |
+
with st.spinner("Loading PDFs..."):
|
82 |
+
data_ingestion()
|
83 |
+
st.session_state.pdfs_loaded = True
|
84 |
|
85 |
+
if 'messages' not in st.session_state:
|
86 |
+
preloaded_pdfs_list = ", ".join(PRELOADED_PDFS) if PRELOADED_PDFS else "No PDFs available"
|
87 |
+
st.session_state.messages = [{'role': 'assistant', "content": f'Hello! I have loaded the following PDFs: {preloaded_pdfs_list}. Ask me anything about their content.'}]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
88 |
|
89 |
+
user_prompt = st.chat_input("Ask me anything about the content of the PDFs:")
|
90 |
if user_prompt:
|
91 |
st.session_state.messages.append({'role': 'user', "content": user_prompt})
|
92 |
response = handle_query(user_prompt)
|