DrishtiSharma commited on
Commit
b255649
Β·
verified Β·
1 Parent(s): fff2b0a

Update app1.py

Browse files
Files changed (1) hide show
  1. app1.py +13 -14
app1.py CHANGED
@@ -54,8 +54,10 @@ if pdf_source == "Upload a PDF file":
54
  st.session_state.vector_created = False
55
 
56
  elif pdf_source == "Enter a PDF URL":
57
- pdf_url = st.text_input("Enter PDF URL:", value = "https://arxiv.org/pdf/2406.06998")
58
- if pdf_url and not st.session_state.pdf_path:
 
 
59
  with st.spinner("Downloading PDF..."):
60
  try:
61
  response = requests.get(pdf_url)
@@ -63,15 +65,20 @@ elif pdf_source == "Enter a PDF URL":
63
  st.session_state.pdf_path = "temp.pdf"
64
  with open(st.session_state.pdf_path, "wb") as f:
65
  f.write(response.content)
 
 
66
  st.session_state.pdf_loaded = False
67
  st.session_state.chunked = False
68
  st.session_state.vector_created = False
 
 
69
  st.success("βœ… PDF Downloaded Successfully!")
70
  else:
71
  st.error("❌ Failed to download PDF. Check the URL.")
72
  except Exception as e:
73
  st.error(f"❌ Error downloading PDF: {e}")
74
 
 
75
  # Step 2: Load & Process PDF (Only Once)
76
  if st.session_state.pdf_path and not st.session_state.pdf_loaded:
77
  with st.spinner("Loading PDF..."):
@@ -280,21 +287,13 @@ if query:
280
  final_output = context_management_chain({"context":context,"retriever_query":query,"query":query})
281
 
282
  st.subheader('final_output["relevancy_response"]')
283
- st.json(final_output["relevancy_response"] )
284
 
285
  st.subheader('final_output["context_number"]')
286
- st.json(final_output["context_number"])
287
 
288
  st.subheader('final_output["relevant_contexts"]')
289
- st.json(final_output["relevant_contexts"])
290
 
291
  st.subheader('final_output["final_response"]')
292
- st.json(final_output["final_response"])
293
-
294
-
295
-
296
-
297
-
298
-
299
-
300
-
 
54
  st.session_state.vector_created = False
55
 
56
  elif pdf_source == "Enter a PDF URL":
57
+ pdf_url = st.text_input("Enter PDF URL:", value="https://arxiv.org/pdf/2406.06998", key="pdf_url", on_change=lambda: st.session_state.update(trigger_download=True))
58
+
59
+ # Button OR Enter key will trigger download
60
+ if st.button("Download and Process PDF") or st.session_state.get("trigger_download", False):
61
  with st.spinner("Downloading PDF..."):
62
  try:
63
  response = requests.get(pdf_url)
 
65
  st.session_state.pdf_path = "temp.pdf"
66
  with open(st.session_state.pdf_path, "wb") as f:
67
  f.write(response.content)
68
+
69
+ # Reset states
70
  st.session_state.pdf_loaded = False
71
  st.session_state.chunked = False
72
  st.session_state.vector_created = False
73
+ st.session_state.trigger_download = False # Reset trigger
74
+
75
  st.success("βœ… PDF Downloaded Successfully!")
76
  else:
77
  st.error("❌ Failed to download PDF. Check the URL.")
78
  except Exception as e:
79
  st.error(f"❌ Error downloading PDF: {e}")
80
 
81
+
82
  # Step 2: Load & Process PDF (Only Once)
83
  if st.session_state.pdf_path and not st.session_state.pdf_loaded:
84
  with st.spinner("Loading PDF..."):
 
287
  final_output = context_management_chain({"context":context,"retriever_query":query,"query":query})
288
 
289
  st.subheader('final_output["relevancy_response"]')
290
+ st.write(final_output["relevancy_response"] )
291
 
292
  st.subheader('final_output["context_number"]')
293
+ st.write(final_output["context_number"])
294
 
295
  st.subheader('final_output["relevant_contexts"]')
296
+ st.write(final_output["relevant_contexts"])
297
 
298
  st.subheader('final_output["final_response"]')
299
+ st.write(final_output["final_response"])