Push Bot commited on
Commit
a25bc66
Β·
1 Parent(s): 9535a4e

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
@@ -1060,7 +1060,8 @@ def debug_compile_output_zip():
1060
  if not zip_path.exists():
1061
  return (
1062
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
1063
- + f"<div>Expected at: {zip_path}</div>"
 
1064
  )
1065
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
1066
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
@@ -1096,7 +1097,7 @@ def debug_compile_output_zip():
1096
  except Exception as e:
1097
  logs.append(f"❌ unzip failed: {e}")
1098
  _write_logs(LOG_PATH, logs)
1099
- return "<div style='color:#b00'>Unzip failed.</div>"
1100
 
1101
  # Locate poster_output.tex (fallback to poster.tex)
1102
  tex_path = None
@@ -1113,7 +1114,7 @@ def debug_compile_output_zip():
1113
  if tex_path is None:
1114
  logs.append("❌ No .tex file found in output.zip")
1115
  _write_logs(LOG_PATH, logs)
1116
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
1117
 
1118
  # If left_logo missing, disable \logoleft
1119
  try:
@@ -1144,7 +1145,8 @@ def debug_compile_output_zip():
1144
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1145
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1146
  + "\n".join(logs)
1147
- + "</pre>"
 
1148
  )
1149
 
1150
  try:
@@ -1155,11 +1157,11 @@ def debug_compile_output_zip():
1155
  + _pdf_to_iframe_html(pdf_path, height="700px")
1156
  )
1157
  _write_logs(LOG_PATH, logs)
1158
- return html
1159
  except Exception as e:
1160
  logs.append(f"⚠️ preview failed: {e}")
1161
  _write_logs(LOG_PATH, logs)
1162
- return f"<div>Compiled but preview failed: {e}</div>"
1163
 
1164
  def _find_last_pipeline_zip():
1165
  try:
@@ -1180,7 +1182,7 @@ def _find_last_pipeline_zip():
1180
  return None
1181
 
1182
  def debug_compile_last_pipeline_zip():
1183
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
1184
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1185
  last_zip = _find_last_pipeline_zip()
1186
  if not last_zip:
@@ -1195,7 +1197,7 @@ def debug_compile_last_pipeline_zip():
1195
  logs.append(f"❌ Auto-stage failed: {e}")
1196
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1197
  else:
1198
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
1199
 
1200
  # Prepare workspace
1201
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -1212,7 +1214,7 @@ def debug_compile_last_pipeline_zip():
1212
  except Exception as e:
1213
  logs.append(f"❌ unzip failed: {e}")
1214
  _write_logs(LOG_PATH, logs)
1215
- return "<div style='color:#b00'>Unzip failed.</div>"
1216
 
1217
  # Locate tex
1218
  tex_path = None
@@ -1228,7 +1230,7 @@ def debug_compile_last_pipeline_zip():
1228
  if tex_path is None:
1229
  logs.append("❌ No .tex file found in last pipeline zip")
1230
  _write_logs(LOG_PATH, logs)
1231
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
1232
 
1233
  # Ensure local fonts and theme precedence (same as other debug path)
1234
  try:
@@ -1264,7 +1266,8 @@ def debug_compile_last_pipeline_zip():
1264
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1265
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1266
  + "\n".join(logs)
1267
- + "</pre>"
 
1268
  )
1269
  try:
1270
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -1274,17 +1277,17 @@ def debug_compile_last_pipeline_zip():
1274
  + _pdf_to_iframe_html(pdf_path, height="700px")
1275
  )
1276
  _write_logs(LOG_PATH, logs)
1277
- return html
1278
  except Exception as e:
1279
  logs.append(f"⚠️ preview failed: {e}")
1280
  _write_logs(LOG_PATH, logs)
1281
- return f"<div>Compiled but preview failed: {e}</div>"
1282
 
1283
  def debug_compile_uploaded_zip(zip_file):
1284
- """Compile an uploaded poster zip (user-provided) and preview PDF."""
1285
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1286
  if not zip_file:
1287
- return "<div style='color:#b00'>Please upload a .zip file first.</div>"
1288
  # Prepare workspace
1289
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1290
  work_zip_dir = WORK_DIR / "zip_upload"
@@ -1296,7 +1299,7 @@ def debug_compile_uploaded_zip(zip_file):
1296
  except Exception as e:
1297
  logs.append(f"❌ save upload failed: {e}")
1298
  _write_logs(LOG_PATH, logs)
1299
- return "<div style='color:#b00'>Save upload failed.</div>"
1300
  # Extract
1301
  try:
1302
  import zipfile as _zf
@@ -1305,7 +1308,7 @@ def debug_compile_uploaded_zip(zip_file):
1305
  except Exception as e:
1306
  logs.append(f"❌ unzip failed: {e}")
1307
  _write_logs(LOG_PATH, logs)
1308
- return "<div style='color:#b00'>Unzip failed.</div>"
1309
  # Find tex
1310
  tex_path = None
1311
  for name in ("poster_output.tex", "poster.tex"):
@@ -1349,7 +1352,8 @@ def debug_compile_uploaded_zip(zip_file):
1349
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1350
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1351
  + "\n".join(logs)
1352
- + "</pre>"
 
1353
  )
1354
  try:
1355
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -1671,11 +1675,11 @@ def debug_compile_uploaded_zip(zip_file):
1671
  + _pdf_to_iframe_html(pdf_path, height="700px")
1672
  )
1673
  _write_logs(LOG_PATH, logs)
1674
- return html
1675
  except Exception as e:
1676
  logs.append(f"⚠️ preview failed: {e}")
1677
  _write_logs(LOG_PATH, logs)
1678
- return f"<div>Compiled but preview failed: {e}</div>"
1679
 
1680
  # =====================
1681
  # Gradio pipeline function (ISOLATED)
 
1060
  if not zip_path.exists():
1061
  return (
1062
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
1063
+ + f"<div>Expected at: {zip_path}</div>",
1064
+ None,
1065
  )
1066
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
1067
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
 
1097
  except Exception as e:
1098
  logs.append(f"❌ unzip failed: {e}")
1099
  _write_logs(LOG_PATH, logs)
1100
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1101
 
1102
  # Locate poster_output.tex (fallback to poster.tex)
1103
  tex_path = None
 
1114
  if tex_path is None:
1115
  logs.append("❌ No .tex file found in output.zip")
1116
  _write_logs(LOG_PATH, logs)
1117
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
1118
 
1119
  # If left_logo missing, disable \logoleft
1120
  try:
 
1145
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1146
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1147
  + "\n".join(logs)
1148
+ + "</pre>",
1149
+ None,
1150
  )
1151
 
1152
  try:
 
1157
  + _pdf_to_iframe_html(pdf_path, height="700px")
1158
  )
1159
  _write_logs(LOG_PATH, logs)
1160
+ return html, str(pdf_path)
1161
  except Exception as e:
1162
  logs.append(f"⚠️ preview failed: {e}")
1163
  _write_logs(LOG_PATH, logs)
1164
+ return f"<div>Compiled but preview failed: {e}</div>", None
1165
 
1166
  def _find_last_pipeline_zip():
1167
  try:
 
1182
  return None
1183
 
1184
  def debug_compile_last_pipeline_zip():
1185
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
1186
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1187
  last_zip = _find_last_pipeline_zip()
1188
  if not last_zip:
 
1197
  logs.append(f"❌ Auto-stage failed: {e}")
1198
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1199
  else:
1200
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
1201
 
1202
  # Prepare workspace
1203
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
1214
  except Exception as e:
1215
  logs.append(f"❌ unzip failed: {e}")
1216
  _write_logs(LOG_PATH, logs)
1217
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1218
 
1219
  # Locate tex
1220
  tex_path = None
 
1230
  if tex_path is None:
1231
  logs.append("❌ No .tex file found in last pipeline zip")
1232
  _write_logs(LOG_PATH, logs)
1233
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
1234
 
1235
  # Ensure local fonts and theme precedence (same as other debug path)
1236
  try:
 
1266
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1267
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1268
  + "\n".join(logs)
1269
+ + "</pre>",
1270
+ None,
1271
  )
1272
  try:
1273
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1277
  + _pdf_to_iframe_html(pdf_path, height="700px")
1278
  )
1279
  _write_logs(LOG_PATH, logs)
1280
+ return html, str(pdf_path)
1281
  except Exception as e:
1282
  logs.append(f"⚠️ preview failed: {e}")
1283
  _write_logs(LOG_PATH, logs)
1284
+ return f"<div>Compiled but preview failed: {e}</div>", None
1285
 
1286
  def debug_compile_uploaded_zip(zip_file):
1287
+ """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
1288
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1289
  if not zip_file:
1290
+ return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
1291
  # Prepare workspace
1292
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1293
  work_zip_dir = WORK_DIR / "zip_upload"
 
1299
  except Exception as e:
1300
  logs.append(f"❌ save upload failed: {e}")
1301
  _write_logs(LOG_PATH, logs)
1302
+ return "<div style='color:#b00'>Save upload failed.</div>", None
1303
  # Extract
1304
  try:
1305
  import zipfile as _zf
 
1308
  except Exception as e:
1309
  logs.append(f"❌ unzip failed: {e}")
1310
  _write_logs(LOG_PATH, logs)
1311
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1312
  # Find tex
1313
  tex_path = None
1314
  for name in ("poster_output.tex", "poster.tex"):
 
1352
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1353
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1354
  + "\n".join(logs)
1355
+ + "</pre>",
1356
+ None,
1357
  )
1358
  try:
1359
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1675
  + _pdf_to_iframe_html(pdf_path, height="700px")
1676
  )
1677
  _write_logs(LOG_PATH, logs)
1678
+ return html, str(pdf_path)
1679
  except Exception as e:
1680
  logs.append(f"⚠️ preview failed: {e}")
1681
  _write_logs(LOG_PATH, logs)
1682
+ return f"<div>Compiled but preview failed: {e}</div>", None
1683
 
1684
  # =====================
1685
  # Gradio pipeline function (ISOLATED)