File size: 1,428 Bytes
112423f
5d72210
b8f450e
9a35c66
 
3bd25bb
 
282ba81
f5d8dcc
3bd25bb
 
b8f450e
f5d8dcc
5d72210
b8f450e
112423f
5be7449
b8f450e
 
112423f
1862a67
3bd25bb
b8f450e
3bd25bb
b8f450e
3bd25bb
32eac0f
112423f
 
fd7ec7d
1862a67
112423f
3bd25bb
112423f
3bd25bb
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
import gradio as gr
import requests
import json
import base64

def get_latex_from_image_all_formats(image):
    image_base64 = base64.b64encode(image).decode('utf-8')

    headers = {
        "app_id": "arxivgpt_2c0986",
        "app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
        "Content-Type": "application/json"
    }

    data = {
        "src": f"data:image/jpeg;base64,{image_base64}",
        "formats": ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]
    }

    response = requests.post("https://api.mathpix.com/v3/latex", headers=headers, json=data)
    response.raise_for_status()

    result = response.json()
    formats_results = {f: result.get(f, "추출 실패") for f in data["formats"]}

    return formats_results

def build_gradio_app():
    with gr.Blocks() as app:
        with gr.Row():
            image_input = gr.Image(type="filepath", label="이미지 업로드")  # 'file' 타입을 'filepath'로 변경
            submit_button = gr.Button("변환하기")
        outputs = {f: gr.Textbox(label=f"{f} 결과") for f in ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]}

        submit_button.click(fn=get_latex_from_image_all_formats, inputs=[image_input], outputs=outputs)

    return app

if __name__ == "__main__":
    app = build_gradio_app()
    app.launch()