Sharath1036 commited on
Commit
c5c6a6a
·
1 Parent(s): fd59124

[bug]: modified pdf not showing

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -25,11 +25,17 @@ with tab1:
25
  uploaded_pdf = st.file_uploader("Upload a PDF", type=["pdf"])
26
  question = st.text_input("Ask a question about the PDF:")
27
  if uploaded_pdf:
28
- st.info(f"PDF uploaded: {uploaded_pdf.name}, size: {uploaded_pdf.size} bytes")
29
- if uploaded_pdf and question:
 
 
 
 
 
 
30
  try:
31
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
32
- tmp_file.write(uploaded_pdf.read())
33
  tmp_path = tmp_file.name
34
  st.info(f"Saved PDF to temp file: {tmp_path}")
35
  pdf_agent = PDFAgent(pdf_path=tmp_path)
@@ -42,6 +48,7 @@ with tab1:
42
  import traceback
43
  st.text(traceback.format_exc())
44
 
 
45
  with tab2:
46
  st.header("Weather Agent")
47
  location = st.text_input("Enter a location for weather info: e.g. Mumbai")
 
25
  uploaded_pdf = st.file_uploader("Upload a PDF", type=["pdf"])
26
  question = st.text_input("Ask a question about the PDF:")
27
  if uploaded_pdf:
28
+ if 'uploaded_pdf_data' not in st.session_state:
29
+ st.session_state.uploaded_pdf_data = uploaded_pdf.read()
30
+ st.session_state.uploaded_pdf_name = uploaded_pdf.name
31
+ st.session_state.uploaded_pdf_size = uploaded_pdf.size
32
+
33
+ st.info(f"PDF uploaded: {st.session_state.uploaded_pdf_name}, size: {st.session_state.uploaded_pdf_size} bytes")
34
+
35
+ if 'uploaded_pdf_data' in st.session_state and question:
36
  try:
37
  with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
38
+ tmp_file.write(st.session_state.uploaded_pdf_data)
39
  tmp_path = tmp_file.name
40
  st.info(f"Saved PDF to temp file: {tmp_path}")
41
  pdf_agent = PDFAgent(pdf_path=tmp_path)
 
48
  import traceback
49
  st.text(traceback.format_exc())
50
 
51
+
52
  with tab2:
53
  st.header("Weather Agent")
54
  location = st.text_input("Enter a location for weather info: e.g. Mumbai")