1234567891011121314151617181920212223242526272829 |
- # -*- coding: utf-8 -*-
- """
- Created on 2024-11-01
- ---------
- @summary:
- ---------
- @author: Dzr
- """
- from base64 import b64encode
- import requests
- def file_extract(path):
- b64_str = b64encode(path.read_bytes()).decode('utf8')
- data = {"input": {"image": b64_str}}
- url = 'http://1228910937799386.cn-hangzhou.pai-eas.aliyuncs.com/api/predict/ms_eas_c38f0a8d_f314_463b_875d_581a/invoke'
- headers = {
- 'Content-Type': 'application/json',
- 'Authorization': 'ZDljNTk5ZTU3M2U3NzQzOGI5NzJhY2Y2OTI1M2I0NWI5NmVhZjljZA=='
- }
- # print(b64_str)
- # data = {"input":{"image":"http://modelscope.oss-cn-beijing.aliyuncs.com/demo/images/image_ocr_recognition.jpg"}}
- response = requests.post(url, headers=headers, json=data, timeout=10)
- r_json = response.json()
- print(r_json)
- return r_json['Data']['text'][0] if r_json and 'Data' in r_json else ''
|