Push Bot commited on
Commit
8252043
Β·
1 Parent(s): 9b43571

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 +21 -18
app.py CHANGED
@@ -1736,7 +1736,7 @@ def debug_compile_output_zip():
1736
  if tex_path is None:
1737
  logs.append("❌ No .tex file found in output.zip")
1738
  _write_logs(LOG_PATH, logs)
1739
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
1740
 
1741
  # If left_logo missing, disable \logoleft
1742
  try:
@@ -1767,7 +1767,8 @@ def debug_compile_output_zip():
1767
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1768
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1769
  + "\n".join(logs)
1770
- + "</pre>"
 
1771
  )
1772
 
1773
  try:
@@ -1778,11 +1779,11 @@ def debug_compile_output_zip():
1778
  + _pdf_to_iframe_html(pdf_path, height="700px")
1779
  )
1780
  _write_logs(LOG_PATH, logs)
1781
- return html
1782
  except Exception as e:
1783
  logs.append(f"⚠️ preview failed: {e}")
1784
  _write_logs(LOG_PATH, logs)
1785
- return f"<div>Compiled but preview failed: {e}</div>"
1786
 
1787
  def _find_last_pipeline_zip():
1788
  try:
@@ -1803,7 +1804,7 @@ def _find_last_pipeline_zip():
1803
  return None
1804
 
1805
  def debug_compile_last_pipeline_zip():
1806
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
1807
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1808
  last_zip = _find_last_pipeline_zip()
1809
  if not last_zip:
@@ -1818,7 +1819,7 @@ def debug_compile_last_pipeline_zip():
1818
  logs.append(f"❌ Auto-stage failed: {e}")
1819
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1820
  else:
1821
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
1822
 
1823
  # Prepare workspace
1824
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -1835,7 +1836,7 @@ def debug_compile_last_pipeline_zip():
1835
  except Exception as e:
1836
  logs.append(f"❌ unzip failed: {e}")
1837
  _write_logs(LOG_PATH, logs)
1838
- return "<div style='color:#b00'>Unzip failed.</div>"
1839
 
1840
  # Locate tex
1841
  tex_path = None
@@ -1851,7 +1852,7 @@ def debug_compile_last_pipeline_zip():
1851
  if tex_path is None:
1852
  logs.append("❌ No .tex file found in last pipeline zip")
1853
  _write_logs(LOG_PATH, logs)
1854
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
1855
 
1856
  # Ensure local fonts and theme precedence (same as other debug path)
1857
  try:
@@ -1887,7 +1888,8 @@ def debug_compile_last_pipeline_zip():
1887
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1888
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1889
  + "\n".join(logs)
1890
- + "</pre>"
 
1891
  )
1892
  try:
1893
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -1897,17 +1899,17 @@ def debug_compile_last_pipeline_zip():
1897
  + _pdf_to_iframe_html(pdf_path, height="700px")
1898
  )
1899
  _write_logs(LOG_PATH, logs)
1900
- return html
1901
  except Exception as e:
1902
  logs.append(f"⚠️ preview failed: {e}")
1903
  _write_logs(LOG_PATH, logs)
1904
- return f"<div>Compiled but preview failed: {e}</div>"
1905
 
1906
  def debug_compile_uploaded_zip(zip_file):
1907
- """Compile an uploaded poster zip (user-provided) and preview PDF."""
1908
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1909
  if not zip_file:
1910
- return "<div style='color:#b00'>Please upload a .zip file first.</div>"
1911
  # Prepare workspace
1912
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1913
  work_zip_dir = WORK_DIR / "zip_upload"
@@ -1919,7 +1921,7 @@ def debug_compile_uploaded_zip(zip_file):
1919
  except Exception as e:
1920
  logs.append(f"❌ save upload failed: {e}")
1921
  _write_logs(LOG_PATH, logs)
1922
- return "<div style='color:#b00'>Save upload failed.</div>"
1923
  # Extract
1924
  try:
1925
  import zipfile as _zf
@@ -1928,7 +1930,7 @@ def debug_compile_uploaded_zip(zip_file):
1928
  except Exception as e:
1929
  logs.append(f"❌ unzip failed: {e}")
1930
  _write_logs(LOG_PATH, logs)
1931
- return "<div style='color:#b00'>Unzip failed.</div>"
1932
  # Find tex
1933
  tex_path = None
1934
  for name in ("poster_output.tex", "poster.tex"):
@@ -1972,7 +1974,8 @@ def debug_compile_uploaded_zip(zip_file):
1972
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1973
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1974
  + "\n".join(logs)
1975
- + "</pre>"
 
1976
  )
1977
  try:
1978
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
@@ -2157,11 +2160,11 @@ def debug_compile_uploaded_zip(zip_file):
2157
  + _pdf_to_iframe_html(pdf_path, height="700px")
2158
  )
2159
  _write_logs(LOG_PATH, logs)
2160
- return html
2161
  except Exception as e:
2162
  logs.append(f"⚠️ preview failed: {e}")
2163
  _write_logs(LOG_PATH, logs)
2164
- return f"<div>Compiled but preview failed: {e}</div>"
2165
 
2166
  # =====================
2167
  # Gradio pipeline function (ISOLATED)
 
1736
  if tex_path is None:
1737
  logs.append("❌ No .tex file found in output.zip")
1738
  _write_logs(LOG_PATH, logs)
1739
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
1740
 
1741
  # If left_logo missing, disable \logoleft
1742
  try:
 
1767
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1768
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1769
  + "\n".join(logs)
1770
+ + "</pre>",
1771
+ None,
1772
  )
1773
 
1774
  try:
 
1779
  + _pdf_to_iframe_html(pdf_path, height="700px")
1780
  )
1781
  _write_logs(LOG_PATH, logs)
1782
+ return html, str(pdf_path)
1783
  except Exception as e:
1784
  logs.append(f"⚠️ preview failed: {e}")
1785
  _write_logs(LOG_PATH, logs)
1786
+ return f"<div>Compiled but preview failed: {e}</div>", None
1787
 
1788
  def _find_last_pipeline_zip():
1789
  try:
 
1804
  return None
1805
 
1806
  def debug_compile_last_pipeline_zip():
1807
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
1808
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
1809
  last_zip = _find_last_pipeline_zip()
1810
  if not last_zip:
 
1819
  logs.append(f"❌ Auto-stage failed: {e}")
1820
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
1821
  else:
1822
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
1823
 
1824
  # Prepare workspace
1825
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
1836
  except Exception as e:
1837
  logs.append(f"❌ unzip failed: {e}")
1838
  _write_logs(LOG_PATH, logs)
1839
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1840
 
1841
  # Locate tex
1842
  tex_path = None
 
1852
  if tex_path is None:
1853
  logs.append("❌ No .tex file found in last pipeline zip")
1854
  _write_logs(LOG_PATH, logs)
1855
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
1856
 
1857
  # Ensure local fonts and theme precedence (same as other debug path)
1858
  try:
 
1888
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1889
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1890
  + "\n".join(logs)
1891
+ + "</pre>",
1892
+ None,
1893
  )
1894
  try:
1895
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
1899
  + _pdf_to_iframe_html(pdf_path, height="700px")
1900
  )
1901
  _write_logs(LOG_PATH, logs)
1902
+ return html, str(pdf_path)
1903
  except Exception as e:
1904
  logs.append(f"⚠️ preview failed: {e}")
1905
  _write_logs(LOG_PATH, logs)
1906
+ return f"<div>Compiled but preview failed: {e}</div>", None
1907
 
1908
  def debug_compile_uploaded_zip(zip_file):
1909
+ """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
1910
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
1911
  if not zip_file:
1912
+ return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
1913
  # Prepare workspace
1914
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
1915
  work_zip_dir = WORK_DIR / "zip_upload"
 
1921
  except Exception as e:
1922
  logs.append(f"❌ save upload failed: {e}")
1923
  _write_logs(LOG_PATH, logs)
1924
+ return "<div style='color:#b00'>Save upload failed.</div>", None
1925
  # Extract
1926
  try:
1927
  import zipfile as _zf
 
1930
  except Exception as e:
1931
  logs.append(f"❌ unzip failed: {e}")
1932
  _write_logs(LOG_PATH, logs)
1933
+ return "<div style='color:#b00'>Unzip failed.</div>", None
1934
  # Find tex
1935
  tex_path = None
1936
  for name in ("poster_output.tex", "poster.tex"):
 
1974
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1975
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1976
  + "\n".join(logs)
1977
+ + "</pre>",
1978
+ None,
1979
  )
1980
  try:
1981
  b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
 
2160
  + _pdf_to_iframe_html(pdf_path, height="700px")
2161
  )
2162
  _write_logs(LOG_PATH, logs)
2163
+ return html, str(pdf_path)
2164
  except Exception as e:
2165
  logs.append(f"⚠️ preview failed: {e}")
2166
  _write_logs(LOG_PATH, logs)
2167
+ return f"<div>Compiled but preview failed: {e}</div>", None
2168
 
2169
  # =====================
2170
  # Gradio pipeline function (ISOLATED)