Spaces:
Sleeping
Sleeping
Push Bot
commited on
Commit
Β·
e03ee37
1
Parent(s):
b6bec6c
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
|
@@ -3140,7 +3140,8 @@ def debug_compile_output_zip():
|
|
| 3140 |
if not zip_path.exists():
|
| 3141 |
return (
|
| 3142 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3143 |
-
+ f"<div>Expected at: {zip_path}</div>"
|
|
|
|
| 3144 |
)
|
| 3145 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3146 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
@@ -3176,7 +3177,7 @@ def debug_compile_output_zip():
|
|
| 3176 |
except Exception as e:
|
| 3177 |
logs.append(f"β unzip failed: {e}")
|
| 3178 |
_write_logs(LOG_PATH, logs)
|
| 3179 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3180 |
|
| 3181 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3182 |
tex_path = None
|
|
@@ -3193,7 +3194,7 @@ def debug_compile_output_zip():
|
|
| 3193 |
if tex_path is None:
|
| 3194 |
logs.append("β No .tex file found in output.zip")
|
| 3195 |
_write_logs(LOG_PATH, logs)
|
| 3196 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 3197 |
|
| 3198 |
# If left_logo missing, disable \logoleft
|
| 3199 |
try:
|
|
@@ -3224,7 +3225,8 @@ def debug_compile_output_zip():
|
|
| 3224 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3225 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3226 |
+ "\n".join(logs)
|
| 3227 |
-
+ "</pre>"
|
|
|
|
| 3228 |
)
|
| 3229 |
|
| 3230 |
try:
|
|
@@ -3235,11 +3237,11 @@ def debug_compile_output_zip():
|
|
| 3235 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3236 |
)
|
| 3237 |
_write_logs(LOG_PATH, logs)
|
| 3238 |
-
return html
|
| 3239 |
except Exception as e:
|
| 3240 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3241 |
_write_logs(LOG_PATH, logs)
|
| 3242 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3243 |
|
| 3244 |
def _find_last_pipeline_zip():
|
| 3245 |
try:
|
|
@@ -3260,7 +3262,7 @@ def _find_last_pipeline_zip():
|
|
| 3260 |
return None
|
| 3261 |
|
| 3262 |
def debug_compile_last_pipeline_zip():
|
| 3263 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 3264 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3265 |
last_zip = _find_last_pipeline_zip()
|
| 3266 |
if not last_zip:
|
|
@@ -3275,7 +3277,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3275 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3276 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3277 |
else:
|
| 3278 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 3279 |
|
| 3280 |
# Prepare workspace
|
| 3281 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -3292,7 +3294,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3292 |
except Exception as e:
|
| 3293 |
logs.append(f"β unzip failed: {e}")
|
| 3294 |
_write_logs(LOG_PATH, logs)
|
| 3295 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3296 |
|
| 3297 |
# Locate tex
|
| 3298 |
tex_path = None
|
|
@@ -3308,7 +3310,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 3308 |
if tex_path is None:
|
| 3309 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3310 |
_write_logs(LOG_PATH, logs)
|
| 3311 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 3312 |
|
| 3313 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3314 |
try:
|
|
@@ -3344,7 +3346,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 3344 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3345 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3346 |
+ "\n".join(logs)
|
| 3347 |
-
+ "</pre>"
|
|
|
|
| 3348 |
)
|
| 3349 |
try:
|
| 3350 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3140 |
if not zip_path.exists():
|
| 3141 |
return (
|
| 3142 |
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 3143 |
+
+ f"<div>Expected at: {zip_path}</div>",
|
| 3144 |
+
None,
|
| 3145 |
)
|
| 3146 |
logs = [f"π Stage(repo zip) at {_now_str()}"]
|
| 3147 |
_, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
|
|
|
|
| 3177 |
except Exception as e:
|
| 3178 |
logs.append(f"β unzip failed: {e}")
|
| 3179 |
_write_logs(LOG_PATH, logs)
|
| 3180 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3181 |
|
| 3182 |
# Locate poster_output.tex (fallback to poster.tex)
|
| 3183 |
tex_path = None
|
|
|
|
| 3194 |
if tex_path is None:
|
| 3195 |
logs.append("β No .tex file found in output.zip")
|
| 3196 |
_write_logs(LOG_PATH, logs)
|
| 3197 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 3198 |
|
| 3199 |
# If left_logo missing, disable \logoleft
|
| 3200 |
try:
|
|
|
|
| 3225 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3226 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3227 |
+ "\n".join(logs)
|
| 3228 |
+
+ "</pre>",
|
| 3229 |
+
None,
|
| 3230 |
)
|
| 3231 |
|
| 3232 |
try:
|
|
|
|
| 3237 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3238 |
)
|
| 3239 |
_write_logs(LOG_PATH, logs)
|
| 3240 |
+
return html, str(pdf_path)
|
| 3241 |
except Exception as e:
|
| 3242 |
logs.append(f"β οΈ preview failed: {e}")
|
| 3243 |
_write_logs(LOG_PATH, logs)
|
| 3244 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3245 |
|
| 3246 |
def _find_last_pipeline_zip():
|
| 3247 |
try:
|
|
|
|
| 3262 |
return None
|
| 3263 |
|
| 3264 |
def debug_compile_last_pipeline_zip():
|
| 3265 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 3266 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 3267 |
last_zip = _find_last_pipeline_zip()
|
| 3268 |
if not last_zip:
|
|
|
|
| 3277 |
logs.append(f"β Auto-stage failed: {e}")
|
| 3278 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 3279 |
else:
|
| 3280 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 3281 |
|
| 3282 |
# Prepare workspace
|
| 3283 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 3294 |
except Exception as e:
|
| 3295 |
logs.append(f"β unzip failed: {e}")
|
| 3296 |
_write_logs(LOG_PATH, logs)
|
| 3297 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3298 |
|
| 3299 |
# Locate tex
|
| 3300 |
tex_path = None
|
|
|
|
| 3310 |
if tex_path is None:
|
| 3311 |
logs.append("β No .tex file found in last pipeline zip")
|
| 3312 |
_write_logs(LOG_PATH, logs)
|
| 3313 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 3314 |
|
| 3315 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 3316 |
try:
|
|
|
|
| 3346 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3347 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3348 |
+ "\n".join(logs)
|
| 3349 |
+
+ "</pre>",
|
| 3350 |
+
None,
|
| 3351 |
)
|
| 3352 |
try:
|
| 3353 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|