Spaces:
Running
Running
Push Bot
commited on
Commit
Β·
5eac1a0
1
Parent(s):
f8cd563
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
|
@@ -3172,7 +3172,8 @@ def debug_compile_output_zip():
|
|
| 3172 |
if not zip_path.exists():
|
| 3173 |
return (
|
| 3174 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3175 |
-
+ f"<div>Expected at: {zip_path}</div>"
|
|
|
|
| 3176 |
)
|
| 3177 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3178 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
@@ -3208,7 +3209,7 @@ def debug_compile_output_zip():
|
|
| 3208 |
except Exception as e:
|
| 3209 |
logs.append(f"β unzip failed: {e}")
|
| 3210 |
_write_logs(LOG_PATH, logs)
|
| 3211 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3212 |
|
| 3213 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3214 |
tex_path = None
|
|
@@ -3225,7 +3226,7 @@ def debug_compile_output_zip():
|
|
| 3225 |
if tex_path is None:
|
| 3226 |
logs.append("β No .tex file found in output.zip")
|
| 3227 |
_write_logs(LOG_PATH, logs)
|
| 3228 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 3229 |
|
| 3230 |
# If left_logo missing, disable \logoleft
|
| 3231 |
try:
|
|
@@ -3256,7 +3257,8 @@ def debug_compile_output_zip():
|
|
| 3256 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3257 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3258 |
+ "\n".join(logs)
|
| 3259 |
-
+ "</pre>"
|
|
|
|
| 3260 |
)
|
| 3261 |
|
| 3262 |
try:
|
|
@@ -3267,11 +3269,11 @@ def debug_compile_output_zip():
|
|
| 3267 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3268 |
)
|
| 3269 |
_write_logs(LOG_PATH, logs)
|
| 3270 |
-
return html
|
| 3271 |
except Exception as e:
|
| 3272 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3273 |
_write_logs(LOG_PATH, logs)
|
| 3274 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3275 |
|
| 3276 |
def _find_last_pipeline_zip():
|
| 3277 |
try:
|
|
@@ -3292,7 +3294,7 @@ def _find_last_pipeline_zip():
|
|
| 3292 |
return None
|
| 3293 |
|
| 3294 |
def debug_compile_last_pipeline_zip():
|
| 3295 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 3296 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3297 |
last_zip = _find_last_pipeline_zip()
|
| 3298 |
if not last_zip:
|
|
@@ -3307,7 +3309,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3307 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3308 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3309 |
else:
|
| 3310 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 3311 |
|
| 3312 |
# Prepare workspace
|
| 3313 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -3324,7 +3326,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3324 |
except Exception as e:
|
| 3325 |
logs.append(f"β unzip failed: {e}")
|
| 3326 |
_write_logs(LOG_PATH, logs)
|
| 3327 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3328 |
|
| 3329 |
# Locate tex
|
| 3330 |
tex_path = None
|
|
@@ -3340,7 +3342,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3340 |
if tex_path is None:
|
| 3341 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3342 |
_write_logs(LOG_PATH, logs)
|
| 3343 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 3344 |
|
| 3345 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3346 |
try:
|
|
@@ -3376,7 +3378,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 3376 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3377 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3378 |
+ "\n".join(logs)
|
| 3379 |
-
+ "</pre>"
|
|
|
|
| 3380 |
)
|
| 3381 |
try:
|
| 3382 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
@@ -3386,17 +3389,17 @@ def debug_compile_last_pipeline_zip():
|
|
| 3386 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3387 |
)
|
| 3388 |
_write_logs(LOG_PATH, logs)
|
| 3389 |
-
return html
|
| 3390 |
except Exception as e:
|
| 3391 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3392 |
_write_logs(LOG_PATH, logs)
|
| 3393 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3394 |
|
| 3395 |
def debug_compile_uploaded_zip(zip_file):
|
| 3396 |
-
"""Compile an uploaded poster zip (user-provided)
|
| 3397 |
logs = [f"π Debug(upload) at {_now_str()}"]
|
| 3398 |
if not zip_file:
|
| 3399 |
-
return "<div style='color:#b00'>Please upload a .zip file first.</div>"
|
| 3400 |
# Prepare workspace
|
| 3401 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 3402 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
@@ -3408,7 +3411,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3408 |
except Exception as e:
|
| 3409 |
logs.append(f"β save upload failed: {e}")
|
| 3410 |
_write_logs(LOG_PATH, logs)
|
| 3411 |
-
return "<div style='color:#b00'>Save upload failed.</div>"
|
| 3412 |
# Extract
|
| 3413 |
try:
|
| 3414 |
import zipfile as _zf
|
|
@@ -3417,7 +3420,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3417 |
except Exception as e:
|
| 3418 |
logs.append(f"β unzip failed: {e}")
|
| 3419 |
_write_logs(LOG_PATH, logs)
|
| 3420 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3421 |
# Find tex
|
| 3422 |
tex_path = None
|
| 3423 |
for name in ("poster_output.tex", "poster.tex"):
|
|
@@ -3461,7 +3464,8 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3461 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3462 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3463 |
+ "\n".join(logs)
|
| 3464 |
-
+ "</pre>"
|
|
|
|
| 3465 |
)
|
| 3466 |
try:
|
| 3467 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
@@ -3471,11 +3475,11 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3471 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3472 |
)
|
| 3473 |
_write_logs(LOG_PATH, logs)
|
| 3474 |
-
return html
|
| 3475 |
except Exception as e:
|
| 3476 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3477 |
_write_logs(LOG_PATH, logs)
|
| 3478 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3479 |
|
| 3480 |
# =====================
|
| 3481 |
# Gradio pipeline function (ISOLATED)
|
|
|
|
| 3172 |
if not zip_path.exists():
|
| 3173 |
return (
|
| 3174 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3175 |
+
+ f"<div>Expected at: {zip_path}</div>",
|
| 3176 |
+
None,
|
| 3177 |
)
|
| 3178 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3179 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
|
|
| 3209 |
except Exception as e:
|
| 3210 |
logs.append(f"β unzip failed: {e}")
|
| 3211 |
_write_logs(LOG_PATH, logs)
|
| 3212 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3213 |
|
| 3214 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3215 |
tex_path = None
|
|
|
|
| 3226 |
if tex_path is None:
|
| 3227 |
logs.append("β No .tex file found in output.zip")
|
| 3228 |
_write_logs(LOG_PATH, logs)
|
| 3229 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 3230 |
|
| 3231 |
# If left_logo missing, disable \logoleft
|
| 3232 |
try:
|
|
|
|
| 3257 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3258 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3259 |
+ "\n".join(logs)
|
| 3260 |
+
+ "</pre>",
|
| 3261 |
+
None,
|
| 3262 |
)
|
| 3263 |
|
| 3264 |
try:
|
|
|
|
| 3269 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3270 |
)
|
| 3271 |
_write_logs(LOG_PATH, logs)
|
| 3272 |
+
return html, str(pdf_path)
|
| 3273 |
except Exception as e:
|
| 3274 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3275 |
_write_logs(LOG_PATH, logs)
|
| 3276 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3277 |
|
| 3278 |
def _find_last_pipeline_zip():
|
| 3279 |
try:
|
|
|
|
| 3294 |
return None
|
| 3295 |
|
| 3296 |
def debug_compile_last_pipeline_zip():
|
| 3297 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 3298 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3299 |
last_zip = _find_last_pipeline_zip()
|
| 3300 |
if not last_zip:
|
|
|
|
| 3309 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3310 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3311 |
else:
|
| 3312 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 3313 |
|
| 3314 |
# Prepare workspace
|
| 3315 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 3326 |
except Exception as e:
|
| 3327 |
logs.append(f"β unzip failed: {e}")
|
| 3328 |
_write_logs(LOG_PATH, logs)
|
| 3329 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3330 |
|
| 3331 |
# Locate tex
|
| 3332 |
tex_path = None
|
|
|
|
| 3342 |
if tex_path is None:
|
| 3343 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3344 |
_write_logs(LOG_PATH, logs)
|
| 3345 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 3346 |
|
| 3347 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3348 |
try:
|
|
|
|
| 3378 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3379 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3380 |
+ "\n".join(logs)
|
| 3381 |
+
+ "</pre>",
|
| 3382 |
+
None,
|
| 3383 |
)
|
| 3384 |
try:
|
| 3385 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3389 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3390 |
)
|
| 3391 |
_write_logs(LOG_PATH, logs)
|
| 3392 |
+
return html, str(pdf_path)
|
| 3393 |
except Exception as e:
|
| 3394 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3395 |
_write_logs(LOG_PATH, logs)
|
| 3396 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3397 |
|
| 3398 |
def debug_compile_uploaded_zip(zip_file):
|
| 3399 |
+
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
|
| 3400 |
logs = [f"π Debug(upload) at {_now_str()}"]
|
| 3401 |
if not zip_file:
|
| 3402 |
+
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
|
| 3403 |
# Prepare workspace
|
| 3404 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 3405 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
|
|
| 3411 |
except Exception as e:
|
| 3412 |
logs.append(f"β save upload failed: {e}")
|
| 3413 |
_write_logs(LOG_PATH, logs)
|
| 3414 |
+
return "<div style='color:#b00'>Save upload failed.</div>", None
|
| 3415 |
# Extract
|
| 3416 |
try:
|
| 3417 |
import zipfile as _zf
|
|
|
|
| 3420 |
except Exception as e:
|
| 3421 |
logs.append(f"β unzip failed: {e}")
|
| 3422 |
_write_logs(LOG_PATH, logs)
|
| 3423 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3424 |
# Find tex
|
| 3425 |
tex_path = None
|
| 3426 |
for name in ("poster_output.tex", "poster.tex"):
|
|
|
|
| 3464 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3465 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3466 |
+ "\n".join(logs)
|
| 3467 |
+
+ "</pre>",
|
| 3468 |
+
None,
|
| 3469 |
)
|
| 3470 |
try:
|
| 3471 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3475 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3476 |
)
|
| 3477 |
_write_logs(LOG_PATH, logs)
|
| 3478 |
+
return html, str(pdf_path)
|
| 3479 |
except Exception as e:
|
| 3480 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3481 |
_write_logs(LOG_PATH, logs)
|
| 3482 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3483 |
|
| 3484 |
# =====================
|
| 3485 |
# Gradio pipeline function (ISOLATED)
|