import urllib.parse import gradio as gr def render_latex_to_image(latex_str): """ 사용자의 LaTeX 문자열 입력을 받아서 Codecogs LaTeX Rendering API를 이용해 이미지(png 형식)로 변환하고, 생성된 이미지 URL을 반환하는 함수 """ base_url = "https://latex.codecogs.com/png.latex?" # LaTeX 문자열을 URL 인코딩 encoded_str = urllib.parse.quote(latex_str) # 최종 이미지 URL 생성 image_url = f"{base_url}{encoded_str}" return image_url # Gradio 인터페이스 정의 iface = gr.Interface( fn=render_latex_to_image, inputs=gr.Textbox(placeholder="Enter LaTeX code here...", lines=4), outputs=gr.Image(), title="LaTeX to Image Renderer with CodeCogs API", description="Enter LaTeX code to render it into an image using the CodeCogs LaTeX Rendering API." ) # Gradio 인터페이스 실행 iface.launch()