Spaces:
Running
Running
Siyuan Hu
commited on
Commit
Β·
489ab2a
1
Parent(s):
aab81af
feat(debug): add UI to compile repo output.zip and uploaded zip; connect handlers (no binary files)
Browse files
app.py
CHANGED
|
@@ -605,6 +605,181 @@ This is a debug build generated at \today.
|
|
| 605 |
_write_logs(LOG_PATH, logs)
|
| 606 |
return f"<div>Compiled but preview failed: {e}</div>"
|
| 607 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 608 |
# =====================
|
| 609 |
# Gradio pipeline function (ISOLATED)
|
| 610 |
# =====================
|
|
@@ -912,11 +1087,9 @@ The framework builds upon [CAMEL-ai](https://github.com/camel-ai/camel).
|
|
| 912 |
inputs=[arxiv_in, pdf_in, key_in, inst_logo_in, conf_logo_in, theme_in],
|
| 913 |
outputs=[logs_out, pdf_out, zip_out, overleaf_out],
|
| 914 |
)
|
| 915 |
-
debug_btn.click(
|
| 916 |
-
|
| 917 |
-
|
| 918 |
-
outputs=[debug_out],
|
| 919 |
-
)
|
| 920 |
|
| 921 |
if __name__ == "__main__":
|
| 922 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 605 |
_write_logs(LOG_PATH, logs)
|
| 606 |
return f"<div>Compiled but preview failed: {e}</div>"
|
| 607 |
|
| 608 |
+
def debug_compile_output_zip():
|
| 609 |
+
"""Compile the repo-root output.zip (a real LaTeX project) and preview the resulting PDF."""
|
| 610 |
+
logs = [f"π Debug(real) at {_now_str()}"]
|
| 611 |
+
zip_path = ROOT / "output.zip"
|
| 612 |
+
if not zip_path.exists():
|
| 613 |
+
return (
|
| 614 |
+
"<div style='color:#b00'><b>output.zip not found at repo root.</b></div>"
|
| 615 |
+
+ f"<div>Expected at: {zip_path}</div>"
|
| 616 |
+
)
|
| 617 |
+
|
| 618 |
+
# Prepare workspace
|
| 619 |
+
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 620 |
+
work_zip_dir = WORK_DIR / "zip_proj"
|
| 621 |
+
work_zip_dir.mkdir(parents=True, exist_ok=True)
|
| 622 |
+
logs.append(f"Workspace: runs/{WORK_DIR.name}")
|
| 623 |
+
logs.append("Unzipping output.zip β zip_proj/")
|
| 624 |
+
|
| 625 |
+
# Extract zip
|
| 626 |
+
try:
|
| 627 |
+
import zipfile as _zf
|
| 628 |
+
with _zf.ZipFile(zip_path, 'r') as zf:
|
| 629 |
+
zf.extractall(work_zip_dir)
|
| 630 |
+
except Exception as e:
|
| 631 |
+
logs.append(f"β unzip failed: {e}")
|
| 632 |
+
_write_logs(LOG_PATH, logs)
|
| 633 |
+
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 634 |
+
|
| 635 |
+
# Locate poster_output.tex (fallback to poster.tex)
|
| 636 |
+
tex_path = None
|
| 637 |
+
for name in ("poster_output.tex", "poster.tex"):
|
| 638 |
+
cand = list(work_zip_dir.rglob(name))
|
| 639 |
+
if cand:
|
| 640 |
+
tex_path = cand[0]
|
| 641 |
+
break
|
| 642 |
+
if tex_path is None:
|
| 643 |
+
# fallback: any .tex
|
| 644 |
+
cand = list(work_zip_dir.rglob("*.tex"))
|
| 645 |
+
if cand:
|
| 646 |
+
tex_path = cand[0]
|
| 647 |
+
if tex_path is None:
|
| 648 |
+
logs.append("β No .tex file found in output.zip")
|
| 649 |
+
_write_logs(LOG_PATH, logs)
|
| 650 |
+
return "<div style='color:#b00'>No .tex found in output.zip</div>"
|
| 651 |
+
|
| 652 |
+
# If left_logo missing, disable \logoleft
|
| 653 |
+
try:
|
| 654 |
+
logos_dir = tex_path.parent / "logos"
|
| 655 |
+
has_left = False
|
| 656 |
+
if logos_dir.exists():
|
| 657 |
+
for p in logos_dir.iterdir():
|
| 658 |
+
if p.is_file() and p.stem == "left_logo":
|
| 659 |
+
has_left = True
|
| 660 |
+
break
|
| 661 |
+
if not has_left:
|
| 662 |
+
txt = tex_path.read_text(encoding="utf-8")
|
| 663 |
+
if "\\logoleft" in txt:
|
| 664 |
+
import re as _re
|
| 665 |
+
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
|
| 666 |
+
if new_txt != txt:
|
| 667 |
+
tex_path.write_text(new_txt, encoding="utf-8")
|
| 668 |
+
logs.append("βΉοΈ No left_logo found; disabled \\logoleft in zip project.")
|
| 669 |
+
except Exception as e:
|
| 670 |
+
logs.append(f"β οΈ left_logo adjust failed: {e}")
|
| 671 |
+
|
| 672 |
+
# Compile to PDF
|
| 673 |
+
pdf_path = _compile_tex_to_pdf(tex_path, logs)
|
| 674 |
+
if not pdf_path or not pdf_path.exists():
|
| 675 |
+
logs.append("β Failed to compile zip PDF.")
|
| 676 |
+
_write_logs(LOG_PATH, logs)
|
| 677 |
+
return (
|
| 678 |
+
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 679 |
+
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 680 |
+
+ "\n".join(logs)
|
| 681 |
+
+ "</pre>"
|
| 682 |
+
)
|
| 683 |
+
|
| 684 |
+
try:
|
| 685 |
+
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
| 686 |
+
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
|
| 687 |
+
html = (
|
| 688 |
+
f"<div style='margin-bottom:8px'>{open_tab}</div>"
|
| 689 |
+
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 690 |
+
)
|
| 691 |
+
_write_logs(LOG_PATH, logs)
|
| 692 |
+
return html
|
| 693 |
+
except Exception as e:
|
| 694 |
+
logs.append(f"β οΈ preview failed: {e}")
|
| 695 |
+
_write_logs(LOG_PATH, logs)
|
| 696 |
+
return f"<div>Compiled but preview failed: {e}</div>"
|
| 697 |
+
|
| 698 |
+
def debug_compile_uploaded_zip(zip_file):
|
| 699 |
+
"""Compile an uploaded poster zip (user-provided) and preview PDF."""
|
| 700 |
+
logs = [f"π Debug(upload) at {_now_str()}"]
|
| 701 |
+
if not zip_file:
|
| 702 |
+
return "<div style='color:#b00'>Please upload a .zip file first.</div>"
|
| 703 |
+
# Prepare workspace
|
| 704 |
+
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 705 |
+
work_zip_dir = WORK_DIR / "zip_upload"
|
| 706 |
+
work_zip_dir.mkdir(parents=True, exist_ok=True)
|
| 707 |
+
# Save uploaded zip
|
| 708 |
+
up_path = work_zip_dir / "input.zip"
|
| 709 |
+
try:
|
| 710 |
+
shutil.copy(zip_file.name, up_path)
|
| 711 |
+
except Exception as e:
|
| 712 |
+
logs.append(f"β save upload failed: {e}")
|
| 713 |
+
_write_logs(LOG_PATH, logs)
|
| 714 |
+
return "<div style='color:#b00'>Save upload failed.</div>"
|
| 715 |
+
# Extract
|
| 716 |
+
try:
|
| 717 |
+
import zipfile as _zf
|
| 718 |
+
with _zf.ZipFile(up_path, 'r') as zf:
|
| 719 |
+
zf.extractall(work_zip_dir)
|
| 720 |
+
except Exception as e:
|
| 721 |
+
logs.append(f"β unzip failed: {e}")
|
| 722 |
+
_write_logs(LOG_PATH, logs)
|
| 723 |
+
return "<div style='color:#b00'>Unzip failed.</div>"
|
| 724 |
+
# Find tex
|
| 725 |
+
tex_path = None
|
| 726 |
+
for name in ("poster_output.tex", "poster.tex"):
|
| 727 |
+
cand = list(work_zip_dir.rglob(name))
|
| 728 |
+
if cand:
|
| 729 |
+
tex_path = cand[0]
|
| 730 |
+
break
|
| 731 |
+
if tex_path is None:
|
| 732 |
+
cand = list(work_zip_dir.rglob("*.tex"))
|
| 733 |
+
if cand:
|
| 734 |
+
tex_path = cand[0]
|
| 735 |
+
if tex_path is None:
|
| 736 |
+
logs.append("β No .tex file found in uploaded zip")
|
| 737 |
+
_write_logs(LOG_PATH, logs)
|
| 738 |
+
return "<div style='color:#b00'>No .tex found in uploaded zip</div>"
|
| 739 |
+
# Disable logoleft if missing
|
| 740 |
+
try:
|
| 741 |
+
logos_dir = tex_path.parent / "logos"
|
| 742 |
+
has_left = False
|
| 743 |
+
if logos_dir.exists():
|
| 744 |
+
for p in logos_dir.iterdir():
|
| 745 |
+
if p.is_file() and p.stem == "left_logo":
|
| 746 |
+
has_left = True
|
| 747 |
+
break
|
| 748 |
+
if not has_left:
|
| 749 |
+
txt = tex_path.read_text(encoding="utf-8")
|
| 750 |
+
if "\\logoleft" in txt:
|
| 751 |
+
import re as _re
|
| 752 |
+
new_txt = _re.sub(r"^\\\s*logoleft\s*\{.*?\}\s*$", lambda m: "%" + m.group(0), txt, flags=_re.MULTILINE)
|
| 753 |
+
if new_txt != txt:
|
| 754 |
+
tex_path.write_text(new_txt, encoding="utf-8")
|
| 755 |
+
logs.append("βΉοΈ No left_logo found; disabled \\logoleft in uploaded project.")
|
| 756 |
+
except Exception as e:
|
| 757 |
+
logs.append(f"β οΈ left_logo adjust failed: {e}")
|
| 758 |
+
# Compile
|
| 759 |
+
pdf_path = _compile_tex_to_pdf(tex_path, logs)
|
| 760 |
+
if not pdf_path or not pdf_path.exists():
|
| 761 |
+
logs.append("β Failed to compile uploaded zip PDF.")
|
| 762 |
+
_write_logs(LOG_PATH, logs)
|
| 763 |
+
return (
|
| 764 |
+
"<div style='color:#b00'><b>Compile failed.</b></div>"
|
| 765 |
+
+ "<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>"
|
| 766 |
+
+ "\n".join(logs)
|
| 767 |
+
+ "</pre>"
|
| 768 |
+
)
|
| 769 |
+
try:
|
| 770 |
+
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
| 771 |
+
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
|
| 772 |
+
html = (
|
| 773 |
+
f"<div style='margin-bottom:8px'>{open_tab}</div>"
|
| 774 |
+
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 775 |
+
)
|
| 776 |
+
_write_logs(LOG_PATH, logs)
|
| 777 |
+
return html
|
| 778 |
+
except Exception as e:
|
| 779 |
+
logs.append(f"β οΈ preview failed: {e}")
|
| 780 |
+
_write_logs(LOG_PATH, logs)
|
| 781 |
+
return f"<div>Compiled but preview failed: {e}</div>"
|
| 782 |
+
|
| 783 |
# =====================
|
| 784 |
# Gradio pipeline function (ISOLATED)
|
| 785 |
# =====================
|
|
|
|
| 1087 |
inputs=[arxiv_in, pdf_in, key_in, inst_logo_in, conf_logo_in, theme_in],
|
| 1088 |
outputs=[logs_out, pdf_out, zip_out, overleaf_out],
|
| 1089 |
)
|
| 1090 |
+
debug_btn.click(fn=debug_compile, inputs=[], outputs=[debug_out])
|
| 1091 |
+
debug_zip_btn.click(fn=debug_compile_output_zip, inputs=[], outputs=[debug_zip_out])
|
| 1092 |
+
debug_zip_upload.change(fn=debug_compile_uploaded_zip, inputs=[debug_zip_upload], outputs=[debug_zip_upload_out])
|
|
|
|
|
|
|
| 1093 |
|
| 1094 |
if __name__ == "__main__":
|
| 1095 |
iface.launch(server_name="0.0.0.0", server_port=7860)
|