Push Bot commited on
Commit
0c6109e
Β·
1 Parent(s): 4143d60

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 +22 -18
app.py CHANGED
@@ -1381,7 +1381,8 @@ def debug_compile_output_zip():
1381
  if not zip_path.exists():
1382
  return (
1383
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
1384
- + f"<div>Expected at: {zip_path}</div>"
 
1385
  )
1386
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
1387
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
@@ -1417,7 +1418,7 @@ def debug_compile_output_zip():
1417
  except Exception as e:
1418
  logs.append(f"❌ unzip failed: {e}")
1419
  _write_logs(LOG_PATH, logs)
1420
- return "<div style='color:#b00'>Unzip failed.</div>"
1421
 
1422
  # Locate poster_output.tex (fallback to poster.tex)
1423
  tex_path = None
@@ -1434,7 +1435,7 @@ def debug_compile_output_zip():
1434
  if tex_path is None:
1435
  logs.append("❌ No .tex file found in output.zip")
1436
  _write_logs(LOG_PATH, logs)
1437
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
1438
 
1439
  # If left_logo missing, disable \logoleft
1440
  try:
@@ -1465,7 +1466,8 @@ def debug_compile_output_zip():
1465
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1466
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1467
  + "\n".join(logs)
1468
- + "</pre>"
 
1469
  )
1470
 
1471
  try:
@@ -1476,11 +1478,11 @@ def debug_compile_output_zip():
1476
  + _pdf_to_iframe_html(pdf_path, height="700px")
1477
  )
1478
  _write_logs(LOG_PATH, logs)
1479
- return html
1480
  except Exception as e:
1481
  logs.append(f"⚠️ preview failed: {e}")
1482
  _write_logs(LOG_PATH, logs)
1483
- return f"<div>Compiled but preview failed: {e}</div>"
1484
 
1485
  def _find_last_pipeline_zip():
1486
  try:
@@ -1501,7 +1503,7 @@ def _find_last_pipeline_zip():
1501
  return None
1502
 
1503
  def debug_compile_last_pipeline_zip():
1504
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
1505
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1506
  last_zip = _find_last_pipeline_zip()
1507
  if not last_zip:
@@ -1516,7 +1518,7 @@ def debug_compile_last_pipeline_zip():
1516
  logs.append(f"❌ Auto-stage failed: {e}")
1517
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1518
  else:
1519
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
1520
 
1521
  # Prepare workspace
1522
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -1533,7 +1535,7 @@ def debug_compile_last_pipeline_zip():
1533
  except Exception as e:
1534
  logs.append(f"❌ unzip failed: {e}")
1535
  _write_logs(LOG_PATH, logs)
1536
- return "<div style='color:#b00'>Unzip failed.</div>"
1537
 
1538
  # Locate tex
1539
  tex_path = None
@@ -1549,7 +1551,7 @@ def debug_compile_last_pipeline_zip():
1549
  if tex_path is None:
1550
  logs.append("❌ No .tex file found in last pipeline zip")
1551
  _write_logs(LOG_PATH, logs)
1552
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
1553
 
1554
  # Ensure local fonts and theme precedence (same as other debug path)
1555
  try:
@@ -1585,7 +1587,8 @@ def debug_compile_last_pipeline_zip():
1585
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1586
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1587
  + "\n".join(logs)
1588
- + "</pre>"
 
1589
  )
1590
  try:
1591
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -1595,17 +1598,17 @@ def debug_compile_last_pipeline_zip():
1595
  + _pdf_to_iframe_html(pdf_path, height="700px")
1596
  )
1597
  _write_logs(LOG_PATH, logs)
1598
- return html
1599
  except Exception as e:
1600
  logs.append(f"⚠️ preview failed: {e}")
1601
  _write_logs(LOG_PATH, logs)
1602
- return f"<div>Compiled but preview failed: {e}</div>"
1603
 
1604
  def debug_compile_uploaded_zip(zip_file):
1605
- """Compile an uploaded poster zip (user-provided) and preview PDF."""
1606
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1607
  if not zip_file:
1608
- return "<div style='color:#b00'>Please upload a .zip file first.</div>"
1609
  # Prepare workspace
1610
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1611
  work_zip_dir = WORK_DIR / "zip_upload"
@@ -1617,7 +1620,7 @@ def debug_compile_uploaded_zip(zip_file):
1617
  except Exception as e:
1618
  logs.append(f"❌ save upload failed: {e}")
1619
  _write_logs(LOG_PATH, logs)
1620
- return "<div style='color:#b00'>Save upload failed.</div>"
1621
  # Extract
1622
  try:
1623
  import zipfile as _zf
@@ -1626,7 +1629,7 @@ def debug_compile_uploaded_zip(zip_file):
1626
  except Exception as e:
1627
  logs.append(f"❌ unzip failed: {e}")
1628
  _write_logs(LOG_PATH, logs)
1629
- return "<div style='color:#b00'>Unzip failed.</div>"
1630
  # Find tex
1631
  tex_path = None
1632
  for name in ("poster_output.tex", "poster.tex"):
@@ -1670,7 +1673,8 @@ def debug_compile_uploaded_zip(zip_file):
1670
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1671
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1672
  + "\n".join(logs)
1673
- + "</pre>"
 
1674
  )
1675
  try:
1676
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1381
  if not zip_path.exists():
1382
  return (
1383
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
1384
+ + f"<div>Expected at: {zip_path}</div>",
1385
+ None,
1386
  )
1387
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
1388
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
 
1418
  except Exception as e:
1419
  logs.append(f"❌ unzip failed: {e}")
1420
  _write_logs(LOG_PATH, logs)
1421
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1422
 
1423
  # Locate poster_output.tex (fallback to poster.tex)
1424
  tex_path = None
 
1435
  if tex_path is None:
1436
  logs.append("❌ No .tex file found in output.zip")
1437
  _write_logs(LOG_PATH, logs)
1438
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
1439
 
1440
  # If left_logo missing, disable \logoleft
1441
  try:
 
1466
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1467
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1468
  + "\n".join(logs)
1469
+ + "</pre>",
1470
+ None,
1471
  )
1472
 
1473
  try:
 
1478
  + _pdf_to_iframe_html(pdf_path, height="700px")
1479
  )
1480
  _write_logs(LOG_PATH, logs)
1481
+ return html, str(pdf_path)
1482
  except Exception as e:
1483
  logs.append(f"⚠️ preview failed: {e}")
1484
  _write_logs(LOG_PATH, logs)
1485
+ return f"<div>Compiled but preview failed: {e}</div>", None
1486
 
1487
  def _find_last_pipeline_zip():
1488
  try:
 
1503
  return None
1504
 
1505
  def debug_compile_last_pipeline_zip():
1506
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
1507
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1508
  last_zip = _find_last_pipeline_zip()
1509
  if not last_zip:
 
1518
  logs.append(f"❌ Auto-stage failed: {e}")
1519
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1520
  else:
1521
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
1522
 
1523
  # Prepare workspace
1524
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
1535
  except Exception as e:
1536
  logs.append(f"❌ unzip failed: {e}")
1537
  _write_logs(LOG_PATH, logs)
1538
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1539
 
1540
  # Locate tex
1541
  tex_path = None
 
1551
  if tex_path is None:
1552
  logs.append("❌ No .tex file found in last pipeline zip")
1553
  _write_logs(LOG_PATH, logs)
1554
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
1555
 
1556
  # Ensure local fonts and theme precedence (same as other debug path)
1557
  try:
 
1587
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1588
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1589
  + "\n".join(logs)
1590
+ + "</pre>",
1591
+ None,
1592
  )
1593
  try:
1594
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1598
  + _pdf_to_iframe_html(pdf_path, height="700px")
1599
  )
1600
  _write_logs(LOG_PATH, logs)
1601
+ return html, str(pdf_path)
1602
  except Exception as e:
1603
  logs.append(f"⚠️ preview failed: {e}")
1604
  _write_logs(LOG_PATH, logs)
1605
+ return f"<div>Compiled but preview failed: {e}</div>", None
1606
 
1607
  def debug_compile_uploaded_zip(zip_file):
1608
+ """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
1609
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1610
  if not zip_file:
1611
+ return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
1612
  # Prepare workspace
1613
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1614
  work_zip_dir = WORK_DIR / "zip_upload"
 
1620
  except Exception as e:
1621
  logs.append(f"❌ save upload failed: {e}")
1622
  _write_logs(LOG_PATH, logs)
1623
+ return "<div style='color:#b00'>Save upload failed.</div>", None
1624
  # Extract
1625
  try:
1626
  import zipfile as _zf
 
1629
  except Exception as e:
1630
  logs.append(f"❌ unzip failed: {e}")
1631
  _write_logs(LOG_PATH, logs)
1632
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1633
  # Find tex
1634
  tex_path = None
1635
  for name in ("poster_output.tex", "poster.tex"):
 
1673
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1674
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1675
  + "\n".join(logs)
1676
+ + "</pre>",
1677
+ None,
1678
  )
1679
  try:
1680
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")