Push Bot commited on
Commit
d3eea95
Β·
1 Parent(s): 379dfe4

Debug: add image preview (first page) with PyMuPDF/pdfium; return PDF path from debug flows; chain .then to render image

Browse files
Files changed (1) hide show
  1. app.py +24 -20
app.py CHANGED
@@ -1066,7 +1066,8 @@ def debug_compile_output_zip():
1066
  if not zip_path.exists():
1067
  return (
1068
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
1069
- + f"<div>Expected at: {zip_path}</div>"
 
1070
  )
1071
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
1072
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
@@ -1102,7 +1103,7 @@ def debug_compile_output_zip():
1102
  except Exception as e:
1103
  logs.append(f"❌ unzip failed: {e}")
1104
  _write_logs(LOG_PATH, logs)
1105
- return "<div style='color:#b00'>Unzip failed.</div>"
1106
 
1107
  # Locate poster_output.tex (fallback to poster.tex)
1108
  tex_path = None
@@ -1119,7 +1120,7 @@ def debug_compile_output_zip():
1119
  if tex_path is None:
1120
  logs.append("❌ No .tex file found in output.zip")
1121
  _write_logs(LOG_PATH, logs)
1122
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
1123
 
1124
  # If left_logo missing, disable \logoleft
1125
  try:
@@ -1150,7 +1151,8 @@ def debug_compile_output_zip():
1150
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1151
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1152
  + "\n".join(logs)
1153
- + "</pre>"
 
1154
  )
1155
 
1156
  try:
@@ -1161,11 +1163,11 @@ def debug_compile_output_zip():
1161
  + _pdf_to_iframe_html(pdf_path, height="700px")
1162
  )
1163
  _write_logs(LOG_PATH, logs)
1164
- return html
1165
  except Exception as e:
1166
  logs.append(f"⚠️ preview failed: {e}")
1167
  _write_logs(LOG_PATH, logs)
1168
- return f"<div>Compiled but preview failed: {e}</div>"
1169
 
1170
  def _find_last_pipeline_zip():
1171
  try:
@@ -1186,7 +1188,7 @@ def _find_last_pipeline_zip():
1186
  return None
1187
 
1188
  def debug_compile_last_pipeline_zip():
1189
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
1190
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1191
  last_zip = _find_last_pipeline_zip()
1192
  if not last_zip:
@@ -1201,7 +1203,7 @@ def debug_compile_last_pipeline_zip():
1201
  logs.append(f"❌ Auto-stage failed: {e}")
1202
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1203
  else:
1204
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
1205
 
1206
  # Prepare workspace
1207
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -1218,7 +1220,7 @@ def debug_compile_last_pipeline_zip():
1218
  except Exception as e:
1219
  logs.append(f"❌ unzip failed: {e}")
1220
  _write_logs(LOG_PATH, logs)
1221
- return "<div style='color:#b00'>Unzip failed.</div>"
1222
 
1223
  # Locate tex
1224
  tex_path = None
@@ -1234,7 +1236,7 @@ def debug_compile_last_pipeline_zip():
1234
  if tex_path is None:
1235
  logs.append("❌ No .tex file found in last pipeline zip")
1236
  _write_logs(LOG_PATH, logs)
1237
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
1238
 
1239
  # Ensure local fonts and theme precedence (same as other debug path)
1240
  try:
@@ -1270,7 +1272,8 @@ def debug_compile_last_pipeline_zip():
1270
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1271
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1272
  + "\n".join(logs)
1273
- + "</pre>"
 
1274
  )
1275
  try:
1276
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -1280,17 +1283,17 @@ def debug_compile_last_pipeline_zip():
1280
  + _pdf_to_iframe_html(pdf_path, height="700px")
1281
  )
1282
  _write_logs(LOG_PATH, logs)
1283
- return html
1284
  except Exception as e:
1285
  logs.append(f"⚠️ preview failed: {e}")
1286
  _write_logs(LOG_PATH, logs)
1287
- return f"<div>Compiled but preview failed: {e}</div>"
1288
 
1289
  def debug_compile_uploaded_zip(zip_file):
1290
- """Compile an uploaded poster zip (user-provided) and preview PDF."""
1291
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1292
  if not zip_file:
1293
- return "<div style='color:#b00'>Please upload a .zip file first.</div>"
1294
  # Prepare workspace
1295
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1296
  work_zip_dir = WORK_DIR / "zip_upload"
@@ -1302,7 +1305,7 @@ def debug_compile_uploaded_zip(zip_file):
1302
  except Exception as e:
1303
  logs.append(f"❌ save upload failed: {e}")
1304
  _write_logs(LOG_PATH, logs)
1305
- return "<div style='color:#b00'>Save upload failed.</div>"
1306
  # Extract
1307
  try:
1308
  import zipfile as _zf
@@ -1311,7 +1314,7 @@ def debug_compile_uploaded_zip(zip_file):
1311
  except Exception as e:
1312
  logs.append(f"❌ unzip failed: {e}")
1313
  _write_logs(LOG_PATH, logs)
1314
- return "<div style='color:#b00'>Unzip failed.</div>"
1315
  # Find tex
1316
  tex_path = None
1317
  for name in ("poster_output.tex", "poster.tex"):
@@ -1355,7 +1358,8 @@ def debug_compile_uploaded_zip(zip_file):
1355
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1356
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1357
  + "\n".join(logs)
1358
- + "</pre>"
 
1359
  )
1360
  try:
1361
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -1677,11 +1681,11 @@ def debug_compile_uploaded_zip(zip_file):
1677
  + _pdf_to_iframe_html(pdf_path, height="700px")
1678
  )
1679
  _write_logs(LOG_PATH, logs)
1680
- return html
1681
  except Exception as e:
1682
  logs.append(f"⚠️ preview failed: {e}")
1683
  _write_logs(LOG_PATH, logs)
1684
- return f"<div>Compiled but preview failed: {e}</div>"
1685
 
1686
  def debug_compile_output_zip():
1687
  """Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
 
1066
  if not zip_path.exists():
1067
  return (
1068
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
1069
+ + f"<div>Expected at: {zip_path}</div>",
1070
+ None,
1071
  )
1072
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
1073
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
 
1103
  except Exception as e:
1104
  logs.append(f"❌ unzip failed: {e}")
1105
  _write_logs(LOG_PATH, logs)
1106
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1107
 
1108
  # Locate poster_output.tex (fallback to poster.tex)
1109
  tex_path = None
 
1120
  if tex_path is None:
1121
  logs.append("❌ No .tex file found in output.zip")
1122
  _write_logs(LOG_PATH, logs)
1123
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
1124
 
1125
  # If left_logo missing, disable \logoleft
1126
  try:
 
1151
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1152
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1153
  + "\n".join(logs)
1154
+ + "</pre>",
1155
+ None,
1156
  )
1157
 
1158
  try:
 
1163
  + _pdf_to_iframe_html(pdf_path, height="700px")
1164
  )
1165
  _write_logs(LOG_PATH, logs)
1166
+ return html, str(pdf_path)
1167
  except Exception as e:
1168
  logs.append(f"⚠️ preview failed: {e}")
1169
  _write_logs(LOG_PATH, logs)
1170
+ return f"<div>Compiled but preview failed: {e}</div>", None
1171
 
1172
  def _find_last_pipeline_zip():
1173
  try:
 
1188
  return None
1189
 
1190
  def debug_compile_last_pipeline_zip():
1191
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
1192
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1193
  last_zip = _find_last_pipeline_zip()
1194
  if not last_zip:
 
1203
  logs.append(f"❌ Auto-stage failed: {e}")
1204
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1205
  else:
1206
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
1207
 
1208
  # Prepare workspace
1209
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
1220
  except Exception as e:
1221
  logs.append(f"❌ unzip failed: {e}")
1222
  _write_logs(LOG_PATH, logs)
1223
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1224
 
1225
  # Locate tex
1226
  tex_path = None
 
1236
  if tex_path is None:
1237
  logs.append("❌ No .tex file found in last pipeline zip")
1238
  _write_logs(LOG_PATH, logs)
1239
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
1240
 
1241
  # Ensure local fonts and theme precedence (same as other debug path)
1242
  try:
 
1272
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1273
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1274
  + "\n".join(logs)
1275
+ + "</pre>",
1276
+ None,
1277
  )
1278
  try:
1279
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1283
  + _pdf_to_iframe_html(pdf_path, height="700px")
1284
  )
1285
  _write_logs(LOG_PATH, logs)
1286
+ return html, str(pdf_path)
1287
  except Exception as e:
1288
  logs.append(f"⚠️ preview failed: {e}")
1289
  _write_logs(LOG_PATH, logs)
1290
+ return f"<div>Compiled but preview failed: {e}</div>", None
1291
 
1292
  def debug_compile_uploaded_zip(zip_file):
1293
+ """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
1294
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1295
  if not zip_file:
1296
+ return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
1297
  # Prepare workspace
1298
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1299
  work_zip_dir = WORK_DIR / "zip_upload"
 
1305
  except Exception as e:
1306
  logs.append(f"❌ save upload failed: {e}")
1307
  _write_logs(LOG_PATH, logs)
1308
+ return "<div style='color:#b00'>Save upload failed.</div>", None
1309
  # Extract
1310
  try:
1311
  import zipfile as _zf
 
1314
  except Exception as e:
1315
  logs.append(f"❌ unzip failed: {e}")
1316
  _write_logs(LOG_PATH, logs)
1317
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1318
  # Find tex
1319
  tex_path = None
1320
  for name in ("poster_output.tex", "poster.tex"):
 
1358
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1359
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1360
  + "\n".join(logs)
1361
+ + "</pre>",
1362
+ None,
1363
  )
1364
  try:
1365
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1681
  + _pdf_to_iframe_html(pdf_path, height="700px")
1682
  )
1683
  _write_logs(LOG_PATH, logs)
1684
+ return html, str(pdf_path)
1685
  except Exception as e:
1686
  logs.append(f"⚠️ preview failed: {e}")
1687
  _write_logs(LOG_PATH, logs)
1688
+ return f"<div>Compiled but preview failed: {e}</div>", None
1689
 
1690
  def debug_compile_output_zip():
1691
  """Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""