Spaces:
Running
Running
File size: 1,139 Bytes
282ba81 5d72210 282ba81 5d72210 73b4995 5d72210 32eac0f 5d72210 282ba81 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 |
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() |