Spaces:
Sleeping
Sleeping
Push Bot
commited on
Commit
Β·
0ec5389
1
Parent(s):
fec4387
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
|
@@ -2445,7 +2445,8 @@ def debug_compile_output_zip():
|
|
| 2445 |
if not zip_path.exists():
|
| 2446 |
return (
|
| 2447 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 2448 |
-
+ f"<div>Expected at: {zip_path}</div>"
|
|
|
|
| 2449 |
)
|
| 2450 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 2451 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
@@ -2481,7 +2482,7 @@ def debug_compile_output_zip():
|
|
| 2481 |
except Exception as e:
|
| 2482 |
logs.append(f"β unzip failed: {e}")
|
| 2483 |
_write_logs(LOG_PATH, logs)
|
| 2484 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 2485 |
|
| 2486 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 2487 |
tex_path = None
|
|
@@ -2498,7 +2499,7 @@ def debug_compile_output_zip():
|
|
| 2498 |
if tex_path is None:
|
| 2499 |
logs.append("β No .tex file found in output.zip")
|
| 2500 |
_write_logs(LOG_PATH, logs)
|
| 2501 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 2502 |
|
| 2503 |
# If left_logo missing, disable \logoleft
|
| 2504 |
try:
|
|
@@ -2529,7 +2530,8 @@ def debug_compile_output_zip():
|
|
| 2529 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2530 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2531 |
+ "\n".join(logs)
|
| 2532 |
-
+ "</pre>"
|
|
|
|
| 2533 |
)
|
| 2534 |
|
| 2535 |
try:
|
|
@@ -2540,11 +2542,11 @@ def debug_compile_output_zip():
|
|
| 2540 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2541 |
)
|
| 2542 |
_write_logs(LOG_PATH, logs)
|
| 2543 |
-
return html
|
| 2544 |
except Exception as e:
|
| 2545 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2546 |
_write_logs(LOG_PATH, logs)
|
| 2547 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 2548 |
|
| 2549 |
def _find_last_pipeline_zip():
|
| 2550 |
try:
|
|
@@ -2565,7 +2567,7 @@ def _find_last_pipeline_zip():
|
|
| 2565 |
return None
|
| 2566 |
|
| 2567 |
def debug_compile_last_pipeline_zip():
|
| 2568 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 2569 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 2570 |
last_zip = _find_last_pipeline_zip()
|
| 2571 |
if not last_zip:
|
|
@@ -2580,7 +2582,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2580 |
logs.append(f"β Auto-stage failed: {e}")
|
| 2581 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 2582 |
else:
|
| 2583 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 2584 |
|
| 2585 |
# Prepare workspace
|
| 2586 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -2597,7 +2599,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2597 |
except Exception as e:
|
| 2598 |
logs.append(f"β unzip failed: {e}")
|
| 2599 |
_write_logs(LOG_PATH, logs)
|
| 2600 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 2601 |
|
| 2602 |
# Locate tex
|
| 2603 |
tex_path = None
|
|
@@ -2613,7 +2615,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2613 |
if tex_path is None:
|
| 2614 |
logs.append("β No .tex file found in last pipeline zip")
|
| 2615 |
_write_logs(LOG_PATH, logs)
|
| 2616 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 2617 |
|
| 2618 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 2619 |
try:
|
|
@@ -2649,7 +2651,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 2649 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2650 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2651 |
+ "\n".join(logs)
|
| 2652 |
-
+ "</pre>"
|
|
|
|
| 2653 |
)
|
| 2654 |
try:
|
| 2655 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 2445 |
if not zip_path.exists():
|
| 2446 |
return (
|
| 2447 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 2448 |
+
+ f"<div>Expected at: {zip_path}</div>",
|
| 2449 |
+
None,
|
| 2450 |
)
|
| 2451 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 2452 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
|
|
| 2482 |
except Exception as e:
|
| 2483 |
logs.append(f"β unzip failed: {e}")
|
| 2484 |
_write_logs(LOG_PATH, logs)
|
| 2485 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 2486 |
|
| 2487 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 2488 |
tex_path = None
|
|
|
|
| 2499 |
if tex_path is None:
|
| 2500 |
logs.append("β No .tex file found in output.zip")
|
| 2501 |
_write_logs(LOG_PATH, logs)
|
| 2502 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 2503 |
|
| 2504 |
# If left_logo missing, disable \logoleft
|
| 2505 |
try:
|
|
|
|
| 2530 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2531 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2532 |
+ "\n".join(logs)
|
| 2533 |
+
+ "</pre>",
|
| 2534 |
+
None,
|
| 2535 |
)
|
| 2536 |
|
| 2537 |
try:
|
|
|
|
| 2542 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2543 |
)
|
| 2544 |
_write_logs(LOG_PATH, logs)
|
| 2545 |
+
return html, str(pdf_path)
|
| 2546 |
except Exception as e:
|
| 2547 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2548 |
_write_logs(LOG_PATH, logs)
|
| 2549 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 2550 |
|
| 2551 |
def _find_last_pipeline_zip():
|
| 2552 |
try:
|
|
|
|
| 2567 |
return None
|
| 2568 |
|
| 2569 |
def debug_compile_last_pipeline_zip():
|
| 2570 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 2571 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 2572 |
last_zip = _find_last_pipeline_zip()
|
| 2573 |
if not last_zip:
|
|
|
|
| 2582 |
logs.append(f"β Auto-stage failed: {e}")
|
| 2583 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 2584 |
else:
|
| 2585 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 2586 |
|
| 2587 |
# Prepare workspace
|
| 2588 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 2599 |
except Exception as e:
|
| 2600 |
logs.append(f"β unzip failed: {e}")
|
| 2601 |
_write_logs(LOG_PATH, logs)
|
| 2602 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 2603 |
|
| 2604 |
# Locate tex
|
| 2605 |
tex_path = None
|
|
|
|
| 2615 |
if tex_path is None:
|
| 2616 |
logs.append("β No .tex file found in last pipeline zip")
|
| 2617 |
_write_logs(LOG_PATH, logs)
|
| 2618 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 2619 |
|
| 2620 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 2621 |
try:
|
|
|
|
| 2651 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2652 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2653 |
+ "\n".join(logs)
|
| 2654 |
+
+ "</pre>",
|
| 2655 |
+
None,
|
| 2656 |
)
|
| 2657 |
try:
|
| 2658 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|