Spaces:
Sleeping
Sleeping
Push Bot
commited on
Commit
·
0488d17
1
Parent(s):
9c9bb0e
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
|
@@ -3010,17 +3010,17 @@ def debug_compile_last_pipeline_zip():
|
|
| 3010 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3011 |
)
|
| 3012 |
_write_logs(LOG_PATH, logs)
|
| 3013 |
-
return html
|
| 3014 |
except Exception as e:
|
| 3015 |
logs.append(f"⚠️ preview failed: {e}")
|
| 3016 |
_write_logs(LOG_PATH, logs)
|
| 3017 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 3018 |
|
| 3019 |
def debug_compile_uploaded_zip(zip_file):
|
| 3020 |
-
"""Compile an uploaded poster zip (user-provided)
|
| 3021 |
logs = [f"🐞 Debug(upload) at {_now_str()}"]
|
| 3022 |
if not zip_file:
|
| 3023 |
-
return "<div style='color:#b00'>Please upload a .zip file first.</div>"
|
| 3024 |
# Prepare workspace
|
| 3025 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 3026 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
@@ -3032,7 +3032,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3032 |
except Exception as e:
|
| 3033 |
logs.append(f"❌ save upload failed: {e}")
|
| 3034 |
_write_logs(LOG_PATH, logs)
|
| 3035 |
-
return "<div style='color:#b00'>Save upload failed.</div>"
|
| 3036 |
# Extract
|
| 3037 |
try:
|
| 3038 |
import zipfile as _zf
|
|
@@ -3041,7 +3041,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3041 |
except Exception as e:
|
| 3042 |
logs.append(f"❌ unzip failed: {e}")
|
| 3043 |
_write_logs(LOG_PATH, logs)
|
| 3044 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 3045 |
# Find tex
|
| 3046 |
tex_path = None
|
| 3047 |
for name in ("poster_output.tex", "poster.tex"):
|
|
@@ -3085,7 +3085,8 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 3085 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3086 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3087 |
+ "\n".join(logs)
|
| 3088 |
-
+ "</pre>"
|
|
|
|
| 3089 |
)
|
| 3090 |
try:
|
| 3091 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 3010 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 3011 |
)
|
| 3012 |
_write_logs(LOG_PATH, logs)
|
| 3013 |
+
return html, str(pdf_path)
|
| 3014 |
except Exception as e:
|
| 3015 |
logs.append(f"⚠️ preview failed: {e}")
|
| 3016 |
_write_logs(LOG_PATH, logs)
|
| 3017 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 3018 |
|
| 3019 |
def debug_compile_uploaded_zip(zip_file):
|
| 3020 |
+
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
|
| 3021 |
logs = [f"🐞 Debug(upload) at {_now_str()}"]
|
| 3022 |
if not zip_file:
|
| 3023 |
+
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
|
| 3024 |
# Prepare workspace
|
| 3025 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 3026 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
|
|
| 3032 |
except Exception as e:
|
| 3033 |
logs.append(f"❌ save upload failed: {e}")
|
| 3034 |
_write_logs(LOG_PATH, logs)
|
| 3035 |
+
return "<div style='color:#b00'>Save upload failed.</div>", None
|
| 3036 |
# Extract
|
| 3037 |
try:
|
| 3038 |
import zipfile as _zf
|
|
|
|
| 3041 |
except Exception as e:
|
| 3042 |
logs.append(f"❌ unzip failed: {e}")
|
| 3043 |
_write_logs(LOG_PATH, logs)
|
| 3044 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 3045 |
# Find tex
|
| 3046 |
tex_path = None
|
| 3047 |
for name in ("poster_output.tex", "poster.tex"):
|
|
|
|
| 3085 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 3086 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 3087 |
+ "\n".join(logs)
|
| 3088 |
+
+ "</pre>",
|
| 3089 |
+
None,
|
| 3090 |
)
|
| 3091 |
try:
|
| 3092 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|