Spaces:
Running
Running
import gradio as gr | |
import requests | |
import urllib.parse | |
def latex_to_image_via_api(latex_code): | |
encoded_latex = urllib.parse.quote(latex_code) # LaTeX ์ฝ๋๋ฅผ URL ์ธ์ฝ๋ฉ | |
api_url = f"https://latex.codecogs.com/png.download?{encoded_latex}" # URL ์์ฑ | |
response = requests.get(api_url) # API ์์ฒญ | |
if response.status_code == 200: | |
# ์๋ต์ผ๋ก๋ถํฐ ๋ฐ์ด๋๋ฆฌ ๋ฐ์ดํฐ๋ฅผ ๋ฐ์ ์์ ํ์ผ์ ์ ์ฅ | |
with open("latex_image.png", "wb") as f: | |
f.write(response.content) # ์ด๋ฏธ์ง ๋ด์ฉ์ ํ์ผ์ ์ด๋ค | |
return "latex_image.png" # ์ด๋ฏธ์ง ํ์ผ ๊ฒฝ๋ก ๋ฐํ | |
else: | |
return "LaTeX ๋ณํ ์คํจ: API ํธ์ถ์ ์คํจํ์ต๋๋ค." | |
iface = gr.Interface(fn=latex_to_image_via_api, | |
inputs=gr.Textarea(placeholder="LaTeX ์ฝ๋๋ฅผ ์ ๋ ฅํ์ธ์..."), | |
outputs=gr.Image(label="๋ณํ๋ ์ด๋ฏธ์ง"), | |
title="LaTeX ์ฝ๋๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํ", | |
description="Codecogs LaTeX Rendering API๋ฅผ ์ฌ์ฉํ์ฌ LaTeX ์ฝ๋๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํํฉ๋๋ค.") | |
iface.launch() |