Spaces:
Sleeping
Sleeping
Push Bot
commited on
Commit
·
a437861
1
Parent(s):
289fc20
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
|
@@ -2035,7 +2035,7 @@ def debug_compile_output_zip():
|
|
| 2035 |
if tex_path is None:
|
| 2036 |
logs.append("❌ No .tex file found in output.zip")
|
| 2037 |
_write_logs(LOG_PATH, logs)
|
| 2038 |
-
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 2039 |
|
| 2040 |
# If left_logo missing, disable \logoleft
|
| 2041 |
try:
|
|
@@ -2066,7 +2066,8 @@ def debug_compile_output_zip():
|
|
| 2066 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2067 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2068 |
+ "\n".join(logs)
|
| 2069 |
-
+ "</pre>"
|
|
|
|
| 2070 |
)
|
| 2071 |
|
| 2072 |
try:
|
|
@@ -2077,7 +2078,7 @@ def debug_compile_output_zip():
|
|
| 2077 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2078 |
)
|
| 2079 |
_write_logs(LOG_PATH, logs)
|
| 2080 |
-
return html
|
| 2081 |
except Exception as e:
|
| 2082 |
logs.append(f"⚠️ preview failed: {e}")
|
| 2083 |
_write_logs(LOG_PATH, logs)
|
|
@@ -2197,17 +2198,17 @@ def debug_compile_last_pipeline_zip():
|
|
| 2197 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2198 |
)
|
| 2199 |
_write_logs(LOG_PATH, logs)
|
| 2200 |
-
return html
|
| 2201 |
except Exception as e:
|
| 2202 |
logs.append(f"⚠️ preview failed: {e}")
|
| 2203 |
_write_logs(LOG_PATH, logs)
|
| 2204 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 2205 |
|
| 2206 |
def debug_compile_uploaded_zip(zip_file):
|
| 2207 |
-
"""Compile an uploaded poster zip (user-provided)
|
| 2208 |
logs = [f"🐞 Debug(upload) at {_now_str()}"]
|
| 2209 |
if not zip_file:
|
| 2210 |
-
return "<div style='color:#b00'>Please upload a .zip file first.</div>"
|
| 2211 |
# Prepare workspace
|
| 2212 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 2213 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
@@ -2219,7 +2220,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 2219 |
except Exception as e:
|
| 2220 |
logs.append(f"❌ save upload failed: {e}")
|
| 2221 |
_write_logs(LOG_PATH, logs)
|
| 2222 |
-
return "<div style='color:#b00'>Save upload failed.</div>"
|
| 2223 |
# Extract
|
| 2224 |
try:
|
| 2225 |
import zipfile as _zf
|
|
@@ -2228,7 +2229,7 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 2228 |
except Exception as e:
|
| 2229 |
logs.append(f"❌ unzip failed: {e}")
|
| 2230 |
_write_logs(LOG_PATH, logs)
|
| 2231 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 2232 |
# Find tex
|
| 2233 |
tex_path = None
|
| 2234 |
for name in ("poster_output.tex", "poster.tex"):
|
|
@@ -2272,7 +2273,8 @@ def debug_compile_uploaded_zip(zip_file):
|
|
| 2272 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2273 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2274 |
+ "\n".join(logs)
|
| 2275 |
-
+ "</pre>"
|
|
|
|
| 2276 |
)
|
| 2277 |
try:
|
| 2278 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 2035 |
if tex_path is None:
|
| 2036 |
logs.append("❌ No .tex file found in output.zip")
|
| 2037 |
_write_logs(LOG_PATH, logs)
|
| 2038 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>", None
|
| 2039 |
|
| 2040 |
# If left_logo missing, disable \logoleft
|
| 2041 |
try:
|
|
|
|
| 2066 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2067 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2068 |
+ "\n".join(logs)
|
| 2069 |
+
+ "</pre>",
|
| 2070 |
+
None,
|
| 2071 |
)
|
| 2072 |
|
| 2073 |
try:
|
|
|
|
| 2078 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2079 |
)
|
| 2080 |
_write_logs(LOG_PATH, logs)
|
| 2081 |
+
return html, str(pdf_path)
|
| 2082 |
except Exception as e:
|
| 2083 |
logs.append(f"⚠️ preview failed: {e}")
|
| 2084 |
_write_logs(LOG_PATH, logs)
|
|
|
|
| 2198 |
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 2199 |
)
|
| 2200 |
_write_logs(LOG_PATH, logs)
|
| 2201 |
+
return html, str(pdf_path)
|
| 2202 |
except Exception as e:
|
| 2203 |
logs.append(f"⚠️ preview failed: {e}")
|
| 2204 |
_write_logs(LOG_PATH, logs)
|
| 2205 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 2206 |
|
| 2207 |
def debug_compile_uploaded_zip(zip_file):
|
| 2208 |
+
"""Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
|
| 2209 |
logs = [f"🐞 Debug(upload) at {_now_str()}"]
|
| 2210 |
if not zip_file:
|
| 2211 |
+
return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
|
| 2212 |
# Prepare workspace
|
| 2213 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 2214 |
work_zip_dir = WORK_DIR / "zip_upload"
|
|
|
|
| 2220 |
except Exception as e:
|
| 2221 |
logs.append(f"❌ save upload failed: {e}")
|
| 2222 |
_write_logs(LOG_PATH, logs)
|
| 2223 |
+
return "<div style='color:#b00'>Save upload failed.</div>", None
|
| 2224 |
# Extract
|
| 2225 |
try:
|
| 2226 |
import zipfile as _zf
|
|
|
|
| 2229 |
except Exception as e:
|
| 2230 |
logs.append(f"❌ unzip failed: {e}")
|
| 2231 |
_write_logs(LOG_PATH, logs)
|
| 2232 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 2233 |
# Find tex
|
| 2234 |
tex_path = None
|
| 2235 |
for name in ("poster_output.tex", "poster.tex"):
|
|
|
|
| 2273 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2274 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2275 |
+ "\n".join(logs)
|
| 2276 |
+
+ "</pre>",
|
| 2277 |
+
None,
|
| 2278 |
)
|
| 2279 |
try:
|
| 2280 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|