ocrlatex / app.py
seawolf2357's picture
Update app.py
27249d8 verified
raw
history blame
909 Bytes
import requests
import gradio as gr
def render_latex_to_image(latex_str):
"""
์‚ฌ์šฉ์ž์˜ LaTeX ๋ฌธ์ž์—ด ์ž…๋ ฅ์„ ๋ฐ›์•„์„œ CodeCogs LaTeX API๋ฅผ ์ด์šฉํ•ด ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜ํ•˜๊ณ ,
์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€ URL์„ ๋ฐ˜ํ™˜ํ•˜๋Š” ํ•จ์ˆ˜
"""
encoded_str = requests.utils.quote(latex_str) # URL์— ํฌํ•จ์‹œํ‚ฌ ์ˆ˜ ์žˆ๋„๋ก LaTeX ๋ฌธ์ž์—ด ์ธ์ฝ”๋”ฉ
# CodeCogs LaTeX ๋ Œ๋”๋ง ์„œ๋น„์Šค URL ์ƒ์„ฑ
url = f"https://latex.codecogs.com/png.latex?{encoded_str}"
return url # ์ƒ์„ฑ๋œ ์ด๋ฏธ์ง€์˜ 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",
description="Enter LaTeX code to render it into an image using the CodeCogs LaTeX Rendering API."
)
# Gradio ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
iface.launch()