Samarth Naik commited on
Commit
75f0815
·
1 Parent(s): b5cdcf6

init: latex v1

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +24 -4
README.md CHANGED
@@ -7,4 +7,4 @@ sdk: docker
7
  pinned: false
8
  ---
9
 
10
- Upload a `.tex` file and the Space will compile it with LaTeX and return the rendered PDF.
 
7
  pinned: false
8
  ---
9
 
10
+ Upload a main `.tex` file plus any supporting assets like images or bibliography files, and the Space will compile it with LaTeX and return the rendered PDF.
app.py CHANGED
@@ -3,6 +3,7 @@ import shutil
3
  import subprocess
4
  import tempfile
5
  from pathlib import Path
 
6
 
7
  import gradio as gr
8
 
@@ -10,7 +11,15 @@ import gradio as gr
10
  PORT = int(os.environ.get("PORT", "7860"))
11
 
12
 
13
- def compile_latex(tex_file_path: str):
 
 
 
 
 
 
 
 
14
  if not tex_file_path:
15
  raise gr.Error("Upload a .tex file to compile.")
16
 
@@ -21,7 +30,8 @@ def compile_latex(tex_file_path: str):
21
  with tempfile.TemporaryDirectory() as temp_dir:
22
  temp_path = Path(temp_dir)
23
  working_tex = temp_path / source_path.name
24
- shutil.copy(source_path, working_tex)
 
25
 
26
  latexmk_command = [
27
  "latexmk",
@@ -66,7 +76,8 @@ with gr.Blocks(title="Latexee") as demo:
66
  gr.Markdown(
67
  """
68
  # Latexee
69
- Upload a `.tex` file and get back the rendered PDF.
 
70
  """
71
  )
72
 
@@ -77,10 +88,19 @@ with gr.Blocks(title="Latexee") as demo:
77
  file_types=[".tex"],
78
  type="filepath",
79
  )
 
 
 
 
 
80
  pdf_output = gr.File(label="Rendered PDF")
81
 
82
  compile_button = gr.Button("Render PDF", variant="primary")
83
- compile_button.click(fn=compile_latex, inputs=tex_input, outputs=pdf_output)
 
 
 
 
84
 
85
 
86
  if __name__ == "__main__":
 
3
  import subprocess
4
  import tempfile
5
  from pathlib import Path
6
+ from typing import Iterable
7
 
8
  import gradio as gr
9
 
 
11
  PORT = int(os.environ.get("PORT", "7860"))
12
 
13
 
14
+ def _copy_inputs(paths: Iterable[str], destination: Path) -> None:
15
+ for raw_path in paths:
16
+ if not raw_path:
17
+ continue
18
+ source_path = Path(raw_path)
19
+ shutil.copy(source_path, destination / source_path.name)
20
+
21
+
22
+ def compile_latex(tex_file_path: str, attachment_paths: list[str] | None):
23
  if not tex_file_path:
24
  raise gr.Error("Upload a .tex file to compile.")
25
 
 
30
  with tempfile.TemporaryDirectory() as temp_dir:
31
  temp_path = Path(temp_dir)
32
  working_tex = temp_path / source_path.name
33
+ _copy_inputs([tex_file_path], temp_path)
34
+ _copy_inputs(attachment_paths or [], temp_path)
35
 
36
  latexmk_command = [
37
  "latexmk",
 
76
  gr.Markdown(
77
  """
78
  # Latexee
79
+ Upload a main `.tex` file plus any supporting assets like `.jpg`, `.png`,
80
+ `.bib`, `.sty`, or extra TeX files, and get back the rendered PDF.
81
  """
82
  )
83
 
 
88
  file_types=[".tex"],
89
  type="filepath",
90
  )
91
+ attachment_input = gr.File(
92
+ label="Supporting files",
93
+ file_count="multiple",
94
+ type="filepath",
95
+ )
96
  pdf_output = gr.File(label="Rendered PDF")
97
 
98
  compile_button = gr.Button("Render PDF", variant="primary")
99
+ compile_button.click(
100
+ fn=compile_latex,
101
+ inputs=[tex_input, attachment_input],
102
+ outputs=pdf_output,
103
+ )
104
 
105
 
106
  if __name__ == "__main__":