Spaces:
Running
Running
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() | |