DrishtiSharma commited on
Commit
f1054fc
·
verified ·
1 Parent(s): cf5a94b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -23
app.py CHANGED
@@ -168,10 +168,8 @@ if __name__ == "__main__":
168
  st.session_state.loaded_pdf_path = None
169
  if "chain" not in st.session_state:
170
  st.session_state.chain = None
171
- if "messages" not in st.session_state:
172
- st.session_state.messages = [{"role": "assistant", "content": "Hello! How can I assist you with this patent?"}]
173
 
174
- # Load and process patent
175
  if st.button("Load and Process Patent"):
176
  if not patent_link:
177
  st.warning("Please enter a valid Google patent link.")
@@ -194,33 +192,35 @@ if __name__ == "__main__":
194
  else:
195
  st.write("✅ File already downloaded.")
196
 
197
- # Generate preview if not already stored
198
- if st.session_state.LOADED_PATENT != patent_number:
199
- st.write("🖼️ Generating PDF preview...")
200
- preview_image_path = preview_pdf(pdf_path)
201
- if preview_image_path:
202
- st.session_state.pdf_preview = preview_image_path
203
- else:
204
- st.warning("Failed to generate PDF preview.")
205
- st.session_state.pdf_preview = None
206
-
207
- # Load the chain and store metadata
208
- st.session_state.chain = load_chain(pdf_path)
209
- st.session_state.LOADED_PATENT = patent_number
210
- st.session_state.loaded_pdf_path = pdf_path
211
- st.session_state.messages = [{"role": "assistant", "content": "Hello! How can I assist you with this patent?"}]
212
- st.success("🚀 Document successfully loaded!")
213
  else:
214
- st.info(" This patent is already loaded.")
 
 
 
 
 
 
 
 
 
 
 
215
 
216
  # Display the PDF preview if available
217
  if st.session_state.pdf_preview:
218
  st.image(st.session_state.pdf_preview, caption="First Page Preview", use_container_width=True)
219
 
220
  # Display previous chat messages
221
- for message in st.session_state.messages:
222
- with st.chat_message(message["role"]):
223
- st.markdown(message["content"])
 
224
 
225
  # User input for questions
226
  if st.session_state.chain:
 
168
  st.session_state.loaded_pdf_path = None
169
  if "chain" not in st.session_state:
170
  st.session_state.chain = None
 
 
171
 
172
+ # Button to load and process patent
173
  if st.button("Load and Process Patent"):
174
  if not patent_link:
175
  st.warning("Please enter a valid Google patent link.")
 
192
  else:
193
  st.write("✅ File already downloaded.")
194
 
195
+ # Generate PDF preview
196
+ st.write("🖼️ Generating PDF preview...")
197
+ preview_image_path = preview_pdf(pdf_path)
198
+ if preview_image_path:
199
+ st.session_state.pdf_preview = preview_image_path
200
+ st.image(preview_image_path, caption="First Page Preview", use_container_width=True)
 
 
 
 
 
 
 
 
 
 
201
  else:
202
+ st.warning("Failed to generate PDF preview.")
203
+ st.session_state.pdf_preview = None
204
+
205
+ # Load the document into the system
206
+ st.write("🔄 Loading document into the system...")
207
+ st.session_state.chain = load_chain(pdf_path)
208
+ st.session_state.LOADED_PATENT = patent_number
209
+ st.session_state.loaded_pdf_path = pdf_path
210
+
211
+ # Initialize messages AFTER processing
212
+ st.session_state.messages = [{"role": "assistant", "content": "Hello! How can I assist you with this patent?"}]
213
+ st.success("🚀 Document successfully loaded! You can now start asking questions.")
214
 
215
  # Display the PDF preview if available
216
  if st.session_state.pdf_preview:
217
  st.image(st.session_state.pdf_preview, caption="First Page Preview", use_container_width=True)
218
 
219
  # Display previous chat messages
220
+ if "messages" in st.session_state:
221
+ for message in st.session_state.messages:
222
+ with st.chat_message(message["role"]):
223
+ st.markdown(message["content"])
224
 
225
  # User input for questions
226
  if st.session_state.chain: