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