Zen的小站

小舟从此逝,江海寄余生

0%

调用simpletex公式识别api

文章概览

开放平台API文档 (simpletex.cn)

SimpleTex用户中心

公式识别 (simpletex.cn)

个人用

1
2
3
4
5
6
7
8
9
10
11
12
13
import requests
import random, time
import hashlib


url = "https://server.simpletex.cn/api/latex_ocr"
header = {"token": "KHe47xV0oreX6MR2CjFMRpoWwb0i4Z8nVa7Ko7DpczbTfkozsDz0Xzz8IIsZqdgY"}
data = {'file': open('test.png', 'rb')}


x = requests.post(url, files=data, headers=header)

print(x.text)

企业用

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
import requests
import random, time
import hashlib

random_str = ''.join(random.choices('abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789', k=16))
timestamp = str(int(time.time()))
app_id = "e59RqtUBzXil5jvF4I1b4cfq"
app_secret = "xxxxx"

url = "https://server.simpletex.cn/api/latex_ocr"
header = {"random-str": random_str,
"timestamp": timestamp,
"app-id": app_id}
data = {'file': open('test.png', 'rb')}

sign_str = f'app-id={app_id}&random-str={random_str}&timestamp={timestamp}&secret={app_secret}'

# 对拼接的字符串进行MD5签名
signature = hashlib.md5(sign_str.encode()).hexdigest()
header["sign"] = signature
x = requests.post(url, files=data, headers=header)

print(x.text)


1
2
{"status": true, "res": {"conf": 0.939712405204773, "latex": "{\\frac{\\partial V}{\\partial x}}=RI+L{\\frac{\\partial I}{\\partial t}}"}, "request_id": "tr_17098400063327658828874094446"}

第一次成功调用api!轻松

多想多做,发篇一作

-------------本文结束感谢您的阅读-------------
// 在最后添加