Spaces:
Sleeping
Sleeping
Push Bot
commited on
Commit
Β·
331aeb2
1
Parent(s):
b191b73
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
|
@@ -2081,7 +2081,7 @@ def debug_compile_output_zip():
|
|
| 2081 |
except Exception as e:
|
| 2082 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2083 |
_write_logs(LOG_PATH, logs)
|
| 2084 |
-
return f"<div>Compiled but preview failed: {e}</div>"
|
| 2085 |
|
| 2086 |
def _find_last_pipeline_zip():
|
| 2087 |
try:
|
|
@@ -2102,7 +2102,7 @@ def _find_last_pipeline_zip():
|
|
| 2102 |
return None
|
| 2103 |
|
| 2104 |
def debug_compile_last_pipeline_zip():
|
| 2105 |
-
"""Find the most recent runs/*/output.zip from pipeline, compile, and preview
|
| 2106 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 2107 |
last_zip = _find_last_pipeline_zip()
|
| 2108 |
if not last_zip:
|
|
@@ -2117,7 +2117,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2117 |
logs.append(f"β Auto-stage failed: {e}")
|
| 2118 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 2119 |
else:
|
| 2120 |
-
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
|
| 2121 |
|
| 2122 |
# Prepare workspace
|
| 2123 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
@@ -2134,7 +2134,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2134 |
except Exception as e:
|
| 2135 |
logs.append(f"β unzip failed: {e}")
|
| 2136 |
_write_logs(LOG_PATH, logs)
|
| 2137 |
-
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 2138 |
|
| 2139 |
# Locate tex
|
| 2140 |
tex_path = None
|
|
@@ -2150,7 +2150,7 @@ def debug_compile_last_pipeline_zip():
|
|
| 2150 |
if tex_path is None:
|
| 2151 |
logs.append("β No .tex file found in last pipeline zip")
|
| 2152 |
_write_logs(LOG_PATH, logs)
|
| 2153 |
-
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
|
| 2154 |
|
| 2155 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 2156 |
try:
|
|
@@ -2186,7 +2186,8 @@ def debug_compile_last_pipeline_zip():
|
|
| 2186 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2187 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2188 |
+ "\n".join(logs)
|
| 2189 |
-
+ "</pre>"
|
|
|
|
| 2190 |
)
|
| 2191 |
try:
|
| 2192 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
|
|
|
| 2081 |
except Exception as e:
|
| 2082 |
logs.append(f"β οΈ preview failed: {e}")
|
| 2083 |
_write_logs(LOG_PATH, logs)
|
| 2084 |
+
return f"<div>Compiled but preview failed: {e}</div>", None
|
| 2085 |
|
| 2086 |
def _find_last_pipeline_zip():
|
| 2087 |
try:
|
|
|
|
| 2102 |
return None
|
| 2103 |
|
| 2104 |
def debug_compile_last_pipeline_zip():
|
| 2105 |
+
"""Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
|
| 2106 |
logs = [f"π Debug(last-pipeline-zip) at {_now_str()}"]
|
| 2107 |
last_zip = _find_last_pipeline_zip()
|
| 2108 |
if not last_zip:
|
|
|
|
| 2117 |
logs.append(f"β Auto-stage failed: {e}")
|
| 2118 |
return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
|
| 2119 |
else:
|
| 2120 |
+
return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
|
| 2121 |
|
| 2122 |
# Prepare workspace
|
| 2123 |
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
|
|
|
| 2134 |
except Exception as e:
|
| 2135 |
logs.append(f"β unzip failed: {e}")
|
| 2136 |
_write_logs(LOG_PATH, logs)
|
| 2137 |
+
return "<div style='color:#b00'>Unzip failed.</div>", None
|
| 2138 |
|
| 2139 |
# Locate tex
|
| 2140 |
tex_path = None
|
|
|
|
| 2150 |
if tex_path is None:
|
| 2151 |
logs.append("β No .tex file found in last pipeline zip")
|
| 2152 |
_write_logs(LOG_PATH, logs)
|
| 2153 |
+
return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
|
| 2154 |
|
| 2155 |
# Ensure local fonts and theme precedence (same as other debug path)
|
| 2156 |
try:
|
|
|
|
| 2186 |
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 2187 |
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 2188 |
+ "\n".join(logs)
|
| 2189 |
+
+ "</pre>",
|
| 2190 |
+
None,
|
| 2191 |
)
|
| 2192 |
try:
|
| 2193 |
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|