Push Bot commited on
Commit
294e2ce
Β·
1 Parent(s): 54b9a68

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
@@ -2855,7 +2855,8 @@ def debug_compile_output_zip():
2855
  if not zip_path.exists():
2856
  return (
2857
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
2858
- + f"<div>Expected at: {zip_path}</div>"
 
2859
  )
2860
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
2861
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
@@ -2891,7 +2892,7 @@ def debug_compile_output_zip():
2891
  except Exception as e:
2892
  logs.append(f"❌ unzip failed: {e}")
2893
  _write_logs(LOG_PATH, logs)
2894
- return "<div style='color:#b00'>Unzip failed.</div>"
2895
 
2896
  # Locate poster_output.tex (fallback to poster.tex)
2897
  tex_path = None
@@ -2908,7 +2909,7 @@ def debug_compile_output_zip():
2908
  if tex_path is None:
2909
  logs.append("❌ No .tex file found in output.zip")
2910
  _write_logs(LOG_PATH, logs)
2911
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
2912
 
2913
  # If left_logo missing, disable \logoleft
2914
  try:
@@ -2939,7 +2940,8 @@ def debug_compile_output_zip():
2939
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2940
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2941
  + "\n".join(logs)
2942
- + "</pre>"
 
2943
  )
2944
 
2945
  try:
@@ -2950,11 +2952,11 @@ def debug_compile_output_zip():
2950
  + _pdf_to_iframe_html(pdf_path, height="700px")
2951
  )
2952
  _write_logs(LOG_PATH, logs)
2953
- return html
2954
  except Exception as e:
2955
  logs.append(f"⚠️ preview failed: {e}")
2956
  _write_logs(LOG_PATH, logs)
2957
- return f"<div>Compiled but preview failed: {e}</div>"
2958
 
2959
  def _find_last_pipeline_zip():
2960
  try:
@@ -2975,7 +2977,7 @@ def _find_last_pipeline_zip():
2975
  return None
2976
 
2977
  def debug_compile_last_pipeline_zip():
2978
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
2979
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
2980
  last_zip = _find_last_pipeline_zip()
2981
  if not last_zip:
@@ -2990,7 +2992,7 @@ def debug_compile_last_pipeline_zip():
2990
  logs.append(f"❌ Auto-stage failed: {e}")
2991
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
2992
  else:
2993
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
2994
 
2995
  # Prepare workspace
2996
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -3007,7 +3009,7 @@ def debug_compile_last_pipeline_zip():
3007
  except Exception as e:
3008
  logs.append(f"❌ unzip failed: {e}")
3009
  _write_logs(LOG_PATH, logs)
3010
- return "<div style='color:#b00'>Unzip failed.</div>"
3011
 
3012
  # Locate tex
3013
  tex_path = None
@@ -3023,7 +3025,7 @@ def debug_compile_last_pipeline_zip():
3023
  if tex_path is None:
3024
  logs.append("❌ No .tex file found in last pipeline zip")
3025
  _write_logs(LOG_PATH, logs)
3026
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
3027
 
3028
  # Ensure local fonts and theme precedence (same as other debug path)
3029
  try:
@@ -3059,7 +3061,8 @@ def debug_compile_last_pipeline_zip():
3059
  "<div style='color:#b00'><b>Compile failed.</b></div>"
3060
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
3061
  + "\n".join(logs)
3062
- + "</pre>"
 
3063
  )
3064
  try:
3065
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -3069,17 +3072,17 @@ def debug_compile_last_pipeline_zip():
3069
  + _pdf_to_iframe_html(pdf_path, height="700px")
3070
  )
3071
  _write_logs(LOG_PATH, logs)
3072
- return html
3073
  except Exception as e:
3074
  logs.append(f"⚠️ preview failed: {e}")
3075
  _write_logs(LOG_PATH, logs)
3076
- return f"<div>Compiled but preview failed: {e}</div>"
3077
 
3078
  def debug_compile_uploaded_zip(zip_file):
3079
- """Compile an uploaded poster zip (user-provided) and preview PDF."""
3080
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
3081
  if not zip_file:
3082
- return "<div style='color:#b00'>Please upload a .zip file first.</div>"
3083
  # Prepare workspace
3084
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
3085
  work_zip_dir = WORK_DIR / "zip_upload"
@@ -3091,7 +3094,7 @@ def debug_compile_uploaded_zip(zip_file):
3091
  except Exception as e:
3092
  logs.append(f"❌ save upload failed: {e}")
3093
  _write_logs(LOG_PATH, logs)
3094
- return "<div style='color:#b00'>Save upload failed.</div>"
3095
  # Extract
3096
  try:
3097
  import zipfile as _zf
@@ -3100,7 +3103,7 @@ def debug_compile_uploaded_zip(zip_file):
3100
  except Exception as e:
3101
  logs.append(f"❌ unzip failed: {e}")
3102
  _write_logs(LOG_PATH, logs)
3103
- return "<div style='color:#b00'>Unzip failed.</div>"
3104
  # Find tex
3105
  tex_path = None
3106
  for name in ("poster_output.tex", "poster.tex"):
@@ -3144,7 +3147,8 @@ def debug_compile_uploaded_zip(zip_file):
3144
  "<div style='color:#b00'><b>Compile failed.</b></div>"
3145
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
3146
  + "\n".join(logs)
3147
- + "</pre>"
 
3148
  )
3149
  try:
3150
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -3154,11 +3158,11 @@ def debug_compile_uploaded_zip(zip_file):
3154
  + _pdf_to_iframe_html(pdf_path, height="700px")
3155
  )
3156
  _write_logs(LOG_PATH, logs)
3157
- return html
3158
  except Exception as e:
3159
  logs.append(f"⚠️ preview failed: {e}")
3160
  _write_logs(LOG_PATH, logs)
3161
- return f"<div>Compiled but preview failed: {e}</div>"
3162
 
3163
  # =====================
3164
  # Gradio pipeline function (ISOLATED)
 
2855
  if not zip_path.exists():
2856
  return (
2857
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
2858
+ + f"<div>Expected at: {zip_path}</div>",
2859
+ None,
2860
  )
2861
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
2862
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
 
2892
  except Exception as e:
2893
  logs.append(f"❌ unzip failed: {e}")
2894
  _write_logs(LOG_PATH, logs)
2895
+ return "<div style='color:#b00'>Unzip failed.</div>", None
2896
 
2897
  # Locate poster_output.tex (fallback to poster.tex)
2898
  tex_path = None
 
2909
  if tex_path is None:
2910
  logs.append("❌ No .tex file found in output.zip")
2911
  _write_logs(LOG_PATH, logs)
2912
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
2913
 
2914
  # If left_logo missing, disable \logoleft
2915
  try:
 
2940
  "<div style='color:#b00'><b>Compile failed.</b></div>"
2941
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
2942
  + "\n".join(logs)
2943
+ + "</pre>",
2944
+ None,
2945
  )
2946
 
2947
  try:
 
2952
  + _pdf_to_iframe_html(pdf_path, height="700px")
2953
  )
2954
  _write_logs(LOG_PATH, logs)
2955
+ return html, str(pdf_path)
2956
  except Exception as e:
2957
  logs.append(f"⚠️ preview failed: {e}")
2958
  _write_logs(LOG_PATH, logs)
2959
+ return f"<div>Compiled but preview failed: {e}</div>", None
2960
 
2961
  def _find_last_pipeline_zip():
2962
  try:
 
2977
  return None
2978
 
2979
  def debug_compile_last_pipeline_zip():
2980
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
2981
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
2982
  last_zip = _find_last_pipeline_zip()
2983
  if not last_zip:
 
2992
  logs.append(f"❌ Auto-stage failed: {e}")
2993
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
2994
  else:
2995
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
2996
 
2997
  # Prepare workspace
2998
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
3009
  except Exception as e:
3010
  logs.append(f"❌ unzip failed: {e}")
3011
  _write_logs(LOG_PATH, logs)
3012
+ return "<div style='color:#b00'>Unzip failed.</div>", None
3013
 
3014
  # Locate tex
3015
  tex_path = None
 
3025
  if tex_path is None:
3026
  logs.append("❌ No .tex file found in last pipeline zip")
3027
  _write_logs(LOG_PATH, logs)
3028
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
3029
 
3030
  # Ensure local fonts and theme precedence (same as other debug path)
3031
  try:
 
3061
  "<div style='color:#b00'><b>Compile failed.</b></div>"
3062
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
3063
  + "\n".join(logs)
3064
+ + "</pre>",
3065
+ None,
3066
  )
3067
  try:
3068
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
3072
  + _pdf_to_iframe_html(pdf_path, height="700px")
3073
  )
3074
  _write_logs(LOG_PATH, logs)
3075
+ return html, str(pdf_path)
3076
  except Exception as e:
3077
  logs.append(f"⚠️ preview failed: {e}")
3078
  _write_logs(LOG_PATH, logs)
3079
+ return f"<div>Compiled but preview failed: {e}</div>", None
3080
 
3081
  def debug_compile_uploaded_zip(zip_file):
3082
+ """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
3083
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
3084
  if not zip_file:
3085
+ return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
3086
  # Prepare workspace
3087
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
3088
  work_zip_dir = WORK_DIR / "zip_upload"
 
3094
  except Exception as e:
3095
  logs.append(f"❌ save upload failed: {e}")
3096
  _write_logs(LOG_PATH, logs)
3097
+ return "<div style='color:#b00'>Save upload failed.</div>", None
3098
  # Extract
3099
  try:
3100
  import zipfile as _zf
 
3103
  except Exception as e:
3104
  logs.append(f"❌ unzip failed: {e}")
3105
  _write_logs(LOG_PATH, logs)
3106
+ return "<div style='color:#b00'>Unzip failed.</div>", None
3107
  # Find tex
3108
  tex_path = None
3109
  for name in ("poster_output.tex", "poster.tex"):
 
3147
  "<div style='color:#b00'><b>Compile failed.</b></div>"
3148
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
3149
  + "\n".join(logs)
3150
+ + "</pre>",
3151
+ None,
3152
  )
3153
  try:
3154
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
3158
  + _pdf_to_iframe_html(pdf_path, height="700px")
3159
  )
3160
  _write_logs(LOG_PATH, logs)
3161
+ return html, str(pdf_path)
3162
  except Exception as e:
3163
  logs.append(f"⚠️ preview failed: {e}")
3164
  _write_logs(LOG_PATH, logs)
3165
+ return f"<div>Compiled but preview failed: {e}</div>", None
3166
 
3167
  # =====================
3168
  # Gradio pipeline function (ISOLATED)