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()