Spaces:
Running
Running
File size: 1,168 Bytes
5d72210 b8f450e 9a35c66 b8f450e 282ba81 b8f450e f5d8dcc b8f450e f5d8dcc 5d72210 b8f450e 32eac0f b8f450e |
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 31 32 33 34 35 36 37 |
import requests
import json
import base64
# Mathpix์ ์ด๋ฏธ์ง ํ์ผ์ ๋ณด๋ด์ด LaTeX ๋ฌธ์์ด์ ์ถ์ถํ๋ ํจ์
def get_latex_from_image(image_path):
# ์ด๋ฏธ์ง ํ์ผ์ base64 ์ธ์ฝ๋ฉ
with open(image_path, "rb") as f:
image_base64 = base64.b64encode(f.read()).decode()
# Mathpix API ์์ฒญ ํค๋
headers = {
"app_id": "arxivgpt_2c0986", # ์ฌ๊ธฐ์ Mathpix ID๋ฅผ ์
๋ ฅ
"app_key": "b5c14c78ea645a6d673195e6360a1cc33ef2bab7a79b90f7cebf6465177171f5", # ์ฌ๊ธฐ์ Mathpix API ํค๋ฅผ ์
๋ ฅ
"Content-Type": "application/json"
}
# Mathpix API ์์ฒญ ๋ฐ๋
data = {
"src": "data:image/png;base64," + image_base64,
"formats": ["latex_normal"]
}
# Mathpix API ์์ฒญ ๋ณด๋ด๊ธฐ
response = requests.post("https://api.mathpix.com/v3/latex", headers=headers, data=json.dumps(data))
response.raise_for_status() # ์์ฒญ ์คํจ ์ ์์ธ ๋ฐ์
# ์๋ต์์ LaTeX ์ถ์ถ
result = response.json()
latex = result['latex_normal']
return latex
# ์ถ์ถํ LaTeX ์ถ๋ ฅ
latex_string = get_latex_from_image("path/to/image.png")
print(latex_string)
|