Spaces:
Runtime error
Runtime error
File size: 1,080 Bytes
088654a 282ba81 088654a 282ba81 088654a 6e98020 088654a 32eac0f 088654a 32eac0f 088654a deca144 088654a 282ba81 088654a 6e98020 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
import matplotlib.pyplot as plt
import gradio as gr
import tempfile
import shutil
def render_latex(latex_code):
# ์์ ํ์ผ ์์ฑ
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.png')
temp_file_name = temp_file.name
temp_file.close()
# LaTeX ์ฝ๋๋ฅผ matplotlib์ ์ฌ์ฉํ์ฌ ์ด๋ฏธ์ง๋ก ๋ ๋๋ง
plt.rc('text', usetex=True)
plt.rc('font', family='serif')
plt.axis('off')
plt.text(0.5, 0.5, f'${latex_code}$', ha='center', va='center', fontsize=20)
plt.savefig(temp_file_name, bbox_inches='tight', pad_inches=0.1)
plt.close()
# ์์ ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก ๋ฐํ
return temp_file_name
# Gradio ์ธํฐํ์ด์ค ์ ์
iface = gr.Interface(fn=render_latex,
inputs=gr.Textbox(placeholder="Enter LaTeX code here..."),
outputs=gr.Image(type='filepath'), # ์์ ๋ ๋ถ๋ถ
title="LaTeX Renderer",
description="Enter a LaTeX code to render it into an image.")
# Gradio ์ธํฐํ์ด์ค ์คํ
iface.launch() |