File size: 1,011 Bytes
282ba81
5d72210
282ba81
f5d8dcc
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5d72210
f5d8dcc
 
 
 
 
 
 
 
32eac0f
f5d8dcc
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
import gradio as gr
import requests

# Mathpix ์š”์ฒญ์„ ์œ„ํ•œ ํ•จ์ˆ˜
def process_image_to_latex(file_path):
    headers = {
        "app_id": "arxivgpt_2c0986",
        "app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
        "Content-type": "application/json"
    }
    with open(file_path, "rb") as file:
        img_data = file.read()
    response = requests.post(
        "https://api.mathpix.com/v3/latex",
        headers=headers,
        json={"src": "data:image/jpeg;base64," + base64.b64encode(img_data).decode()}
    )
    return response.json()["latex"]

# Gradio ์ธํ„ฐํŽ˜์ด์Šค ๊ตฌ์„ฑ
def create_gradio_interface():
    with gr.Blocks() as demo:
        gr.Markdown("## LaTeX ์ถ”์ถœ๊ธฐ")
        file_input = gr.File(label="์ด๋ฏธ์ง€ ๋˜๋Š” PDF ํŒŒ์ผ ์—…๋กœ๋“œ")
        latex_output = gr.Textbox(label="์ถ”์ถœ๋œ LaTeX")
        file_input.change(fn=process_image_to_latex, inputs=[file_input], outputs=[latex_output])
    demo.launch()

create_gradio_interface()