Update app.py
Browse files
app.py
CHANGED
@@ -212,16 +212,13 @@ def process_pdf(pdf_path):
|
|
212 |
return "image_collection", "text_collection", "video_collection" # Replace with actual collections
|
213 |
|
214 |
def page_1():
|
215 |
-
st.title("Page 1: Upload and Process
|
216 |
-
|
217 |
-
# File uploader for multiple zip files containing videos
|
218 |
-
uploaded_video_zips = st.file_uploader("Upload ZIP files containing videos", type=["zip"], accept_multiple_files=True)
|
219 |
|
220 |
# File uploader for PDF files
|
221 |
uploaded_pdf_files = st.file_uploader("Upload PDF files", type=["pdf"], accept_multiple_files=True)
|
222 |
|
223 |
# Button to trigger processing
|
224 |
-
if
|
225 |
# Temporary folder to store extracted files
|
226 |
temp_folder = "/tmp/extracted_files"
|
227 |
os.makedirs(temp_folder, exist_ok=True)
|
@@ -231,24 +228,10 @@ def page_1():
|
|
231 |
status_text = st.empty()
|
232 |
|
233 |
try:
|
234 |
-
total_files = len(
|
235 |
files_processed = 0
|
236 |
progress_step = 100 / total_files if total_files > 0 else 0
|
237 |
|
238 |
-
# Process video zip files
|
239 |
-
for uploaded_file in uploaded_video_zips:
|
240 |
-
zip_path = f"/tmp/{uploaded_file.name}"
|
241 |
-
with open(zip_path, "wb") as f:
|
242 |
-
f.write(uploaded_file.getbuffer())
|
243 |
-
|
244 |
-
# Extract the content from the zip file
|
245 |
-
folder_name = os.path.splitext(uploaded_file.name)[0]
|
246 |
-
extract_to = os.path.join(temp_folder, folder_name)
|
247 |
-
if unzip_file(zip_path, extract_to):
|
248 |
-
files_processed += 1
|
249 |
-
progress_bar.progress(files_processed * progress_step)
|
250 |
-
status_text.text(f"Extracting: {uploaded_file.name} ({files_processed}/{total_files})")
|
251 |
-
|
252 |
# Process PDF files
|
253 |
for uploaded_pdf in uploaded_pdf_files:
|
254 |
pdf_path = f"/tmp/{uploaded_pdf.name}"
|
@@ -260,18 +243,18 @@ def page_1():
|
|
260 |
progress_bar.progress(files_processed * progress_step)
|
261 |
status_text.text(f"Processing PDF: {uploaded_pdf.name} ({files_processed}/{total_files})")
|
262 |
|
263 |
-
# Call your actual PDF processing function here
|
264 |
-
image_collection, text_collection, video_collection = process_pdf(pdf_path
|
265 |
|
266 |
# Save collections to session state
|
267 |
st.session_state.image_collection = image_collection
|
268 |
st.session_state.text_collection = text_collection
|
269 |
st.session_state.video_collection = video_collection
|
270 |
|
271 |
-
# Update status after
|
272 |
-
status_text.text("
|
273 |
|
274 |
-
st.success("
|
275 |
|
276 |
except Exception as e:
|
277 |
progress_bar.progress(0)
|
|
|
212 |
return "image_collection", "text_collection", "video_collection" # Replace with actual collections
|
213 |
|
214 |
def page_1():
|
215 |
+
st.title("Page 1: Upload and Process PDFs")
|
|
|
|
|
|
|
216 |
|
217 |
# File uploader for PDF files
|
218 |
uploaded_pdf_files = st.file_uploader("Upload PDF files", type=["pdf"], accept_multiple_files=True)
|
219 |
|
220 |
# Button to trigger processing
|
221 |
+
if uploaded_pdf_files and st.button("Process Files"):
|
222 |
# Temporary folder to store extracted files
|
223 |
temp_folder = "/tmp/extracted_files"
|
224 |
os.makedirs(temp_folder, exist_ok=True)
|
|
|
228 |
status_text = st.empty()
|
229 |
|
230 |
try:
|
231 |
+
total_files = len(uploaded_pdf_files)
|
232 |
files_processed = 0
|
233 |
progress_step = 100 / total_files if total_files > 0 else 0
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
# Process PDF files
|
236 |
for uploaded_pdf in uploaded_pdf_files:
|
237 |
pdf_path = f"/tmp/{uploaded_pdf.name}"
|
|
|
243 |
progress_bar.progress(files_processed * progress_step)
|
244 |
status_text.text(f"Processing PDF: {uploaded_pdf.name} ({files_processed}/{total_files})")
|
245 |
|
246 |
+
# Call your actual PDF processing function here
|
247 |
+
image_collection, text_collection, video_collection = process_pdf(pdf_path)
|
248 |
|
249 |
# Save collections to session state
|
250 |
st.session_state.image_collection = image_collection
|
251 |
st.session_state.text_collection = text_collection
|
252 |
st.session_state.video_collection = video_collection
|
253 |
|
254 |
+
# Update status after processing
|
255 |
+
status_text.text("Processing completed successfully!")
|
256 |
|
257 |
+
st.success("PDFs processed successfully! Collections saved to session state.")
|
258 |
|
259 |
except Exception as e:
|
260 |
progress_bar.progress(0)
|