Spaces:
Running
Running
Push Bot
commited on
Commit
Β·
abd9e71
1
Parent(s):
e69584b
Debug: add image preview (first page) with PyMuPDF/pdfium; return PDF path from debug flows; chain .then to render image
Browse files
app.py
CHANGED
|
@@ -3489,7 +3489,8 @@ def debug_compile_output_zip():
|
|
| 3489 |
if not zip_path.exists():
|
| 3490 |
return (
|
| 3491 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3492 |
-
+ f"<div>Expected at: {zip_path}</div>"
|
|
|
|
| 3493 |
)
|
| 3494 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3495 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
@@ -3525,7 +3526,7 @@ def debug_compile_output_zip():
|
|
| 3525 |
except Exception as e:
|
| 3526 |
logs.append(f"β unzip failed: {e}")
|
| 3527 |
_write_logs(LOG_PATH, logs)
|
| 3528 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3529 |
|
| 3530 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3531 |
tex_path = None
|
|
@@ -3542,7 +3543,7 @@ def debug_compile_output_zip():
|
|
| 3542 |
if tex_path is None:
|
| 3543 |
logs.append("β No .tex file found in output.zip")
|
| 3544 |
_write_logs(LOG_PATH, logs)
|
| 3545 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 3546 |
|
| 3547 |
# If left_logo missing, disable \logoleft
|
| 3548 |
try:
|
|
@@ -3573,7 +3574,8 @@ def debug_compile_output_zip():
|
|
| 3573 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3574 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3575 |
+ "\n".join(logs)
|
| 3576 |
-
+ "</pre>"
|
|
|
|
| 3577 |
)
|
| 3578 |
|
| 3579 |
try:
|
|
@@ -3584,11 +3586,11 @@ def debug_compile_output_zip():
|
|
| 3584 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3585 |
)
|
| 3586 |
_write_logs(LOG_PATH, logs)
|
| 3587 |
-
return html
|
| 3588 |
except Exception as e:
|
| 3589 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3590 |
_write_logs(LOG_PATH, logs)
|
| 3591 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3592 |
|
| 3593 |
def _find_last_pipeline_zip():
|
| 3594 |
try:
|
|
@@ -3609,7 +3611,7 @@ def _find_last_pipeline_zip():
|
|
| 3609 |
return None
|
| 3610 |
|
| 3611 |
def debug_compile_last_pipeline_zip():
|
| 3612 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 3613 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3614 |
last_zip = _find_last_pipeline_zip()
|
| 3615 |
if not last_zip:
|
|
@@ -3624,7 +3626,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3624 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3625 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3626 |
else:
|
| 3627 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 3628 |
|
| 3629 |
# Prepare workspace
|
| 3630 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -3641,7 +3643,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3641 |
except Exception as e:
|
| 3642 |
logs.append(f"β unzip failed: {e}")
|
| 3643 |
_write_logs(LOG_PATH, logs)
|
| 3644 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3645 |
|
| 3646 |
# Locate tex
|
| 3647 |
tex_path = None
|
|
@@ -3657,7 +3659,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3657 |
if tex_path is None:
|
| 3658 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3659 |
_write_logs(LOG_PATH, logs)
|
| 3660 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 3661 |
|
| 3662 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3663 |
try:
|
|
@@ -3693,7 +3695,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 3693 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3694 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3695 |
+ "\n".join(logs)
|
| 3696 |
-
+ "</pre>"
|
|
|
|
| 3697 |
)
|
| 3698 |
try:
|
| 3699 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
@@ -3703,17 +3706,17 @@ def debug_compile_last_pipeline_zip():
|
|
| 3703 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3704 |
)
|
| 3705 |
_write_logs(LOG_PATH, logs)
|
| 3706 |
-
return html
|
| 3707 |
except Exception as e:
|
| 3708 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3709 |
_write_logs(LOG_PATH, logs)
|
| 3710 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3711 |
|
| 3712 |
def debug_compile_uploaded_zip(zip_file):
|
| 3713 |
-
"""Compile an uploaded poster zip (user-provided)
|
| 3714 |
logs = [f"π Debug(upload) at {_now_str()}"]
|
| 3715 |
if not zip_file:
|
| 3716 |
-
return "<div style='color:#b00'>Please upload a .zip file first.</div>"
|
| 3717 |
# Prepare workspace
|
| 3718 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 3719 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
@@ -3725,7 +3728,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3725 |
except Exception as e:
|
| 3726 |
logs.append(f"β save upload failed: {e}")
|
| 3727 |
_write_logs(LOG_PATH, logs)
|
| 3728 |
-
return "<div style='color:#b00'>Save upload failed.</div>"
|
| 3729 |
# Extract
|
| 3730 |
try:
|
| 3731 |
import zipfile as _zf
|
|
@@ -3734,7 +3737,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3734 |
except Exception as e:
|
| 3735 |
logs.append(f"β unzip failed: {e}")
|
| 3736 |
_write_logs(LOG_PATH, logs)
|
| 3737 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3738 |
# Find tex
|
| 3739 |
tex_path = None
|
| 3740 |
for name in ("poster_output.tex", "poster.tex"):
|
|
@@ -3778,7 +3781,8 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3778 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3779 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3780 |
+ "\n".join(logs)
|
| 3781 |
-
+ "</pre>"
|
|
|
|
| 3782 |
)
|
| 3783 |
try:
|
| 3784 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
@@ -3788,11 +3792,11 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3788 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3789 |
)
|
| 3790 |
_write_logs(LOG_PATH, logs)
|
| 3791 |
-
return html
|
| 3792 |
except Exception as e:
|
| 3793 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3794 |
_write_logs(LOG_PATH, logs)
|
| 3795 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3796 |
|
| 3797 |
# =====================
|
| 3798 |
# Gradio pipeline function (ISOLATED)
|
|
|
|
| 3489 |
if not zip_path.exists():
|
| 3490 |
return (
|
| 3491 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3492 |
+
+ f"<div>Expected at: {zip_path}</div>",
|
| 3493 |
+
None,
|
| 3494 |
)
|
| 3495 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3496 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
|
|
| 3526 |
except Exception as e:
|
| 3527 |
logs.append(f"β unzip failed: {e}")
|
| 3528 |
_write_logs(LOG_PATH, logs)
|
| 3529 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3530 |
|
| 3531 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3532 |
tex_path = None
|
|
|
|
| 3543 |
if tex_path is None:
|
| 3544 |
logs.append("β No .tex file found in output.zip")
|
| 3545 |
_write_logs(LOG_PATH, logs)
|
| 3546 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 3547 |
|
| 3548 |
# If left_logo missing, disable \logoleft
|
| 3549 |
try:
|
|
|
|
| 3574 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3575 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3576 |
+ "\n".join(logs)
|
| 3577 |
+
+ "</pre>",
|
| 3578 |
+
None,
|
| 3579 |
)
|
| 3580 |
|
| 3581 |
try:
|
|
|
|
| 3586 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3587 |
)
|
| 3588 |
_write_logs(LOG_PATH, logs)
|
| 3589 |
+
return html, str(pdf_path)
|
| 3590 |
except Exception as e:
|
| 3591 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3592 |
_write_logs(LOG_PATH, logs)
|
| 3593 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3594 |
|
| 3595 |
def _find_last_pipeline_zip():
|
| 3596 |
try:
|
|
|
|
| 3611 |
return None
|
| 3612 |
|
| 3613 |
def debug_compile_last_pipeline_zip():
|
| 3614 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 3615 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3616 |
last_zip = _find_last_pipeline_zip()
|
| 3617 |
if not last_zip:
|
|
|
|
| 3626 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3627 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3628 |
else:
|
| 3629 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 3630 |
|
| 3631 |
# Prepare workspace
|
| 3632 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 3643 |
except Exception as e:
|
| 3644 |
logs.append(f"β unzip failed: {e}")
|
| 3645 |
_write_logs(LOG_PATH, logs)
|
| 3646 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3647 |
|
| 3648 |
# Locate tex
|
| 3649 |
tex_path = None
|
|
|
|
| 3659 |
if tex_path is None:
|
| 3660 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3661 |
_write_logs(LOG_PATH, logs)
|
| 3662 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 3663 |
|
| 3664 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3665 |
try:
|
|
|
|
| 3695 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3696 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3697 |
+ "\n".join(logs)
|
| 3698 |
+
+ "</pre>",
|
| 3699 |
+
None,
|
| 3700 |
)
|
| 3701 |
try:
|
| 3702 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3706 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3707 |
)
|
| 3708 |
_write_logs(LOG_PATH, logs)
|
| 3709 |
+
return html, str(pdf_path)
|
| 3710 |
except Exception as e:
|
| 3711 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3712 |
_write_logs(LOG_PATH, logs)
|
| 3713 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3714 |
|
| 3715 |
def debug_compile_uploaded_zip(zip_file):
|
| 3716 |
+
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
|
| 3717 |
logs = [f"π Debug(upload) at {_now_str()}"]
|
| 3718 |
if not zip_file:
|
| 3719 |
+
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
|
| 3720 |
# Prepare workspace
|
| 3721 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 3722 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
|
|
| 3728 |
except Exception as e:
|
| 3729 |
logs.append(f"β save upload failed: {e}")
|
| 3730 |
_write_logs(LOG_PATH, logs)
|
| 3731 |
+
return "<div style='color:#b00'>Save upload failed.</div>", None
|
| 3732 |
# Extract
|
| 3733 |
try:
|
| 3734 |
import zipfile as _zf
|
|
|
|
| 3737 |
except Exception as e:
|
| 3738 |
logs.append(f"β unzip failed: {e}")
|
| 3739 |
_write_logs(LOG_PATH, logs)
|
| 3740 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3741 |
# Find tex
|
| 3742 |
tex_path = None
|
| 3743 |
for name in ("poster_output.tex", "poster.tex"):
|
|
|
|
| 3781 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3782 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3783 |
+ "\n".join(logs)
|
| 3784 |
+
+ "</pre>",
|
| 3785 |
+
None,
|
| 3786 |
)
|
| 3787 |
try:
|
| 3788 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3792 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3793 |
)
|
| 3794 |
_write_logs(LOG_PATH, logs)
|
| 3795 |
+
return html, str(pdf_path)
|
| 3796 |
except Exception as e:
|
| 3797 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3798 |
_write_logs(LOG_PATH, logs)
|
| 3799 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3800 |
|
| 3801 |
# =====================
|
| 3802 |
# Gradio pipeline function (ISOLATED)
|