Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -272,39 +272,39 @@ if __name__ == "__main__":
|
|
| 272 |
# File handling
|
| 273 |
pdf_path = os.path.join(tempfile.gettempdir(), f"{patent_number}.pdf")
|
| 274 |
if not os.path.isfile(pdf_path):
|
| 275 |
-
st.
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
| 279 |
-
|
| 280 |
-
|
| 281 |
-
|
| 282 |
else:
|
| 283 |
st.write("✅ File already downloaded.")
|
| 284 |
|
| 285 |
# Generate PDF preview only if not already displayed
|
| 286 |
if not st.session_state.get("pdf_preview_displayed", False):
|
| 287 |
-
st.
|
| 288 |
-
|
| 289 |
-
|
| 290 |
-
|
| 291 |
-
|
| 292 |
-
|
| 293 |
-
|
| 294 |
-
|
| 295 |
-
|
| 296 |
|
| 297 |
# Load the document into the system
|
| 298 |
-
st.
|
| 299 |
-
|
| 300 |
-
|
| 301 |
-
|
| 302 |
-
|
| 303 |
-
|
| 304 |
-
|
| 305 |
-
|
| 306 |
-
|
| 307 |
-
|
| 308 |
|
| 309 |
# Display previous chat messages
|
| 310 |
if st.session_state.messages:
|
|
|
|
| 272 |
# File handling
|
| 273 |
pdf_path = os.path.join(tempfile.gettempdir(), f"{patent_number}.pdf")
|
| 274 |
if not os.path.isfile(pdf_path):
|
| 275 |
+
with st.spinner("📥 Downloading patent file..."):
|
| 276 |
+
try:
|
| 277 |
+
pdf_path = download_pdf(patent_number)
|
| 278 |
+
st.write(f"✅ File downloaded: {pdf_path}")
|
| 279 |
+
except Exception as e:
|
| 280 |
+
st.error(f"Failed to download patent: {e}")
|
| 281 |
+
st.stop()
|
| 282 |
else:
|
| 283 |
st.write("✅ File already downloaded.")
|
| 284 |
|
| 285 |
# Generate PDF preview only if not already displayed
|
| 286 |
if not st.session_state.get("pdf_preview_displayed", False):
|
| 287 |
+
with st.spinner("🖼️ Generating PDF preview..."):
|
| 288 |
+
preview_image_path = preview_pdf(pdf_path, scale_factor=0.5)
|
| 289 |
+
if preview_image_path:
|
| 290 |
+
st.session_state.pdf_preview = preview_image_path
|
| 291 |
+
st.image(preview_image_path, caption="First Page Preview", use_container_width=False)
|
| 292 |
+
st.session_state["pdf_preview_displayed"] = True
|
| 293 |
+
else:
|
| 294 |
+
st.warning("Failed to generate PDF preview.")
|
| 295 |
+
st.session_state.pdf_preview = None
|
| 296 |
|
| 297 |
# Load the document into the system
|
| 298 |
+
with st.spinner("🔄 Loading document into the system..."):
|
| 299 |
+
try:
|
| 300 |
+
st.session_state.chain = load_chain(pdf_path)
|
| 301 |
+
st.session_state.LOADED_PATENT = patent_number
|
| 302 |
+
st.session_state.loaded_pdf_path = pdf_path
|
| 303 |
+
st.session_state.messages = [{"role": "assistant", "content": "Hello! How can I assist you with this patent?"}]
|
| 304 |
+
st.success("🚀 Document successfully loaded! You can now start asking questions.")
|
| 305 |
+
except Exception as e:
|
| 306 |
+
st.error(f"Failed to load the document: {e}")
|
| 307 |
+
st.stop()
|
| 308 |
|
| 309 |
# Display previous chat messages
|
| 310 |
if st.session_state.messages:
|