Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -22
src/streamlit_app.py
CHANGED
|
@@ -19,34 +19,25 @@ def compile_latex(source: str) -> bytes:
|
|
| 19 |
bytes
|
| 20 |
The compiled PDF file contents.
|
| 21 |
"""
|
| 22 |
-
# Create a sandbox directory for all generated files
|
| 23 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 24 |
-
#
|
| 25 |
-
doc = Document(
|
| 26 |
-
# This sets the base filename for output (without extension)
|
| 27 |
-
"document",
|
| 28 |
-
documentclass="article",
|
| 29 |
-
font_size="10pt",
|
| 30 |
-
)
|
| 31 |
doc.append(source)
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
# Generate PDF; this writes 'document.pdf' into tmpdir
|
| 36 |
_ = doc.generate_pdf(
|
| 37 |
-
filepath=
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
-
|
| 44 |
-
pdf_path = Path(output_base + ".pdf")
|
| 45 |
-
return pdf_path.read_bytes()
|
| 46 |
|
| 47 |
def main():
|
| 48 |
-
"
|
| 49 |
-
st.title("LaTeX Compiler on Hugging Face Space")
|
| 50 |
prompt = st.text_area(
|
| 51 |
"Enter full LaTeX source",
|
| 52 |
value=(
|
|
@@ -60,8 +51,8 @@ def main():
|
|
| 60 |
|
| 61 |
if st.button("Compile to PDF"):
|
| 62 |
with st.spinner("Compiling…"):
|
| 63 |
-
pdf_bytes = compile_latex(
|
| 64 |
-
st.success("
|
| 65 |
st.download_button(
|
| 66 |
"Download PDF",
|
| 67 |
data=pdf_bytes,
|
|
|
|
| 19 |
bytes
|
| 20 |
The compiled PDF file contents.
|
| 21 |
"""
|
|
|
|
| 22 |
with tempfile.TemporaryDirectory() as tmpdir:
|
| 23 |
+
# ドキュメントを初期化
|
| 24 |
+
doc = Document("document", documentclass="article", font_size="10pt")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
doc.append(source)
|
| 26 |
|
| 27 |
+
base_path = os.path.join(tmpdir, "document")
|
| 28 |
+
# compiler 引数で pdflatex を指定。latexmk があれば省略可。
|
|
|
|
| 29 |
_ = doc.generate_pdf(
|
| 30 |
+
filepath=base_path,
|
| 31 |
+
compiler="pdflatex",
|
| 32 |
+
clean=True,
|
| 33 |
+
clean_tex=True,
|
| 34 |
+
silent=True,
|
| 35 |
)
|
| 36 |
|
| 37 |
+
return Path(base_path + ".pdf").read_bytes()
|
|
|
|
|
|
|
| 38 |
|
| 39 |
def main():
|
| 40 |
+
st.title("LaTeX Compiler")
|
|
|
|
| 41 |
prompt = st.text_area(
|
| 42 |
"Enter full LaTeX source",
|
| 43 |
value=(
|
|
|
|
| 51 |
|
| 52 |
if st.button("Compile to PDF"):
|
| 53 |
with st.spinner("Compiling…"):
|
| 54 |
+
pdf_bytes = compile_latex(prompt)
|
| 55 |
+
st.success("Compilation succeeded")
|
| 56 |
st.download_button(
|
| 57 |
"Download PDF",
|
| 58 |
data=pdf_bytes,
|