Push Bot commited on
Commit
a933d3d
Β·
1 Parent(s): 56e3376

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 +14 -11
app.py CHANGED
@@ -2793,7 +2793,8 @@ def debug_compile_output_zip():
2793
  if not zip_path.exists():
2794
  return (
2795
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
2796
- + f"<div>Expected at: {zip_path}</div>"
 
2797
  )
2798
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
2799
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
@@ -2829,7 +2830,7 @@ def debug_compile_output_zip():
2829
  except Exception as e:
2830
  logs.append(f"❌ unzip failed: {e}")
2831
  _write_logs(LOG_PATH, logs)
2832
- return "<div style='color:#b00'>Unzip failed.</div>"
2833
 
2834
  # Locate poster_output.tex (fallback to poster.tex)
2835
  tex_path = None
@@ -2846,7 +2847,7 @@ def debug_compile_output_zip():
2846
  if tex_path is None:
2847
  logs.append("❌ No .tex file found in output.zip")
2848
  _write_logs(LOG_PATH, logs)
2849
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
2850
 
2851
  # If left_logo missing, disable \logoleft
2852
  try:
@@ -2877,7 +2878,8 @@ def debug_compile_output_zip():
2877
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2878
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2879
  + "\n".join(logs)
2880
- + "</pre>"
 
2881
  )
2882
 
2883
  try:
@@ -2888,11 +2890,11 @@ def debug_compile_output_zip():
2888
  + _pdf_to_iframe_html(pdf_path, height="700px")
2889
  )
2890
  _write_logs(LOG_PATH, logs)
2891
- return html
2892
  except Exception as e:
2893
  logs.append(f"⚠️ preview failed: {e}")
2894
  _write_logs(LOG_PATH, logs)
2895
- return f"<div>Compiled but preview failed: {e}</div>"
2896
 
2897
  def _find_last_pipeline_zip():
2898
  try:
@@ -2913,7 +2915,7 @@ def _find_last_pipeline_zip():
2913
  return None
2914
 
2915
  def debug_compile_last_pipeline_zip():
2916
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
2917
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
2918
  last_zip = _find_last_pipeline_zip()
2919
  if not last_zip:
@@ -2928,7 +2930,7 @@ def debug_compile_last_pipeline_zip():
2928
  logs.append(f"❌ Auto-stage failed: {e}")
2929
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
2930
  else:
2931
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
2932
 
2933
  # Prepare workspace
2934
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -2945,7 +2947,7 @@ def debug_compile_last_pipeline_zip():
2945
  except Exception as e:
2946
  logs.append(f"❌ unzip failed: {e}")
2947
  _write_logs(LOG_PATH, logs)
2948
- return "<div style='color:#b00'>Unzip failed.</div>"
2949
 
2950
  # Locate tex
2951
  tex_path = None
@@ -2961,7 +2963,7 @@ def debug_compile_last_pipeline_zip():
2961
  if tex_path is None:
2962
  logs.append("❌ No .tex file found in last pipeline zip")
2963
  _write_logs(LOG_PATH, logs)
2964
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
2965
 
2966
  # Ensure local fonts and theme precedence (same as other debug path)
2967
  try:
@@ -2997,7 +2999,8 @@ def debug_compile_last_pipeline_zip():
2997
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2998
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2999
  + "\n".join(logs)
3000
- + "</pre>"
 
3001
  )
3002
  try:
3003
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
2793
  if not zip_path.exists():
2794
  return (
2795
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
2796
+ + f"<div>Expected at: {zip_path}</div>",
2797
+ None,
2798
  )
2799
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
2800
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
 
2830
  except Exception as e:
2831
  logs.append(f"❌ unzip failed: {e}")
2832
  _write_logs(LOG_PATH, logs)
2833
+ return "<div style='color:#b00'>Unzip failed.</div>", None
2834
 
2835
  # Locate poster_output.tex (fallback to poster.tex)
2836
  tex_path = None
 
2847
  if tex_path is None:
2848
  logs.append("❌ No .tex file found in output.zip")
2849
  _write_logs(LOG_PATH, logs)
2850
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
2851
 
2852
  # If left_logo missing, disable \logoleft
2853
  try:
 
2878
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2879
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2880
  + "\n".join(logs)
2881
+ + "</pre>",
2882
+ None,
2883
  )
2884
 
2885
  try:
 
2890
  + _pdf_to_iframe_html(pdf_path, height="700px")
2891
  )
2892
  _write_logs(LOG_PATH, logs)
2893
+ return html, str(pdf_path)
2894
  except Exception as e:
2895
  logs.append(f"⚠️ preview failed: {e}")
2896
  _write_logs(LOG_PATH, logs)
2897
+ return f"<div>Compiled but preview failed: {e}</div>", None
2898
 
2899
  def _find_last_pipeline_zip():
2900
  try:
 
2915
  return None
2916
 
2917
  def debug_compile_last_pipeline_zip():
2918
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
2919
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
2920
  last_zip = _find_last_pipeline_zip()
2921
  if not last_zip:
 
2930
  logs.append(f"❌ Auto-stage failed: {e}")
2931
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
2932
  else:
2933
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
2934
 
2935
  # Prepare workspace
2936
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
2947
  except Exception as e:
2948
  logs.append(f"❌ unzip failed: {e}")
2949
  _write_logs(LOG_PATH, logs)
2950
+ return "<div style='color:#b00'>Unzip failed.</div>", None
2951
 
2952
  # Locate tex
2953
  tex_path = None
 
2963
  if tex_path is None:
2964
  logs.append("❌ No .tex file found in last pipeline zip")
2965
  _write_logs(LOG_PATH, logs)
2966
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
2967
 
2968
  # Ensure local fonts and theme precedence (same as other debug path)
2969
  try:
 
2999
  "<div style='color:#b00'><b>Compile failed.</b></div>"
3000
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
3001
  + "\n".join(logs)
3002
+ + "</pre>",
3003
+ None,
3004
  )
3005
  try:
3006
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")