Push Bot commited on
Commit
a91574d
Β·
1 Parent(s): ceadda8

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 +34 -24
app.py CHANGED
@@ -649,13 +649,14 @@ def debug_compile():
649
  return "<div style='color:#555'>Minimal debug disabled. Use 'Test repo output.zip' or 'Test last pipeline zip'.</div>"
650
 
651
  def debug_compile_output_zip():
652
- """Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
653
  # Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
654
  zip_path = ROOT / "output.zip"
655
  if not zip_path.exists():
656
  return (
657
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
658
- + f"<div>Expected at: {zip_path}</div>"
 
659
  )
660
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
661
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
@@ -691,7 +692,7 @@ def debug_compile_output_zip():
691
  except Exception as e:
692
  logs.append(f"❌ unzip failed: {e}")
693
  _write_logs(LOG_PATH, logs)
694
- return "<div style='color:#b00'>Unzip failed.</div>"
695
 
696
  # Locate poster_output.tex (fallback to poster.tex)
697
  tex_path = None
@@ -708,7 +709,7 @@ def debug_compile_output_zip():
708
  if tex_path is None:
709
  logs.append("❌ No .tex file found in output.zip")
710
  _write_logs(LOG_PATH, logs)
711
- return "<div style='color:#b00'>No .tex found in output.zip</div>"
712
 
713
  # If left_logo missing, disable \logoleft
714
  try:
@@ -781,18 +782,19 @@ def debug_compile_output_zip():
781
  "<div style='color:#b00'><b>Compile failed.</b></div>"
782
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
783
  + "\n".join(logs)
784
- + "</pre>"
 
785
  )
786
 
787
  try:
788
  # Use served file path to avoid data: URI issues
789
  html = _pdf_preview_html(pdf_path, height="700px")
790
  _write_logs(LOG_PATH, logs)
791
- return html
792
  except Exception as e:
793
  logs.append(f"⚠️ preview failed: {e}")
794
  _write_logs(LOG_PATH, logs)
795
- return f"<div>Compiled but preview failed: {e}</div>"
796
 
797
  def _find_last_pipeline_zip():
798
  try:
@@ -813,7 +815,7 @@ def _find_last_pipeline_zip():
813
  return None
814
 
815
  def debug_compile_last_pipeline_zip():
816
- """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
817
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
818
  last_zip = _find_last_pipeline_zip()
819
  if not last_zip:
@@ -828,7 +830,7 @@ def debug_compile_last_pipeline_zip():
828
  logs.append(f"❌ Auto-stage failed: {e}")
829
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
830
  else:
831
- return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
832
 
833
  # Prepare workspace
834
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
@@ -845,7 +847,7 @@ def debug_compile_last_pipeline_zip():
845
  except Exception as e:
846
  logs.append(f"❌ unzip failed: {e}")
847
  _write_logs(LOG_PATH, logs)
848
- return "<div style='color:#b00'>Unzip failed.</div>"
849
 
850
  # Locate tex
851
  tex_path = None
@@ -861,7 +863,7 @@ def debug_compile_last_pipeline_zip():
861
  if tex_path is None:
862
  logs.append("❌ No .tex file found in last pipeline zip")
863
  _write_logs(LOG_PATH, logs)
864
- return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
865
 
866
  # Ensure local fonts and theme precedence (same as other debug path)
867
  try:
@@ -897,22 +899,23 @@ def debug_compile_last_pipeline_zip():
897
  "<div style='color:#b00'><b>Compile failed.</b></div>"
898
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
899
  + "\n".join(logs)
900
- + "</pre>"
 
901
  )
902
  try:
903
  html = _pdf_preview_html(pdf_path, height="700px")
904
  _write_logs(LOG_PATH, logs)
905
- return html
906
  except Exception as e:
907
  logs.append(f"⚠️ preview failed: {e}")
908
  _write_logs(LOG_PATH, logs)
909
- return f"<div>Compiled but preview failed: {e}</div>"
910
 
911
  def debug_compile_uploaded_zip(zip_file):
912
- """Compile an uploaded poster zip (user-provided) and preview PDF."""
913
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
914
  if not zip_file:
915
- return "<div style='color:#b00'>Please upload a .zip file first.</div>"
916
  # Prepare workspace
917
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
918
  work_zip_dir = WORK_DIR / "zip_upload"
@@ -924,7 +927,7 @@ def debug_compile_uploaded_zip(zip_file):
924
  except Exception as e:
925
  logs.append(f"❌ save upload failed: {e}")
926
  _write_logs(LOG_PATH, logs)
927
- return "<div style='color:#b00'>Save upload failed.</div>"
928
  # Extract
929
  try:
930
  import zipfile as _zf
@@ -933,7 +936,7 @@ def debug_compile_uploaded_zip(zip_file):
933
  except Exception as e:
934
  logs.append(f"❌ unzip failed: {e}")
935
  _write_logs(LOG_PATH, logs)
936
- return "<div style='color:#b00'>Unzip failed.</div>"
937
  # Find tex
938
  tex_path = None
939
  for name in ("poster_output.tex", "poster.tex"):
@@ -948,7 +951,7 @@ def debug_compile_uploaded_zip(zip_file):
948
  if tex_path is None:
949
  logs.append("❌ No .tex file found in uploaded zip")
950
  _write_logs(LOG_PATH, logs)
951
- return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
952
  # Disable logoleft if missing; also ensure local fonts and override theme to use them
953
  try:
954
  logos_dir = tex_path.parent / "logos"
@@ -1000,16 +1003,17 @@ def debug_compile_uploaded_zip(zip_file):
1000
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1001
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1002
  + "\n".join(logs)
1003
- + "</pre>"
 
1004
  )
1005
  try:
1006
  html = _pdf_preview_html(pdf_path, height="700px")
1007
  _write_logs(LOG_PATH, logs)
1008
- return html
1009
  except Exception as e:
1010
  logs.append(f"⚠️ preview failed: {e}")
1011
  _write_logs(LOG_PATH, logs)
1012
- return f"<div>Compiled but preview failed: {e}</div>"
1013
 
1014
  # =====================
1015
  # Gradio pipeline function (ISOLATED)
@@ -1325,16 +1329,22 @@ The framework builds upon [CAMEL-ai](https://github.com/camel-ai/camel).
1325
  overleaf_out = gr.HTML(label="Open in Overleaf")
1326
  debug_zip_btn= gr.Button("🐞 Test repo output.zip", variant="secondary")
1327
  debug_zip_out= gr.HTML(label="🐞 Real Output Preview")
 
 
1328
  debug_last_btn= gr.Button("🐞 Test last pipeline zip", variant="secondary")
1329
  debug_last_out= gr.HTML(label="🐞 Last Pipeline Preview")
 
 
1330
  _run_evt = run_btn.click(
1331
  fn=run_pipeline,
1332
  inputs=[arxiv_in, pdf_in, key_in, inst_logo_in, conf_logo_in, theme_in],
1333
  outputs=[logs_out, pdf_out, pdf_file_out, zip_out, overleaf_out],
1334
  )
1335
  _run_evt.then(fn=preview_image_from_pdf, inputs=[pdf_file_out], outputs=[img_out])
1336
- debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out])
1337
- debug_last_btn.click(fn=debug_compile_last_pipeline_zip, inputs=[], outputs=[debug_last_out])
 
 
1338
 
1339
  if __name__ == "__main__":
1340
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
649
  return "<div style='color:#555'>Minimal debug disabled. Use 'Test repo output.zip' or 'Test last pipeline zip'.</div>"
650
 
651
  def debug_compile_output_zip():
652
+ """Compile the repo-root output.zip (a real LaTeX project) and return preview HTML + PDF path."""
653
  # Stage repo output.zip to runs/<id>/output.zip to follow pipeline layout, then delegate
654
  zip_path = ROOT / "output.zip"
655
  if not zip_path.exists():
656
  return (
657
  "<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
658
+ + f"<div>Expected at: {zip_path}</div>",
659
+ None,
660
  )
661
  logs = [f"🐞 Stage(repo zip) at {_now_str()}"]
662
  _, WORK_DIR, LOG_PATH, ZIP_PATH = _prepare_workspace(logs)
 
692
  except Exception as e:
693
  logs.append(f"❌ unzip failed: {e}")
694
  _write_logs(LOG_PATH, logs)
695
+ return "<div style='color:#b00'>Unzip failed.</div>", None
696
 
697
  # Locate poster_output.tex (fallback to poster.tex)
698
  tex_path = None
 
709
  if tex_path is None:
710
  logs.append("❌ No .tex file found in output.zip")
711
  _write_logs(LOG_PATH, logs)
712
+ return "<div style='color:#b00'>No .tex found in output.zip</div>", None
713
 
714
  # If left_logo missing, disable \logoleft
715
  try:
 
782
  "<div style='color:#b00'><b>Compile failed.</b></div>"
783
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
784
  + "\n".join(logs)
785
+ + "</pre>",
786
+ None,
787
  )
788
 
789
  try:
790
  # Use served file path to avoid data: URI issues
791
  html = _pdf_preview_html(pdf_path, height="700px")
792
  _write_logs(LOG_PATH, logs)
793
+ return html, str(pdf_path)
794
  except Exception as e:
795
  logs.append(f"⚠️ preview failed: {e}")
796
  _write_logs(LOG_PATH, logs)
797
+ return f"<div>Compiled but preview failed: {e}</div>", None
798
 
799
  def _find_last_pipeline_zip():
800
  try:
 
815
  return None
816
 
817
  def debug_compile_last_pipeline_zip():
818
+ """Find the most recent runs/*/output.zip from pipeline, compile, and return preview HTML + PDF path."""
819
  logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
820
  last_zip = _find_last_pipeline_zip()
821
  if not last_zip:
 
830
  logs.append(f"❌ Auto-stage failed: {e}")
831
  return "<div style='color:#b00'>No recent pipeline output.zip found and auto-stage failed.</div>"
832
  else:
833
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>", None
834
 
835
  # Prepare workspace
836
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
 
847
  except Exception as e:
848
  logs.append(f"❌ unzip failed: {e}")
849
  _write_logs(LOG_PATH, logs)
850
+ return "<div style='color:#b00'>Unzip failed.</div>", None
851
 
852
  # Locate tex
853
  tex_path = None
 
863
  if tex_path is None:
864
  logs.append("❌ No .tex file found in last pipeline zip")
865
  _write_logs(LOG_PATH, logs)
866
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>", None
867
 
868
  # Ensure local fonts and theme precedence (same as other debug path)
869
  try:
 
899
  "<div style='color:#b00'><b>Compile failed.</b></div>"
900
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
901
  + "\n".join(logs)
902
+ + "</pre>",
903
+ None,
904
  )
905
  try:
906
  html = _pdf_preview_html(pdf_path, height="700px")
907
  _write_logs(LOG_PATH, logs)
908
+ return html, str(pdf_path)
909
  except Exception as e:
910
  logs.append(f"⚠️ preview failed: {e}")
911
  _write_logs(LOG_PATH, logs)
912
+ return f"<div>Compiled but preview failed: {e}</div>", None
913
 
914
  def debug_compile_uploaded_zip(zip_file):
915
+ """Compile an uploaded poster zip (user-provided); return preview HTML + PDF path."""
916
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
917
  if not zip_file:
918
+ return "<div style='color:#b00'>Please upload a .zip file first.</div>", None
919
  # Prepare workspace
920
  run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
921
  work_zip_dir = WORK_DIR / "zip_upload"
 
927
  except Exception as e:
928
  logs.append(f"❌ save upload failed: {e}")
929
  _write_logs(LOG_PATH, logs)
930
+ return "<div style='color:#b00'>Save upload failed.</div>", None
931
  # Extract
932
  try:
933
  import zipfile as _zf
 
936
  except Exception as e:
937
  logs.append(f"❌ unzip failed: {e}")
938
  _write_logs(LOG_PATH, logs)
939
+ return "<div style='color:#b00'>Unzip failed.</div>", None
940
  # Find tex
941
  tex_path = None
942
  for name in ("poster_output.tex", "poster.tex"):
 
951
  if tex_path is None:
952
  logs.append("❌ No .tex file found in uploaded zip")
953
  _write_logs(LOG_PATH, logs)
954
+ return "<div style='color:#b00'>No .tex found in uploaded zip</div>", None
955
  # Disable logoleft if missing; also ensure local fonts and override theme to use them
956
  try:
957
  logos_dir = tex_path.parent / "logos"
 
1003
  "<div style='color:#b00'><b>Compile failed.</b></div>"
1004
  + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
1005
  + "\n".join(logs)
1006
+ + "</pre>",
1007
+ None,
1008
  )
1009
  try:
1010
  html = _pdf_preview_html(pdf_path, height="700px")
1011
  _write_logs(LOG_PATH, logs)
1012
+ return html, str(pdf_path)
1013
  except Exception as e:
1014
  logs.append(f"⚠️ preview failed: {e}")
1015
  _write_logs(LOG_PATH, logs)
1016
+ return f"<div>Compiled but preview failed: {e}</div>", None
1017
 
1018
  # =====================
1019
  # Gradio pipeline function (ISOLATED)
 
1329
  overleaf_out = gr.HTML(label="Open in Overleaf")
1330
  debug_zip_btn= gr.Button("🐞 Test repo output.zip", variant="secondary")
1331
  debug_zip_out= gr.HTML(label="🐞 Real Output Preview")
1332
+ debug_zip_img= gr.Image(label="🐞 Real Output Image", interactive=False)
1333
+ debug_zip_pdfpath = gr.Textbox(visible=False)
1334
  debug_last_btn= gr.Button("🐞 Test last pipeline zip", variant="secondary")
1335
  debug_last_out= gr.HTML(label="🐞 Last Pipeline Preview")
1336
+ debug_last_img= gr.Image(label="🐞 Last Output Image", interactive=False)
1337
+ debug_last_pdfpath = gr.Textbox(visible=False)
1338
  _run_evt = run_btn.click(
1339
  fn=run_pipeline,
1340
  inputs=[arxiv_in, pdf_in, key_in, inst_logo_in, conf_logo_in, theme_in],
1341
  outputs=[logs_out, pdf_out, pdf_file_out, zip_out, overleaf_out],
1342
  )
1343
  _run_evt.then(fn=preview_image_from_pdf, inputs=[pdf_file_out], outputs=[img_out])
1344
+ _dz = debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out, debug_zip_pdfpath])
1345
+ _dz.then(fn=preview_image_from_pdf, inputs=[debug_zip_pdfpath], outputs=[debug_zip_img])
1346
+ _dl = debug_last_btn.click(fn=debug_compile_last_pipeline_zip, inputs=[], outputs=[debug_last_out, debug_last_pdfpath])
1347
+ _dl.then(fn=preview_image_from_pdf, inputs=[debug_last_pdfpath], outputs=[debug_last_img])
1348
 
1349
  if __name__ == "__main__":
1350
  iface.launch(server_name="0.0.0.0", server_port=7860)