Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -3,38 +3,32 @@ import requests
|
|
3 |
import json
|
4 |
import base64
|
5 |
|
6 |
-
# Mathpix์ ์ด๋ฏธ์ง ํ์ผ์ ๋ณด๋ด์ด ์ฌ๋ฌ ํฌ๋งท์ LaTeX ๋ฌธ์์ด์ ์ถ์ถํ๋ ํจ์
|
7 |
def get_latex_from_image_all_formats(image):
|
8 |
image_base64 = base64.b64encode(image).decode('utf-8')
|
9 |
|
10 |
-
# Mathpix API ์์ฒญ ํค๋
|
11 |
headers = {
|
12 |
"app_id": "arxivgpt_2c0986",
|
13 |
"app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
|
14 |
"Content-Type": "application/json"
|
15 |
}
|
16 |
|
17 |
-
# Mathpix API ์์ฒญ ๋ฐ๋
|
18 |
data = {
|
19 |
"src": f"data:image/jpeg;base64,{image_base64}",
|
20 |
"formats": ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]
|
21 |
}
|
22 |
|
23 |
-
# Mathpix API ์์ฒญ ๋ณด๋ด๊ธฐ
|
24 |
response = requests.post("https://api.mathpix.com/v3/latex", headers=headers, json=data)
|
25 |
-
response.raise_for_status()
|
26 |
|
27 |
-
# ์๋ต์์ ๊ฐ ํฌ๋งท์ LaTeX ์ถ์ถ
|
28 |
result = response.json()
|
29 |
formats_results = {f: result.get(f, "์ถ์ถ ์คํจ") for f in data["formats"]}
|
30 |
|
31 |
return formats_results
|
32 |
|
33 |
-
# Gradio ์ฑ ์ ์
|
34 |
def build_gradio_app():
|
35 |
with gr.Blocks() as app:
|
36 |
with gr.Row():
|
37 |
-
image_input = gr.Image(type="
|
38 |
submit_button = gr.Button("๋ณํํ๊ธฐ")
|
39 |
outputs = {f: gr.Textbox(label=f"{f} ๊ฒฐ๊ณผ") for f in ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]}
|
40 |
|
@@ -42,7 +36,6 @@ def build_gradio_app():
|
|
42 |
|
43 |
return app
|
44 |
|
45 |
-
# Gradio ์ฑ ์คํ
|
46 |
if __name__ == "__main__":
|
47 |
app = build_gradio_app()
|
48 |
app.launch()
|
|
|
3 |
import json
|
4 |
import base64
|
5 |
|
|
|
6 |
def get_latex_from_image_all_formats(image):
|
7 |
image_base64 = base64.b64encode(image).decode('utf-8')
|
8 |
|
|
|
9 |
headers = {
|
10 |
"app_id": "arxivgpt_2c0986",
|
11 |
"app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5",
|
12 |
"Content-Type": "application/json"
|
13 |
}
|
14 |
|
|
|
15 |
data = {
|
16 |
"src": f"data:image/jpeg;base64,{image_base64}",
|
17 |
"formats": ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]
|
18 |
}
|
19 |
|
|
|
20 |
response = requests.post("https://api.mathpix.com/v3/latex", headers=headers, json=data)
|
21 |
+
response.raise_for_status()
|
22 |
|
|
|
23 |
result = response.json()
|
24 |
formats_results = {f: result.get(f, "์ถ์ถ ์คํจ") for f in data["formats"]}
|
25 |
|
26 |
return formats_results
|
27 |
|
|
|
28 |
def build_gradio_app():
|
29 |
with gr.Blocks() as app:
|
30 |
with gr.Row():
|
31 |
+
image_input = gr.Image(type="filepath", label="์ด๋ฏธ์ง ์
๋ก๋") # 'file' ํ์
์ 'filepath'๋ก ๋ณ๊ฒฝ
|
32 |
submit_button = gr.Button("๋ณํํ๊ธฐ")
|
33 |
outputs = {f: gr.Textbox(label=f"{f} ๊ฒฐ๊ณผ") for f in ["text", "latex_styled", "latex_normal", "latex_list", "latex_simplified", "asciimath", "mathml"]}
|
34 |
|
|
|
36 |
|
37 |
return app
|
38 |
|
|
|
39 |
if __name__ == "__main__":
|
40 |
app = build_gradio_app()
|
41 |
app.launch()
|