Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,22 +1,31 @@
|
|
|
|
1 |
import gradio as gr
|
2 |
-
import
|
|
|
3 |
|
4 |
-
def
|
5 |
-
#
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
# ์ค์ ๋ ๋๋ง URL ์์ฑ ๋ก์ง
|
10 |
-
codecogs_url = "https://latex.codecogs.com/png.latex?"
|
11 |
-
response_url = codecogs_url + requests.utils.quote(latex_code)
|
12 |
|
13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
|
|
|
|
|
15 |
|
|
|
|
|
|
|
|
|
|
|
|
|
16 |
|
17 |
-
|
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()
|