Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -348,7 +348,7 @@ def process_pdf(file_obj, progress=gr.Progress()) -> Tuple[Optional[str], str, s
|
|
| 348 |
pass
|
| 349 |
return None, "", f"❌ Error: {str(e)}"
|
| 350 |
|
| 351 |
-
# Create Gradio interface with fixed download
|
| 352 |
with gr.Blocks(
|
| 353 |
title="PDF Splitter - Fast & Simple",
|
| 354 |
theme=gr.themes.Base()
|
|
@@ -381,24 +381,42 @@ with gr.Blocks(
|
|
| 381 |
stats_output = gr.HTML()
|
| 382 |
|
| 383 |
with gr.Row():
|
| 384 |
-
#
|
| 385 |
download_file = gr.File(
|
| 386 |
label="📦 Download ZIP (Contains only segments ≤5MB)",
|
| 387 |
visible=True,
|
| 388 |
-
|
| 389 |
-
|
|
|
|
| 390 |
)
|
| 391 |
|
| 392 |
-
#
|
| 393 |
-
def
|
| 394 |
-
|
| 395 |
-
|
| 396 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 397 |
|
|
|
|
| 398 |
split_btn.click(
|
| 399 |
-
fn=
|
| 400 |
inputs=[file_input],
|
| 401 |
-
outputs=[download_file, stats_output, status_text]
|
|
|
|
| 402 |
)
|
| 403 |
|
| 404 |
# Create Gradio interface with fixed theme
|
|
|
|
| 348 |
pass
|
| 349 |
return None, "", f"❌ Error: {str(e)}"
|
| 350 |
|
| 351 |
+
# Create Gradio interface with fixed download functionality
|
| 352 |
with gr.Blocks(
|
| 353 |
title="PDF Splitter - Fast & Simple",
|
| 354 |
theme=gr.themes.Base()
|
|
|
|
| 381 |
stats_output = gr.HTML()
|
| 382 |
|
| 383 |
with gr.Row():
|
| 384 |
+
# CRITICAL FIX: Use gr.File with proper configuration
|
| 385 |
download_file = gr.File(
|
| 386 |
label="📦 Download ZIP (Contains only segments ≤5MB)",
|
| 387 |
visible=True,
|
| 388 |
+
type="filepath", # Must be filepath for output
|
| 389 |
+
interactive=False, # Non-interactive for output
|
| 390 |
+
elem_id="download_output" # Add ID for debugging
|
| 391 |
)
|
| 392 |
|
| 393 |
+
# Fixed processing function that ensures file path is returned correctly
|
| 394 |
+
def process_pdf_wrapper(file_obj, progress=gr.Progress()):
|
| 395 |
+
"""Wrapper to ensure proper file path return"""
|
| 396 |
+
if file_obj is None:
|
| 397 |
+
return None, "", "⚠️ Please upload a PDF file"
|
| 398 |
+
|
| 399 |
+
try:
|
| 400 |
+
# Call your existing process_pdf function
|
| 401 |
+
zip_path, stats_html, status_msg = process_pdf(file_obj, progress)
|
| 402 |
+
|
| 403 |
+
# CRITICAL: Ensure zip_path is a string and file exists
|
| 404 |
+
if zip_path and Path(zip_path).exists():
|
| 405 |
+
# Return the string path directly
|
| 406 |
+
return str(zip_path), stats_html, status_msg
|
| 407 |
+
else:
|
| 408 |
+
return None, stats_html, "❌ Error: ZIP file was not created"
|
| 409 |
+
|
| 410 |
+
except Exception as e:
|
| 411 |
+
logger.error(f"Process wrapper error: {str(e)}")
|
| 412 |
+
return None, "", f"❌ Error: {str(e)}"
|
| 413 |
|
| 414 |
+
# Connect the button with proper output mapping
|
| 415 |
split_btn.click(
|
| 416 |
+
fn=process_pdf_wrapper,
|
| 417 |
inputs=[file_input],
|
| 418 |
+
outputs=[download_file, stats_output, status_text],
|
| 419 |
+
show_progress=True
|
| 420 |
)
|
| 421 |
|
| 422 |
# Create Gradio interface with fixed theme
|