Push Bot commited on
Commit
cbb1505
Β·
1 Parent(s): 4509859

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 +8 -7
app.py CHANGED
@@ -998,7 +998,7 @@ def _find_last_pipeline_zip():
998
  return None
999
 
1000
  def debug_compile_last_pipeline_zip():
1001
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
1002
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1003
  last_zip = _find_last_pipeline_zip()
1004
  if not last_zip:
@@ -1013,7 +1013,7 @@ def debug_compile_last_pipeline_zip():
1013
  logs.append(f"❌ Auto-stage failed: {e}")
1014
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1015
  else:
1016
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
1017
 
1018
  # Prepare workspace
1019
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -1030,7 +1030,7 @@ def debug_compile_last_pipeline_zip():
1030
  except Exception as e:
1031
  logs.append(f"❌ unzip failed: {e}")
1032
  _write_logs(LOG_PATH, logs)
1033
- return "<div style='color:#b00'>Unzip failed.</div>"
1034
 
1035
  # Locate tex
1036
  tex_path = None
@@ -1046,7 +1046,7 @@ def debug_compile_last_pipeline_zip():
1046
  if tex_path is None:
1047
  logs.append("❌ No .tex file found in last pipeline zip")
1048
  _write_logs(LOG_PATH, logs)
1049
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
1050
 
1051
  # Ensure local fonts and theme precedence (same as other debug path)
1052
  try:
@@ -1082,7 +1082,8 @@ def debug_compile_last_pipeline_zip():
1082
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1083
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1084
  + "\n".join(logs)
1085
- + "</pre>"
 
1086
  )
1087
  try:
1088
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -1092,11 +1093,11 @@ def debug_compile_last_pipeline_zip():
1092
  + _pdf_to_iframe_html(pdf_path, height="700px")
1093
  )
1094
  _write_logs(LOG_PATH, logs)
1095
- return html
1096
  except Exception as e:
1097
  logs.append(f"⚠️ preview failed: {e}")
1098
  _write_logs(LOG_PATH, logs)
1099
- return f"<div>Compiled but preview failed: {e}</div>"
1100
 
1101
  def debug_compile_uploaded_zip(zip_file):
1102
  """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
 
998
  return None
999
 
1000
  def debug_compile_last_pipeline_zip():
1001
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
1002
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1003
  last_zip = _find_last_pipeline_zip()
1004
  if not last_zip:
 
1013
  logs.append(f"❌ Auto-stage failed: {e}")
1014
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1015
  else:
1016
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
1017
 
1018
  # Prepare workspace
1019
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
1030
  except Exception as e:
1031
  logs.append(f"❌ unzip failed: {e}")
1032
  _write_logs(LOG_PATH, logs)
1033
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1034
 
1035
  # Locate tex
1036
  tex_path = None
 
1046
  if tex_path is None:
1047
  logs.append("❌ No .tex file found in last pipeline zip")
1048
  _write_logs(LOG_PATH, logs)
1049
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
1050
 
1051
  # Ensure local fonts and theme precedence (same as other debug path)
1052
  try:
 
1082
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1083
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1084
  + "\n".join(logs)
1085
+ + "</pre>",
1086
+ None,
1087
  )
1088
  try:
1089
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1093
  + _pdf_to_iframe_html(pdf_path, height="700px")
1094
  )
1095
  _write_logs(LOG_PATH, logs)
1096
+ return html, str(pdf_path)
1097
  except Exception as e:
1098
  logs.append(f"⚠️ preview failed: {e}")
1099
  _write_logs(LOG_PATH, logs)
1100
+ return f"<div>Compiled but preview failed: {e}</div>", None
1101
 
1102
  def debug_compile_uploaded_zip(zip_file):
1103
  """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""