1 Star 3 Fork 0

sky/qianniu

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
ocr.py 2.05 KB
一键复制 编辑 原始数据 按行查看 历史
Lixf 提交于 2024-12-18 22:47 . 保存客服和旺旺号
import requests
import base64
import json
from datetime import datetime
smart_server = 'http://118.24.37.241:18080/smart'
# smart_server = 'http://localhost:18080/smart'
smart_token = "54DD84sg0sa18m6jq8u6bmbqYUdfu8dsx"
def get_file_content(filePath):
with open(filePath, 'rb') as fp:
encoded_string = base64.b64encode(fp.read())
return encoded_string.decode("utf-8")
def recognize(file_path):
url = "https://eolink.o.apispace.com/ocrbase/ocr/v1/base"
image = get_file_content(filePath=file_path)
payload = {"image":image,"url":"","pdf":"","language":"CHN_ENG"}
headers = {
"X-APISpace-Token":"5zjtsg0sa18m6tceas6ljq8u6b5vmmbq",
"Content-Type":"application/json"
}
response=requests.request("POST", url, data=json.dumps(payload), headers=headers)
print(response.text)
return response.text
def match_price(payload):
url = smart_server + "/reply/match/price/byOcr"
headers = {
"token": smart_token,
"Content-Type":"application/json"
}
response=requests.request("POST", url, data=json.dumps(payload), headers=headers)
print(response.text)
res = json.loads(response.text)
if (res['code'] == 200 and res['data'] is not None):
return res['data']
return "正在查询,请稍候..."
def get_hardware(name):
url = smart_server + "/system/hardware?name=" + name
headers = {
"token": smart_token,
"Content-Type":"application/json"
}
response = requests.get(url=url,headers=headers)
res = json.loads(response.text)
print(res)
if (res['code'] == 200):
return res['data']
print("查询硬件信息失败,请联系管理员!!!!!" + res['message'])
return None
if __name__ == "__main__":
print(datetime.now().strftime('%Y-%m-%d-%H:%M:%S.s '),888,"测试文字")
ocrResponse = recognize(r"C:\Users\lixf\Desktop\temp\0.jpg")
priceRequest = {
'hardwareName': 'windows_L14_1920*1080_percent100',
'wangwangName': 'test',
'ocrResponse': ocrResponse
}
priceResult = match_price(priceRequest)
print(priceResult)
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/sky_32/qianniu.git
git@gitee.com:sky_32/qianniu.git
sky_32
qianniu
qianniu
master

搜索帮助