ocrlatex / app.py
seawolf2357's picture
Update app.py
f5d8dcc verified
raw
history blame
1.01 kB
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()