File size: 1,482 Bytes
112423f
5d72210
b8f450e
9a35c66
 
b8f450e
112423f
0350c55
112423f
282ba81
b8f450e
f5d8dcc
112423f
 
b8f450e
f5d8dcc
5d72210
b8f450e
 
112423f
b8f450e
 
 
 
112423f
b8f450e
 
 
 
112423f
b8f450e
 
32eac0f
112423f
 
 
fd7ec7d
0350c55
112423f
 
 
fd7ec7d
112423f
 
 
 
 
 
 
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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import gradio as gr
import requests
import json
import base64

# Mathpix์— ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ ๋ณด๋‚ด์–ด LaTeX ๋ฌธ์ž์—ด์„ ์ถ”์ถœํ•˜๋Š” ํ•จ์ˆ˜
def get_latex_from_image(image):
    # ์ด๋ฏธ์ง€ ํŒŒ์ผ์„ base64 ์ธ์ฝ”๋”ฉ
    image_base64 = base64.b64encode(image).decode('utf-8')

    # Mathpix API ์š”์ฒญ ํ—ค๋”
    headers = {
        "app_id": "arxivgpt_2c0986",
        "app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
        "Content-Type": "application/json"
    }

    # Mathpix API ์š”์ฒญ ๋ฐ”๋””
    data = {
        "src": f"data:image/jpeg;base64,{image_base64}",
        "formats": ["latex_normal"]
    }

    # Mathpix API ์š”์ฒญ ๋ณด๋‚ด๊ธฐ
    response = requests.post("https://api.mathpix.com/v3/latex", headers=headers, json=data)
    response.raise_for_status()  # ์š”์ฒญ ์‹คํŒจ ์‹œ ์˜ˆ์™ธ ๋ฐœ์ƒ

    # ์‘๋‹ต์—์„œ LaTeX ์ถ”์ถœ
    result = response.json()
    latex = result.get('latex_normal', "LaTeX ์ถ”์ถœ ์‹คํŒจ")

    return latex

# Gradio ์•ฑ ์ •์˜
def build_gradio_app():
    with gr.Blocks() as app:
        with gr.Row():
            image_input = gr.Image(type="filepath", label="์ด๋ฏธ์ง€ ์—…๋กœ๋“œ")
            submit_button = gr.Button("๋ณ€ํ™˜ํ•˜๊ธฐ")
        latex_output = gr.Textbox(label="์ถ”์ถœ๋œ LaTeX")

        submit_button.click(fn=get_latex_from_image, inputs=image_input, outputs=latex_output)

    return app

# Gradio ์•ฑ ์‹คํ–‰
if __name__ == "__main__":
    app = build_gradio_app()
    app.launch()