Update app.py
Browse files
app.py
CHANGED
@@ -65,7 +65,7 @@ def extract_metadata(pdf_path):
|
|
65 |
|
66 |
return title, author, email_str, affiliation_str
|
67 |
|
68 |
-
# ----------------- PDF
|
69 |
pdf_source = st.radio("Upload or provide a link to a PDF:", ["Upload a PDF file", "Enter a PDF URL"], index=0, horizontal=True)
|
70 |
|
71 |
if pdf_source == "Upload a PDF file":
|
@@ -78,6 +78,26 @@ if pdf_source == "Upload a PDF file":
|
|
78 |
st.session_state.chunked = False
|
79 |
st.session_state.vector_created = False
|
80 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
81 |
# ----------------- Process PDF -----------------
|
82 |
if not st.session_state.pdf_loaded and "pdf_path" in st.session_state:
|
83 |
with st.spinner("π Processing document... Please wait."):
|
|
|
65 |
|
66 |
return title, author, email_str, affiliation_str
|
67 |
|
68 |
+
# ----------------- Step 1: Choose PDF Source -----------------
|
69 |
pdf_source = st.radio("Upload or provide a link to a PDF:", ["Upload a PDF file", "Enter a PDF URL"], index=0, horizontal=True)
|
70 |
|
71 |
if pdf_source == "Upload a PDF file":
|
|
|
78 |
st.session_state.chunked = False
|
79 |
st.session_state.vector_created = False
|
80 |
|
81 |
+
elif pdf_source == "Enter a PDF URL":
|
82 |
+
pdf_url = st.text_input("Enter PDF URL:")
|
83 |
+
if pdf_url and not st.session_state.pdf_loaded:
|
84 |
+
with st.spinner("π Downloading PDF..."):
|
85 |
+
try:
|
86 |
+
response = requests.get(pdf_url)
|
87 |
+
if response.status_code == 200:
|
88 |
+
st.session_state.pdf_path = "/mnt/data/temp.pdf"
|
89 |
+
with open(st.session_state.pdf_path, "wb") as f:
|
90 |
+
f.write(response.content)
|
91 |
+
st.session_state.pdf_loaded = False
|
92 |
+
st.session_state.chunked = False
|
93 |
+
st.session_state.vector_created = False
|
94 |
+
st.success("β
PDF Downloaded Successfully!")
|
95 |
+
else:
|
96 |
+
st.error("β Failed to download PDF. Check the URL.")
|
97 |
+
except Exception as e:
|
98 |
+
st.error(f"Error downloading PDF: {e}")
|
99 |
+
|
100 |
+
|
101 |
# ----------------- Process PDF -----------------
|
102 |
if not st.session_state.pdf_loaded and "pdf_path" in st.session_state:
|
103 |
with st.spinner("π Processing document... Please wait."):
|