Spaces:
Running
Running
Siyuan Hu
commited on
Commit
Β·
cc147c2
1
Parent(s):
3d35f21
feat(debug): add 'Test last pipeline zip' to compile most recent runs/*/output.zip with local fonts + template precedence; widen TEXINPUTS
Browse files
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()}"]
|
|
@@ -1167,6 +1275,8 @@ The framework builds upon [CAMEL-ai](https://github.com/camel-ai/camel).
|
|
| 1167 |
debug_out = gr.HTML(label="π Debug Preview")
|
| 1168 |
debug_zip_btn= gr.Button("π Test repo output.zip", variant="secondary")
|
| 1169 |
debug_zip_out= gr.HTML(label="π Real Output Preview")
|
|
|
|
|
|
|
| 1170 |
debug_zip_upload = gr.File(label="π Upload poster zip", file_types=[".zip"])
|
| 1171 |
debug_zip_upload_out = gr.HTML(label="π Uploaded Zip Preview")
|
| 1172 |
run_btn.click(
|
|
@@ -1177,6 +1287,7 @@ The framework builds upon [CAMEL-ai](https://github.com/camel-ai/camel).
|
|
| 1177 |
debug_btn.click(fn=debug_compile, inputs=[], outputs=[debug_out])
|
| 1178 |
debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out])
|
| 1179 |
debug_zip_upload.change(fn=debug_compile_uploaded_zip, inputs=[debug_zip_upload], outputs=[debug_zip_upload_out])
|
|
|
|
| 1180 |
|
| 1181 |
if __name__ == "__main__":
|
| 1182 |
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()}"]
|
|
|
|
| 1275 |
debug_out = gr.HTML(label="π Debug Preview")
|
| 1276 |
debug_zip_btn= gr.Button("π Test repo output.zip", variant="secondary")
|
| 1277 |
debug_zip_out= gr.HTML(label="π Real Output Preview")
|
| 1278 |
+
debug_last_btn= gr.Button("π Test last pipeline zip", variant="secondary")
|
| 1279 |
+
debug_last_out= gr.HTML(label="π Last Pipeline Preview")
|
| 1280 |
debug_zip_upload = gr.File(label="π Upload poster zip", file_types=[".zip"])
|
| 1281 |
debug_zip_upload_out = gr.HTML(label="π Uploaded Zip Preview")
|
| 1282 |
run_btn.click(
|
|
|
|
| 1287 |
debug_btn.click(fn=debug_compile, inputs=[], outputs=[debug_out])
|
| 1288 |
debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out])
|
| 1289 |
debug_zip_upload.change(fn=debug_compile_uploaded_zip, inputs=[debug_zip_upload], outputs=[debug_zip_upload_out])
|
| 1290 |
+
debug_last_btn.click(fn=debug_compile_last_pipeline_zip, inputs=[], outputs=[debug_last_out])
|
| 1291 |
|
| 1292 |
if __name__ == "__main__":
|
| 1293 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|