seawolf2357 commited on
Commit
088654a
ยท
verified ยท
1 Parent(s): 32eac0f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -15
app.py CHANGED
@@ -1,22 +1,31 @@
 
1
  import gradio as gr
2
- import requests
 
3
 
4
- def latex_to_image(latex_code):
5
- # ๊ธฐ๋ณธ์ ์ธ LaTeX ๋ฌธ๋ฒ• ๊ฒ€์‚ฌ ์˜ˆ์‹œ
6
- if not latex_code.startswith("\\"):
7
- return "invalid equation: LaTeX commands should start with a backslash (\\)."
8
-
9
- # ์‹ค์ œ ๋ Œ๋”๋ง URL ์ƒ์„ฑ ๋กœ์ง
10
- codecogs_url = "https://latex.codecogs.com/png.latex?"
11
- response_url = codecogs_url + requests.utils.quote(latex_code)
12
 
13
- return response_url
 
 
 
 
 
 
14
 
 
 
15
 
 
 
 
 
 
 
16
 
17
- iface = gr.Interface(fn=latex_to_image,
18
- inputs=gr.Textbox(label="Enter your LaTeX code here"),
19
- outputs=gr.Image(label="Rendered LaTeX"),
20
- title="LaTeX to Image Converter",
21
- description="This tool converts LaTeX code to an image using an external rendering service.")
22
  iface.launch()
 
1
+ import matplotlib.pyplot as plt
2
  import gradio as gr
3
+ import tempfile
4
+ import shutil
5
 
6
+ def render_latex(latex_code):
7
+ # ์ž„์‹œ ํŒŒ์ผ ์ƒ์„ฑ
8
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
9
+ temp_file_name = temp_file.name
10
+ temp_file.close()
 
 
 
11
 
12
+ # LaTeX ์ฝ”๋“œ๋ฅผ matplotlib์„ ์‚ฌ์šฉํ•˜์—ฌ ์ด๋ฏธ์ง€๋กœ ๋ Œ๋”๋ง
13
+ plt.rc('text', usetex=True)
14
+ plt.rc('font', family='serif')
15
+ plt.axis('off')
16
+ plt.text(0.5, 0.5, f'${latex_code}$', ha='center', va='center', fontsize=20)
17
+ plt.savefig(temp_file_name, bbox_inches='tight', pad_inches=0.1)
18
+ plt.close()
19
 
20
+ # ์ž„์‹œ ์ด๋ฏธ์ง€ ํŒŒ์ผ ๊ฒฝ๋กœ ๋ฐ˜ํ™˜
21
+ return temp_file_name
22
 
23
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์ •์˜
24
+ iface = gr.Interface(fn=render_latex,
25
+ inputs=gr.Textbox(placeholder="Enter LaTeX code here..."),
26
+ outputs=gr.Image(type='file'),
27
+ title="LaTeX Renderer",
28
+ description="Enter a LaTeX code to render it into an image.")
29
 
30
+ # Gradio ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
 
 
 
 
31
  iface.launch()