Push Bot commited on
Commit
4aadfea
Β·
1 Parent(s): fb4b7b1

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
@@ -2192,7 +2192,8 @@ def debug_compile_output_zip():
2192
  if not zip_path.exists():
2193
  return (
2194
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
2195
- + f"<div>Expected at: {zip_path}</div>"
 
2196
  )
2197
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
2198
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
@@ -2228,7 +2229,7 @@ def debug_compile_output_zip():
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
 
2233
  # Locate poster_output.tex (fallback to poster.tex)
2234
  tex_path = None
@@ -2245,7 +2246,7 @@ def debug_compile_output_zip():
2245
  if tex_path is None:
2246
  logs.append("❌ No .tex file found in output.zip")
2247
  _write_logs(LOG_PATH, logs)
2248
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
2249
 
2250
  # If left_logo missing, disable \logoleft
2251
  try:
@@ -2276,7 +2277,8 @@ def debug_compile_output_zip():
2276
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2277
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2278
  + "\n".join(logs)
2279
- + "</pre>"
 
2280
  )
2281
 
2282
  try:
@@ -2287,11 +2289,11 @@ def debug_compile_output_zip():
2287
  + _pdf_to_iframe_html(pdf_path, height="700px")
2288
  )
2289
  _write_logs(LOG_PATH, logs)
2290
- return html
2291
  except Exception as e:
2292
  logs.append(f"⚠️ preview failed: {e}")
2293
  _write_logs(LOG_PATH, logs)
2294
- return f"<div>Compiled but preview failed: {e}</div>"
2295
 
2296
  def _find_last_pipeline_zip():
2297
  try:
@@ -2312,7 +2314,7 @@ def _find_last_pipeline_zip():
2312
  return None
2313
 
2314
  def debug_compile_last_pipeline_zip():
2315
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
2316
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
2317
  last_zip = _find_last_pipeline_zip()
2318
  if not last_zip:
@@ -2327,7 +2329,7 @@ def debug_compile_last_pipeline_zip():
2327
  logs.append(f"❌ Auto-stage failed: {e}")
2328
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
2329
  else:
2330
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
2331
 
2332
  # Prepare workspace
2333
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -2344,7 +2346,7 @@ def debug_compile_last_pipeline_zip():
2344
  except Exception as e:
2345
  logs.append(f"❌ unzip failed: {e}")
2346
  _write_logs(LOG_PATH, logs)
2347
- return "<div style='color:#b00'>Unzip failed.</div>"
2348
 
2349
  # Locate tex
2350
  tex_path = None
@@ -2360,7 +2362,7 @@ def debug_compile_last_pipeline_zip():
2360
  if tex_path is None:
2361
  logs.append("❌ No .tex file found in last pipeline zip")
2362
  _write_logs(LOG_PATH, logs)
2363
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
2364
 
2365
  # Ensure local fonts and theme precedence (same as other debug path)
2366
  try:
@@ -2396,7 +2398,8 @@ def debug_compile_last_pipeline_zip():
2396
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2397
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2398
  + "\n".join(logs)
2399
- + "</pre>"
 
2400
  )
2401
  try:
2402
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -2406,17 +2409,17 @@ def debug_compile_last_pipeline_zip():
2406
  + _pdf_to_iframe_html(pdf_path, height="700px")
2407
  )
2408
  _write_logs(LOG_PATH, logs)
2409
- return html
2410
  except Exception as e:
2411
  logs.append(f"⚠️ preview failed: {e}")
2412
  _write_logs(LOG_PATH, logs)
2413
- return f"<div>Compiled but preview failed: {e}</div>"
2414
 
2415
  def debug_compile_uploaded_zip(zip_file):
2416
- """Compile an uploaded poster zip (user-provided) and preview PDF."""
2417
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
2418
  if not zip_file:
2419
- return "<div style='color:#b00'>Please upload a .zip file first.</div>"
2420
  # Prepare workspace
2421
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
2422
  work_zip_dir = WORK_DIR / "zip_upload"
@@ -2428,7 +2431,7 @@ def debug_compile_uploaded_zip(zip_file):
2428
  except Exception as e:
2429
  logs.append(f"❌ save upload failed: {e}")
2430
  _write_logs(LOG_PATH, logs)
2431
- return "<div style='color:#b00'>Save upload failed.</div>"
2432
  # Extract
2433
  try:
2434
  import zipfile as _zf
@@ -2437,7 +2440,7 @@ def debug_compile_uploaded_zip(zip_file):
2437
  except Exception as e:
2438
  logs.append(f"❌ unzip failed: {e}")
2439
  _write_logs(LOG_PATH, logs)
2440
- return "<div style='color:#b00'>Unzip failed.</div>"
2441
  # Find tex
2442
  tex_path = None
2443
  for name in ("poster_output.tex", "poster.tex"):
@@ -2481,7 +2484,8 @@ def debug_compile_uploaded_zip(zip_file):
2481
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2482
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2483
  + "\n".join(logs)
2484
- + "</pre>"
 
2485
  )
2486
  try:
2487
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -2491,11 +2495,11 @@ def debug_compile_uploaded_zip(zip_file):
2491
  + _pdf_to_iframe_html(pdf_path, height="700px")
2492
  )
2493
  _write_logs(LOG_PATH, logs)
2494
- return html
2495
  except Exception as e:
2496
  logs.append(f"⚠️ preview failed: {e}")
2497
  _write_logs(LOG_PATH, logs)
2498
- return f"<div>Compiled but preview failed: {e}</div>"
2499
 
2500
  # =====================
2501
  # Gradio pipeline function (ISOLATED)
 
2192
  if not zip_path.exists():
2193
  return (
2194
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
2195
+ + f"<div>Expected at: {zip_path}</div>",
2196
+ None,
2197
  )
2198
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
2199
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
 
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
 
2234
  # Locate poster_output.tex (fallback to poster.tex)
2235
  tex_path = None
 
2246
  if tex_path is None:
2247
  logs.append("❌ No .tex file found in output.zip")
2248
  _write_logs(LOG_PATH, logs)
2249
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
2250
 
2251
  # If left_logo missing, disable \logoleft
2252
  try:
 
2277
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2278
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2279
  + "\n".join(logs)
2280
+ + "</pre>",
2281
+ None,
2282
  )
2283
 
2284
  try:
 
2289
  + _pdf_to_iframe_html(pdf_path, height="700px")
2290
  )
2291
  _write_logs(LOG_PATH, logs)
2292
+ return html, str(pdf_path)
2293
  except Exception as e:
2294
  logs.append(f"⚠️ preview failed: {e}")
2295
  _write_logs(LOG_PATH, logs)
2296
+ return f"<div>Compiled but preview failed: {e}</div>", None
2297
 
2298
  def _find_last_pipeline_zip():
2299
  try:
 
2314
  return None
2315
 
2316
  def debug_compile_last_pipeline_zip():
2317
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
2318
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
2319
  last_zip = _find_last_pipeline_zip()
2320
  if not last_zip:
 
2329
  logs.append(f"❌ Auto-stage failed: {e}")
2330
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
2331
  else:
2332
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
2333
 
2334
  # Prepare workspace
2335
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
2346
  except Exception as e:
2347
  logs.append(f"❌ unzip failed: {e}")
2348
  _write_logs(LOG_PATH, logs)
2349
+ return "<div style='color:#b00'>Unzip failed.</div>", None
2350
 
2351
  # Locate tex
2352
  tex_path = None
 
2362
  if tex_path is None:
2363
  logs.append("❌ No .tex file found in last pipeline zip")
2364
  _write_logs(LOG_PATH, logs)
2365
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
2366
 
2367
  # Ensure local fonts and theme precedence (same as other debug path)
2368
  try:
 
2398
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2399
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2400
  + "\n".join(logs)
2401
+ + "</pre>",
2402
+ None,
2403
  )
2404
  try:
2405
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
2409
  + _pdf_to_iframe_html(pdf_path, height="700px")
2410
  )
2411
  _write_logs(LOG_PATH, logs)
2412
+ return html, str(pdf_path)
2413
  except Exception as e:
2414
  logs.append(f"⚠️ preview failed: {e}")
2415
  _write_logs(LOG_PATH, logs)
2416
+ return f"<div>Compiled but preview failed: {e}</div>", None
2417
 
2418
  def debug_compile_uploaded_zip(zip_file):
2419
+ """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
2420
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
2421
  if not zip_file:
2422
+ return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
2423
  # Prepare workspace
2424
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
2425
  work_zip_dir = WORK_DIR / "zip_upload"
 
2431
  except Exception as e:
2432
  logs.append(f"❌ save upload failed: {e}")
2433
  _write_logs(LOG_PATH, logs)
2434
+ return "<div style='color:#b00'>Save upload failed.</div>", None
2435
  # Extract
2436
  try:
2437
  import zipfile as _zf
 
2440
  except Exception as e:
2441
  logs.append(f"❌ unzip failed: {e}")
2442
  _write_logs(LOG_PATH, logs)
2443
+ return "<div style='color:#b00'>Unzip failed.</div>", None
2444
  # Find tex
2445
  tex_path = None
2446
  for name in ("poster_output.tex", "poster.tex"):
 
2484
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2485
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2486
  + "\n".join(logs)
2487
+ + "</pre>",
2488
+ None,
2489
  )
2490
  try:
2491
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
2495
  + _pdf_to_iframe_html(pdf_path, height="700px")
2496
  )
2497
  _write_logs(LOG_PATH, logs)
2498
+ return html, str(pdf_path)
2499
  except Exception as e:
2500
  logs.append(f"⚠️ preview failed: {e}")
2501
  _write_logs(LOG_PATH, logs)
2502
+ return f"<div>Compiled but preview failed: {e}</div>", None
2503
 
2504
  # =====================
2505
  # Gradio pipeline function (ISOLATED)