Spaces:
Sleeping
Sleeping
Push Bot
commited on
Commit
Β·
09f5a8b
1
Parent(s):
63c0bef
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
|
@@ -3456,7 +3456,8 @@ def debug_compile_output_zip():
|
|
| 3456 |
if not zip_path.exists():
|
| 3457 |
return (
|
| 3458 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3459 |
-
+ f"<div>Expected at: {zip_path}</div>"
|
|
|
|
| 3460 |
)
|
| 3461 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3462 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
@@ -3492,7 +3493,7 @@ def debug_compile_output_zip():
|
|
| 3492 |
except Exception as e:
|
| 3493 |
logs.append(f"β unzip failed: {e}")
|
| 3494 |
_write_logs(LOG_PATH, logs)
|
| 3495 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3496 |
|
| 3497 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3498 |
tex_path = None
|
|
@@ -3509,7 +3510,7 @@ def debug_compile_output_zip():
|
|
| 3509 |
if tex_path is None:
|
| 3510 |
logs.append("β No .tex file found in output.zip")
|
| 3511 |
_write_logs(LOG_PATH, logs)
|
| 3512 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 3513 |
|
| 3514 |
# If left_logo missing, disable \logoleft
|
| 3515 |
try:
|
|
@@ -3540,7 +3541,8 @@ def debug_compile_output_zip():
|
|
| 3540 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3541 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3542 |
+ "\n".join(logs)
|
| 3543 |
-
+ "</pre>"
|
|
|
|
| 3544 |
)
|
| 3545 |
|
| 3546 |
try:
|
|
@@ -3551,11 +3553,11 @@ def debug_compile_output_zip():
|
|
| 3551 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3552 |
)
|
| 3553 |
_write_logs(LOG_PATH, logs)
|
| 3554 |
-
return html
|
| 3555 |
except Exception as e:
|
| 3556 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3557 |
_write_logs(LOG_PATH, logs)
|
| 3558 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3559 |
|
| 3560 |
def _find_last_pipeline_zip():
|
| 3561 |
try:
|
|
@@ -3576,7 +3578,7 @@ def _find_last_pipeline_zip():
|
|
| 3576 |
return None
|
| 3577 |
|
| 3578 |
def debug_compile_last_pipeline_zip():
|
| 3579 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 3580 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3581 |
last_zip = _find_last_pipeline_zip()
|
| 3582 |
if not last_zip:
|
|
@@ -3591,7 +3593,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3591 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3592 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3593 |
else:
|
| 3594 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 3595 |
|
| 3596 |
# Prepare workspace
|
| 3597 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -3608,7 +3610,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3608 |
except Exception as e:
|
| 3609 |
logs.append(f"β unzip failed: {e}")
|
| 3610 |
_write_logs(LOG_PATH, logs)
|
| 3611 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3612 |
|
| 3613 |
# Locate tex
|
| 3614 |
tex_path = None
|
|
@@ -3624,7 +3626,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3624 |
if tex_path is None:
|
| 3625 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3626 |
_write_logs(LOG_PATH, logs)
|
| 3627 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 3628 |
|
| 3629 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3630 |
try:
|
|
@@ -3660,7 +3662,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 3660 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3661 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3662 |
+ "\n".join(logs)
|
| 3663 |
-
+ "</pre>"
|
|
|
|
| 3664 |
)
|
| 3665 |
try:
|
| 3666 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3456 |
if not zip_path.exists():
|
| 3457 |
return (
|
| 3458 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3459 |
+
+ f"<div>Expected at: {zip_path}</div>",
|
| 3460 |
+
None,
|
| 3461 |
)
|
| 3462 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3463 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
|
|
| 3493 |
except Exception as e:
|
| 3494 |
logs.append(f"β unzip failed: {e}")
|
| 3495 |
_write_logs(LOG_PATH, logs)
|
| 3496 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3497 |
|
| 3498 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3499 |
tex_path = None
|
|
|
|
| 3510 |
if tex_path is None:
|
| 3511 |
logs.append("β No .tex file found in output.zip")
|
| 3512 |
_write_logs(LOG_PATH, logs)
|
| 3513 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 3514 |
|
| 3515 |
# If left_logo missing, disable \logoleft
|
| 3516 |
try:
|
|
|
|
| 3541 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3542 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3543 |
+ "\n".join(logs)
|
| 3544 |
+
+ "</pre>",
|
| 3545 |
+
None,
|
| 3546 |
)
|
| 3547 |
|
| 3548 |
try:
|
|
|
|
| 3553 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3554 |
)
|
| 3555 |
_write_logs(LOG_PATH, logs)
|
| 3556 |
+
return html, str(pdf_path)
|
| 3557 |
except Exception as e:
|
| 3558 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3559 |
_write_logs(LOG_PATH, logs)
|
| 3560 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3561 |
|
| 3562 |
def _find_last_pipeline_zip():
|
| 3563 |
try:
|
|
|
|
| 3578 |
return None
|
| 3579 |
|
| 3580 |
def debug_compile_last_pipeline_zip():
|
| 3581 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 3582 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3583 |
last_zip = _find_last_pipeline_zip()
|
| 3584 |
if not last_zip:
|
|
|
|
| 3593 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3594 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3595 |
else:
|
| 3596 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 3597 |
|
| 3598 |
# Prepare workspace
|
| 3599 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 3610 |
except Exception as e:
|
| 3611 |
logs.append(f"β unzip failed: {e}")
|
| 3612 |
_write_logs(LOG_PATH, logs)
|
| 3613 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3614 |
|
| 3615 |
# Locate tex
|
| 3616 |
tex_path = None
|
|
|
|
| 3626 |
if tex_path is None:
|
| 3627 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3628 |
_write_logs(LOG_PATH, logs)
|
| 3629 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 3630 |
|
| 3631 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3632 |
try:
|
|
|
|
| 3662 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3663 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3664 |
+ "\n".join(logs)
|
| 3665 |
+
+ "</pre>",
|
| 3666 |
+
None,
|
| 3667 |
)
|
| 3668 |
try:
|
| 3669 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|