Spaces:
Sleeping
Sleeping
Push Bot
commited on
Commit
Β·
221e6a2
1
Parent(s):
3e32dc0
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
|
@@ -3772,7 +3772,8 @@ def debug_compile_output_zip():
|
|
| 3772 |
if not zip_path.exists():
|
| 3773 |
return (
|
| 3774 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3775 |
-
+ f"<div>Expected at: {zip_path}</div>"
|
|
|
|
| 3776 |
)
|
| 3777 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3778 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
@@ -3808,7 +3809,7 @@ def debug_compile_output_zip():
|
|
| 3808 |
except Exception as e:
|
| 3809 |
logs.append(f"β unzip failed: {e}")
|
| 3810 |
_write_logs(LOG_PATH, logs)
|
| 3811 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3812 |
|
| 3813 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3814 |
tex_path = None
|
|
@@ -3825,7 +3826,7 @@ def debug_compile_output_zip():
|
|
| 3825 |
if tex_path is None:
|
| 3826 |
logs.append("β No .tex file found in output.zip")
|
| 3827 |
_write_logs(LOG_PATH, logs)
|
| 3828 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 3829 |
|
| 3830 |
# If left_logo missing, disable \logoleft
|
| 3831 |
try:
|
|
@@ -3856,7 +3857,8 @@ def debug_compile_output_zip():
|
|
| 3856 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3857 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3858 |
+ "\n".join(logs)
|
| 3859 |
-
+ "</pre>"
|
|
|
|
| 3860 |
)
|
| 3861 |
|
| 3862 |
try:
|
|
@@ -3867,11 +3869,11 @@ def debug_compile_output_zip():
|
|
| 3867 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3868 |
)
|
| 3869 |
_write_logs(LOG_PATH, logs)
|
| 3870 |
-
return html
|
| 3871 |
except Exception as e:
|
| 3872 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3873 |
_write_logs(LOG_PATH, logs)
|
| 3874 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3875 |
|
| 3876 |
def _find_last_pipeline_zip():
|
| 3877 |
try:
|
|
@@ -3892,7 +3894,7 @@ def _find_last_pipeline_zip():
|
|
| 3892 |
return None
|
| 3893 |
|
| 3894 |
def debug_compile_last_pipeline_zip():
|
| 3895 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 3896 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3897 |
last_zip = _find_last_pipeline_zip()
|
| 3898 |
if not last_zip:
|
|
@@ -3907,7 +3909,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3907 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3908 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3909 |
else:
|
| 3910 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 3911 |
|
| 3912 |
# Prepare workspace
|
| 3913 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -3924,7 +3926,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3924 |
except Exception as e:
|
| 3925 |
logs.append(f"β unzip failed: {e}")
|
| 3926 |
_write_logs(LOG_PATH, logs)
|
| 3927 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3928 |
|
| 3929 |
# Locate tex
|
| 3930 |
tex_path = None
|
|
@@ -3940,7 +3942,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3940 |
if tex_path is None:
|
| 3941 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3942 |
_write_logs(LOG_PATH, logs)
|
| 3943 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 3944 |
|
| 3945 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3946 |
try:
|
|
@@ -3976,7 +3978,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 3976 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3977 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3978 |
+ "\n".join(logs)
|
| 3979 |
-
+ "</pre>"
|
|
|
|
| 3980 |
)
|
| 3981 |
try:
|
| 3982 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3772 |
if not zip_path.exists():
|
| 3773 |
return (
|
| 3774 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3775 |
+
+ f"<div>Expected at: {zip_path}</div>",
|
| 3776 |
+
None,
|
| 3777 |
)
|
| 3778 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3779 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
|
|
| 3809 |
except Exception as e:
|
| 3810 |
logs.append(f"β unzip failed: {e}")
|
| 3811 |
_write_logs(LOG_PATH, logs)
|
| 3812 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3813 |
|
| 3814 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3815 |
tex_path = None
|
|
|
|
| 3826 |
if tex_path is None:
|
| 3827 |
logs.append("β No .tex file found in output.zip")
|
| 3828 |
_write_logs(LOG_PATH, logs)
|
| 3829 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 3830 |
|
| 3831 |
# If left_logo missing, disable \logoleft
|
| 3832 |
try:
|
|
|
|
| 3857 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3858 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3859 |
+ "\n".join(logs)
|
| 3860 |
+
+ "</pre>",
|
| 3861 |
+
None,
|
| 3862 |
)
|
| 3863 |
|
| 3864 |
try:
|
|
|
|
| 3869 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3870 |
)
|
| 3871 |
_write_logs(LOG_PATH, logs)
|
| 3872 |
+
return html, str(pdf_path)
|
| 3873 |
except Exception as e:
|
| 3874 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3875 |
_write_logs(LOG_PATH, logs)
|
| 3876 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3877 |
|
| 3878 |
def _find_last_pipeline_zip():
|
| 3879 |
try:
|
|
|
|
| 3894 |
return None
|
| 3895 |
|
| 3896 |
def debug_compile_last_pipeline_zip():
|
| 3897 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 3898 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3899 |
last_zip = _find_last_pipeline_zip()
|
| 3900 |
if not last_zip:
|
|
|
|
| 3909 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3910 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3911 |
else:
|
| 3912 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 3913 |
|
| 3914 |
# Prepare workspace
|
| 3915 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 3926 |
except Exception as e:
|
| 3927 |
logs.append(f"β unzip failed: {e}")
|
| 3928 |
_write_logs(LOG_PATH, logs)
|
| 3929 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3930 |
|
| 3931 |
# Locate tex
|
| 3932 |
tex_path = None
|
|
|
|
| 3942 |
if tex_path is None:
|
| 3943 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3944 |
_write_logs(LOG_PATH, logs)
|
| 3945 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 3946 |
|
| 3947 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3948 |
try:
|
|
|
|
| 3978 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3979 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3980 |
+ "\n".join(logs)
|
| 3981 |
+
+ "</pre>",
|
| 3982 |
+
None,
|
| 3983 |
)
|
| 3984 |
try:
|
| 3985 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|