Spaces:
Running
Running
Push Bot
commited on
Commit
Β·
b5c2d8d
1
Parent(s):
c13961f
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
|
@@ -2539,7 +2539,8 @@ def debug_compile_output_zip():
|
|
| 2539 |
if not zip_path.exists():
|
| 2540 |
return (
|
| 2541 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 2542 |
-
+ f"<div>Expected at: {zip_path}</div>"
|
|
|
|
| 2543 |
)
|
| 2544 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 2545 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
@@ -2575,7 +2576,7 @@ def debug_compile_output_zip():
|
|
| 2575 |
except Exception as e:
|
| 2576 |
logs.append(f"β unzip failed: {e}")
|
| 2577 |
_write_logs(LOG_PATH, logs)
|
| 2578 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 2579 |
|
| 2580 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 2581 |
tex_path = None
|
|
@@ -2592,7 +2593,7 @@ def debug_compile_output_zip():
|
|
| 2592 |
if tex_path is None:
|
| 2593 |
logs.append("β No .tex file found in output.zip")
|
| 2594 |
_write_logs(LOG_PATH, logs)
|
| 2595 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 2596 |
|
| 2597 |
# If left_logo missing, disable \logoleft
|
| 2598 |
try:
|
|
@@ -2623,7 +2624,8 @@ def debug_compile_output_zip():
|
|
| 2623 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2624 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2625 |
+ "\n".join(logs)
|
| 2626 |
-
+ "</pre>"
|
|
|
|
| 2627 |
)
|
| 2628 |
|
| 2629 |
try:
|
|
@@ -2634,11 +2636,11 @@ def debug_compile_output_zip():
|
|
| 2634 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2635 |
)
|
| 2636 |
_write_logs(LOG_PATH, logs)
|
| 2637 |
-
return html
|
| 2638 |
except Exception as e:
|
| 2639 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2640 |
_write_logs(LOG_PATH, logs)
|
| 2641 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 2642 |
|
| 2643 |
def _find_last_pipeline_zip():
|
| 2644 |
try:
|
|
@@ -2659,7 +2661,7 @@ def _find_last_pipeline_zip():
|
|
| 2659 |
return None
|
| 2660 |
|
| 2661 |
def debug_compile_last_pipeline_zip():
|
| 2662 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 2663 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 2664 |
last_zip = _find_last_pipeline_zip()
|
| 2665 |
if not last_zip:
|
|
@@ -2674,7 +2676,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2674 |
logs.append(f"β Auto-stage failed: {e}")
|
| 2675 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 2676 |
else:
|
| 2677 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 2678 |
|
| 2679 |
# Prepare workspace
|
| 2680 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -2691,7 +2693,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2691 |
except Exception as e:
|
| 2692 |
logs.append(f"β unzip failed: {e}")
|
| 2693 |
_write_logs(LOG_PATH, logs)
|
| 2694 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 2695 |
|
| 2696 |
# Locate tex
|
| 2697 |
tex_path = None
|
|
@@ -2707,7 +2709,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2707 |
if tex_path is None:
|
| 2708 |
logs.append("β No .tex file found in last pipeline zip")
|
| 2709 |
_write_logs(LOG_PATH, logs)
|
| 2710 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 2711 |
|
| 2712 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 2713 |
try:
|
|
@@ -2743,7 +2745,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 2743 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2744 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2745 |
+ "\n".join(logs)
|
| 2746 |
-
+ "</pre>"
|
|
|
|
| 2747 |
)
|
| 2748 |
try:
|
| 2749 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
@@ -2753,17 +2756,17 @@ def debug_compile_last_pipeline_zip():
|
|
| 2753 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2754 |
)
|
| 2755 |
_write_logs(LOG_PATH, logs)
|
| 2756 |
-
return html
|
| 2757 |
except Exception as e:
|
| 2758 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2759 |
_write_logs(LOG_PATH, logs)
|
| 2760 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 2761 |
|
| 2762 |
def debug_compile_uploaded_zip(zip_file):
|
| 2763 |
-
"""Compile an uploaded poster zip (user-provided)
|
| 2764 |
logs = [f"π Debug(upload) at {_now_str()}"]
|
| 2765 |
if not zip_file:
|
| 2766 |
-
return "<div style='color:#b00'>Please upload a .zip file first.</div>"
|
| 2767 |
# Prepare workspace
|
| 2768 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 2769 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
@@ -2775,7 +2778,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 2775 |
except Exception as e:
|
| 2776 |
logs.append(f"β save upload failed: {e}")
|
| 2777 |
_write_logs(LOG_PATH, logs)
|
| 2778 |
-
return "<div style='color:#b00'>Save upload failed.</div>"
|
| 2779 |
# Extract
|
| 2780 |
try:
|
| 2781 |
import zipfile as _zf
|
|
@@ -2784,7 +2787,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 2784 |
except Exception as e:
|
| 2785 |
logs.append(f"β unzip failed: {e}")
|
| 2786 |
_write_logs(LOG_PATH, logs)
|
| 2787 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 2788 |
# Find tex
|
| 2789 |
tex_path = None
|
| 2790 |
for name in ("poster_output.tex", "poster.tex"):
|
|
@@ -2828,7 +2831,8 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 2828 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2829 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2830 |
+ "\n".join(logs)
|
| 2831 |
-
+ "</pre>"
|
|
|
|
| 2832 |
)
|
| 2833 |
try:
|
| 2834 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
@@ -2838,11 +2842,11 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 2838 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2839 |
)
|
| 2840 |
_write_logs(LOG_PATH, logs)
|
| 2841 |
-
return html
|
| 2842 |
except Exception as e:
|
| 2843 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2844 |
_write_logs(LOG_PATH, logs)
|
| 2845 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 2846 |
|
| 2847 |
# =====================
|
| 2848 |
# Gradio pipeline function (ISOLATED)
|
|
|
|
| 2539 |
if not zip_path.exists():
|
| 2540 |
return (
|
| 2541 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 2542 |
+
+ f"<div>Expected at: {zip_path}</div>",
|
| 2543 |
+
None,
|
| 2544 |
)
|
| 2545 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 2546 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
|
|
| 2576 |
except Exception as e:
|
| 2577 |
logs.append(f"β unzip failed: {e}")
|
| 2578 |
_write_logs(LOG_PATH, logs)
|
| 2579 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 2580 |
|
| 2581 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 2582 |
tex_path = None
|
|
|
|
| 2593 |
if tex_path is None:
|
| 2594 |
logs.append("β No .tex file found in output.zip")
|
| 2595 |
_write_logs(LOG_PATH, logs)
|
| 2596 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 2597 |
|
| 2598 |
# If left_logo missing, disable \logoleft
|
| 2599 |
try:
|
|
|
|
| 2624 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2625 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2626 |
+ "\n".join(logs)
|
| 2627 |
+
+ "</pre>",
|
| 2628 |
+
None,
|
| 2629 |
)
|
| 2630 |
|
| 2631 |
try:
|
|
|
|
| 2636 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2637 |
)
|
| 2638 |
_write_logs(LOG_PATH, logs)
|
| 2639 |
+
return html, str(pdf_path)
|
| 2640 |
except Exception as e:
|
| 2641 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2642 |
_write_logs(LOG_PATH, logs)
|
| 2643 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 2644 |
|
| 2645 |
def _find_last_pipeline_zip():
|
| 2646 |
try:
|
|
|
|
| 2661 |
return None
|
| 2662 |
|
| 2663 |
def debug_compile_last_pipeline_zip():
|
| 2664 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 2665 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 2666 |
last_zip = _find_last_pipeline_zip()
|
| 2667 |
if not last_zip:
|
|
|
|
| 2676 |
logs.append(f"β Auto-stage failed: {e}")
|
| 2677 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 2678 |
else:
|
| 2679 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 2680 |
|
| 2681 |
# Prepare workspace
|
| 2682 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 2693 |
except Exception as e:
|
| 2694 |
logs.append(f"β unzip failed: {e}")
|
| 2695 |
_write_logs(LOG_PATH, logs)
|
| 2696 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 2697 |
|
| 2698 |
# Locate tex
|
| 2699 |
tex_path = None
|
|
|
|
| 2709 |
if tex_path is None:
|
| 2710 |
logs.append("β No .tex file found in last pipeline zip")
|
| 2711 |
_write_logs(LOG_PATH, logs)
|
| 2712 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 2713 |
|
| 2714 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 2715 |
try:
|
|
|
|
| 2745 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2746 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2747 |
+ "\n".join(logs)
|
| 2748 |
+
+ "</pre>",
|
| 2749 |
+
None,
|
| 2750 |
)
|
| 2751 |
try:
|
| 2752 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 2756 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2757 |
)
|
| 2758 |
_write_logs(LOG_PATH, logs)
|
| 2759 |
+
return html, str(pdf_path)
|
| 2760 |
except Exception as e:
|
| 2761 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2762 |
_write_logs(LOG_PATH, logs)
|
| 2763 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 2764 |
|
| 2765 |
def debug_compile_uploaded_zip(zip_file):
|
| 2766 |
+
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
|
| 2767 |
logs = [f"π Debug(upload) at {_now_str()}"]
|
| 2768 |
if not zip_file:
|
| 2769 |
+
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
|
| 2770 |
# Prepare workspace
|
| 2771 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 2772 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
|
|
| 2778 |
except Exception as e:
|
| 2779 |
logs.append(f"β save upload failed: {e}")
|
| 2780 |
_write_logs(LOG_PATH, logs)
|
| 2781 |
+
return "<div style='color:#b00'>Save upload failed.</div>", None
|
| 2782 |
# Extract
|
| 2783 |
try:
|
| 2784 |
import zipfile as _zf
|
|
|
|
| 2787 |
except Exception as e:
|
| 2788 |
logs.append(f"β unzip failed: {e}")
|
| 2789 |
_write_logs(LOG_PATH, logs)
|
| 2790 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 2791 |
# Find tex
|
| 2792 |
tex_path = None
|
| 2793 |
for name in ("poster_output.tex", "poster.tex"):
|
|
|
|
| 2831 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2832 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2833 |
+ "\n".join(logs)
|
| 2834 |
+
+ "</pre>",
|
| 2835 |
+
None,
|
| 2836 |
)
|
| 2837 |
try:
|
| 2838 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 2842 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2843 |
)
|
| 2844 |
_write_logs(LOG_PATH, logs)
|
| 2845 |
+
return html, str(pdf_path)
|
| 2846 |
except Exception as e:
|
| 2847 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2848 |
_write_logs(LOG_PATH, logs)
|
| 2849 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 2850 |
|
| 2851 |
# =====================
|
| 2852 |
# Gradio pipeline function (ISOLATED)
|