Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,25 +1,29 @@
|
|
1 |
import gradio as gr
|
2 |
import requests
|
3 |
-
import urllib.parse
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
|
|
18 |
|
19 |
-
|
20 |
-
inputs=gr.TextArea(placeholder="LaTeX ์ฝ๋๋ฅผ ์
๋ ฅํ์ธ์..."),
|
21 |
-
outputs=gr.Image(label="๋ณํ๋ ์ด๋ฏธ์ง"),
|
22 |
-
title="LaTeX ์ฝ๋๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํ",
|
23 |
-
description="Codecogs LaTeX Rendering API๋ฅผ ์ฌ์ฉํ์ฌ LaTeX ์ฝ๋๋ฅผ ์ด๋ฏธ์ง๋ก ๋ณํํฉ๋๋ค.")
|
24 |
-
|
25 |
-
iface.launch()
|
|
|
1 |
import gradio as gr
|
2 |
import requests
|
|
|
3 |
|
4 |
+
# Mathpix ์์ฒญ์ ์ํ ํจ์
|
5 |
+
def process_image_to_latex(file_path):
|
6 |
+
headers = {
|
7 |
+
"app_id": "arxivgpt_2c0986",
|
8 |
+
"app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
|
9 |
+
"Content-type": "application/json"
|
10 |
+
}
|
11 |
+
with open(file_path, "rb") as file:
|
12 |
+
img_data = file.read()
|
13 |
+
response = requests.post(
|
14 |
+
"https://api.mathpix.com/v3/latex",
|
15 |
+
headers=headers,
|
16 |
+
json={"src": "data:image/jpeg;base64," + base64.b64encode(img_data).decode()}
|
17 |
+
)
|
18 |
+
return response.json()["latex"]
|
19 |
|
20 |
+
# Gradio ์ธํฐํ์ด์ค ๊ตฌ์ฑ
|
21 |
+
def create_gradio_interface():
|
22 |
+
with gr.Blocks() as demo:
|
23 |
+
gr.Markdown("## LaTeX ์ถ์ถ๊ธฐ")
|
24 |
+
file_input = gr.File(label="์ด๋ฏธ์ง ๋๋ PDF ํ์ผ ์
๋ก๋")
|
25 |
+
latex_output = gr.Textbox(label="์ถ์ถ๋ LaTeX")
|
26 |
+
file_input.change(fn=process_image_to_latex, inputs=[file_input], outputs=[latex_output])
|
27 |
+
demo.launch()
|
28 |
|
29 |
+
create_gradio_interface()
|
|
|
|
|
|
|
|
|
|
|
|