Siyuan Hu commited on
Commit
b95ddcd
Β·
1 Parent(s): 5e9efe4

feat(debug): add 'Test last pipeline zip' to compile most recent runs/*/output.zip with local fonts + template precedence; widen TEXINPUTS

Browse files
Files changed (1) hide show
  1. app.py +109 -0
app.py CHANGED
@@ -754,6 +754,114 @@ def debug_compile_output_zip():
754
  _write_logs(LOG_PATH, logs)
755
  return f"<div>Compiled but preview failed: {e}</div>"
756
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
757
  def debug_compile_uploaded_zip(zip_file):
758
  """Compile an uploaded poster zip (user-provided) and preview PDF."""
759
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
@@ -1172,6 +1280,7 @@ The framework builds upon [CAMEL-ai](https://github.com/camel-ai/camel).
1172
  debug_btn.click(fn=debug_compile, inputs=[], outputs=[debug_out])
1173
  debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out])
1174
  debug_zip_upload.change(fn=debug_compile_uploaded_zip, inputs=[debug_zip_upload], outputs=[debug_zip_upload_out])
 
1175
 
1176
  if __name__ == "__main__":
1177
  iface.launch(server_name="0.0.0.0", server_port=7860)
 
754
  _write_logs(LOG_PATH, logs)
755
  return f"<div>Compiled but preview failed: {e}</div>"
756
 
757
+ def _find_last_pipeline_zip():
758
+ try:
759
+ candidates = []
760
+ for d in RUNS_DIR.iterdir():
761
+ try:
762
+ if d.is_dir():
763
+ z = d / "output.zip"
764
+ if z.exists():
765
+ candidates.append((z.stat().st_mtime, z))
766
+ except Exception:
767
+ pass
768
+ if not candidates:
769
+ return None
770
+ candidates.sort(key=lambda x: x[0], reverse=True)
771
+ return candidates[0][1]
772
+ except Exception:
773
+ return None
774
+
775
+ def debug_compile_last_pipeline_zip():
776
+ """Find the most recent runs/*/output.zip from pipeline, compile, and preview the PDF."""
777
+ logs = [f"🐞 Debug(last-pipeline-zip) at {_now_str()}"]
778
+ last_zip = _find_last_pipeline_zip()
779
+ if not last_zip:
780
+ return "<div style='color:#b00'>No recent pipeline output.zip found under runs/.</div>"
781
+
782
+ # Prepare workspace
783
+ run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
784
+ work_zip_dir = WORK_DIR / "zip_last"
785
+ work_zip_dir.mkdir(parents=True, exist_ok=True)
786
+ logs.append(f"Workspace: runs/{WORK_DIR.name}")
787
+ logs.append(f"Using: {last_zip}")
788
+
789
+ # Extract zip
790
+ try:
791
+ import zipfile as _zf
792
+ with _zf.ZipFile(last_zip, 'r') as zf:
793
+ zf.extractall(work_zip_dir)
794
+ except Exception as e:
795
+ logs.append(f"❌ unzip failed: {e}")
796
+ _write_logs(LOG_PATH, logs)
797
+ return "<div style='color:#b00'>Unzip failed.</div>"
798
+
799
+ # Locate tex
800
+ tex_path = None
801
+ for name in ("poster_output.tex", "poster.tex"):
802
+ cand = list(work_zip_dir.rglob(name))
803
+ if cand:
804
+ tex_path = cand[0]
805
+ break
806
+ if tex_path is None:
807
+ cand = list(work_zip_dir.rglob("*.tex"))
808
+ if cand:
809
+ tex_path = cand[0]
810
+ if tex_path is None:
811
+ logs.append("❌ No .tex file found in last pipeline zip")
812
+ _write_logs(LOG_PATH, logs)
813
+ return "<div style='color:#b00'>No .tex found in last pipeline zip</div>"
814
+
815
+ # Ensure local fonts and theme precedence (same as other debug path)
816
+ try:
817
+ src_fonts = ROOT / "template" / "fonts"
818
+ dst_fonts = work_zip_dir / "fonts"
819
+ if src_fonts.exists():
820
+ for root_dir, dirs, files in os.walk(src_fonts):
821
+ rel = Path(root_dir).relative_to(src_fonts)
822
+ out_dir = dst_fonts / rel
823
+ out_dir.mkdir(parents=True, exist_ok=True)
824
+ for fn in files:
825
+ if fn.lower().endswith((".ttf", ".otf")):
826
+ shutil.copy2(Path(root_dir)/fn, out_dir/fn)
827
+ logs.append("πŸ“ Copied local fonts β†’ zip_last/fonts/")
828
+ # Copy repository theme .sty next to tex and at root
829
+ try:
830
+ tmpl_dir = ROOT / "template"
831
+ for sty in tmpl_dir.glob("*.sty"):
832
+ shutil.copy2(sty, work_zip_dir / sty.name)
833
+ shutil.copy2(sty, tex_path.parent / sty.name)
834
+ logs.append("πŸ“„ Copied template/*.sty β†’ zip_last/ and tex dir")
835
+ except Exception as e:
836
+ logs.append(f"⚠️ Copy sty failed: {e}")
837
+ except Exception as e:
838
+ logs.append(f"⚠️ Local font setup failed: {e}")
839
+
840
+ # Compile to PDF
841
+ pdf_path = _compile_tex_to_pdf(tex_path, logs)
842
+ if not pdf_path or not pdf_path.exists():
843
+ logs.append("❌ Failed to compile last pipeline zip PDF.")
844
+ _write_logs(LOG_PATH, logs)
845
+ return (
846
+ "<div style='color:#b00'><b>Compile failed.</b></div>"
847
+ + "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
848
+ + "\n".join(logs)
849
+ + "</pre>"
850
+ )
851
+ try:
852
+ b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
853
+ open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
854
+ html = (
855
+ f"<div style='margin-bottom:8px'>{open_tab}</div>"
856
+ + _pdf_to_iframe_html(pdf_path, height="700px")
857
+ )
858
+ _write_logs(LOG_PATH, logs)
859
+ return html
860
+ except Exception as e:
861
+ logs.append(f"⚠️ preview failed: {e}")
862
+ _write_logs(LOG_PATH, logs)
863
+ return f"<div>Compiled but preview failed: {e}</div>"
864
+
865
  def debug_compile_uploaded_zip(zip_file):
866
  """Compile an uploaded poster zip (user-provided) and preview PDF."""
867
  logs = [f"🐞 Debug(upload) at {_now_str()}"]
 
1280
  debug_btn.click(fn=debug_compile, inputs=[], outputs=[debug_out])
1281
  debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out])
1282
  debug_zip_upload.change(fn=debug_compile_uploaded_zip, inputs=[debug_zip_upload], outputs=[debug_zip_upload_out])
1283
+ debug_last_btn.click(fn=debug_compile_last_pipeline_zip, inputs=[], outputs=[debug_last_out])
1284
 
1285
  if __name__ == "__main__":
1286
  iface.launch(server_name="0.0.0.0", server_port=7860)