Spaces:
Running
Running
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() |