ocrlatex / app.py
seawolf2357's picture
Update app.py
deca144 verified
raw
history blame
1.08 kB
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()