Spaces:
Running
Running
Siyuan Hu
commited on
Commit
·
4f19e2d
1
Parent(s):
9a566da
feat: PDF compile + preview + debug button
Browse files- app.py +48 -0
- packages.txt +1 -0
- template/logos/left_logo.png +0 -3
- template/logos/right_logo.png +0 -3
- template/poster.bib +0 -9
app.py
CHANGED
|
@@ -1217,6 +1217,54 @@ def run_pipeline(arxiv_url, pdf_file, openai_key, logo_files, meeting_logo_file,
|
|
| 1217 |
), render_overleaf_button(overleaf_zip_b64)
|
| 1218 |
|
| 1219 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1220 |
# =====================
|
| 1221 |
# Gradio UI
|
| 1222 |
# =====================
|
|
|
|
| 1217 |
), render_overleaf_button(overleaf_zip_b64)
|
| 1218 |
|
| 1219 |
|
| 1220 |
+
def debug_compile():
|
| 1221 |
+
"""Generate a minimal LaTeX file, compile it to PDF, and return an HTML preview with an 'open in new tab' link."""
|
| 1222 |
+
logs = [f"🐞 Debug start at {_now_str()}"]
|
| 1223 |
+
# Prepare workspace
|
| 1224 |
+
run_id, WORK_DIR, LOG_PATH, _ = _prepare_workspace(logs)
|
| 1225 |
+
dbg_dir = WORK_DIR / "debug"
|
| 1226 |
+
dbg_dir.mkdir(parents=True, exist_ok=True)
|
| 1227 |
+
tex_path = dbg_dir / "test.tex"
|
| 1228 |
+
tex_path.write_text(r"""
|
| 1229 |
+
\documentclass{article}
|
| 1230 |
+
\usepackage[T1]{fontenc}
|
| 1231 |
+
\usepackage{lmodern}
|
| 1232 |
+
\usepackage[margin=1in]{geometry}
|
| 1233 |
+
\begin{document}
|
| 1234 |
+
Hello, PDF!\\
|
| 1235 |
+
This is a debug build generated at \today.
|
| 1236 |
+
\end{document}
|
| 1237 |
+
""".strip(), encoding="utf-8")
|
| 1238 |
+
|
| 1239 |
+
logs.append(f"Workspace: runs/{WORK_DIR.name}")
|
| 1240 |
+
logs.append(f"Writing: debug/test.tex")
|
| 1241 |
+
|
| 1242 |
+
pdf_path = _compile_tex_to_pdf(tex_path, logs)
|
| 1243 |
+
if not pdf_path or not pdf_path.exists():
|
| 1244 |
+
logs.append("❌ Failed to compile debug PDF.")
|
| 1245 |
+
_write_logs(LOG_PATH, logs)
|
| 1246 |
+
return (
|
| 1247 |
+
"<div style='color:#b00'><b>Debug PDF compile failed.</b></div>"
|
| 1248 |
+
+ f"<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px'>{'\n'.join(logs)}</pre>"
|
| 1249 |
+
)
|
| 1250 |
+
|
| 1251 |
+
# Build preview + open-new-tab link
|
| 1252 |
+
try:
|
| 1253 |
+
b64 = base64.b64encode(pdf_path.read_bytes()).decode("utf-8")
|
| 1254 |
+
open_tab = f"<a target='_blank' rel='noopener' href='data:application/pdf;base64,{b64}'>Open PDF in new tab</a>"
|
| 1255 |
+
html = (
|
| 1256 |
+
f"<div style='margin-bottom:8px'>{open_tab}</div>"
|
| 1257 |
+
+ _pdf_to_iframe_html(pdf_path, height="700px")
|
| 1258 |
+
+ f"<pre style='white-space:pre-wrap;background:#f7f7f8;padding:8px;border-radius:6px;margin-top:8px'>{'\n'.join(logs[-60:])}</pre>"
|
| 1259 |
+
)
|
| 1260 |
+
_write_logs(LOG_PATH, logs)
|
| 1261 |
+
return html
|
| 1262 |
+
except Exception as e:
|
| 1263 |
+
logs.append(f"⚠️ Building preview failed: {e}")
|
| 1264 |
+
_write_logs(LOG_PATH, logs)
|
| 1265 |
+
return f"<div>Compiled but preview failed: {e}</div>"
|
| 1266 |
+
|
| 1267 |
+
|
| 1268 |
# =====================
|
| 1269 |
# Gradio UI
|
| 1270 |
# =====================
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
tectonic
|
template/logos/left_logo.png
DELETED
Git LFS Details
|
template/logos/right_logo.png
DELETED
Git LFS Details
|
template/poster.bib
DELETED
|
@@ -1,9 +0,0 @@
|
|
| 1 |
-
@article{shannon1948communication,
|
| 2 |
-
author = {Claude E. Shannon},
|
| 3 |
-
title = {A Mathematical Theory of Communication},
|
| 4 |
-
journal = {Bell System Technical Journal},
|
| 5 |
-
year = 1948,
|
| 6 |
-
volume = {27},
|
| 7 |
-
number = {3},
|
| 8 |
-
pages = {379-423},
|
| 9 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|