43 lines
1.4 KiB
Python
43 lines
1.4 KiB
Python
import json
|
|
from newsetting import All_Setting
|
|
import requests
|
|
from io import BytesIO
|
|
from concurrent.futures import ThreadPoolExecutor, as_completed
|
|
import json
|
|
tent2 = All_Setting(host='183.6.7.91', port=33016, db='tk_test')
|
|
def ocr_1(img_url):
|
|
import requests
|
|
from io import BytesIO
|
|
url = "http://192.168.5.2:9002/infer"
|
|
# img_url = 'https://p0.meituan.net/mallimages/04e59006293302d0808a5e9bff01d17a79341.png'
|
|
img_response = requests.get(img_url, timeout=10)
|
|
img_response.raise_for_status()
|
|
img_file = BytesIO(img_response.content)
|
|
files = {"file": ("your.jpg", img_file, "image/jpeg")}
|
|
r = requests.post(url, files=files, timeout=60)
|
|
return r.json()['full_text']
|
|
sql3 = f"SELECT show_contents FROM product_data"
|
|
result = tent2.get_shoppingmalls(sql3)
|
|
li = []
|
|
print("返回类型:", type(result))
|
|
for i in result:
|
|
da23 = i[0]
|
|
print(da23)
|
|
da = eval(da23)
|
|
for d in da:
|
|
if d not in li:
|
|
li.append(d)
|
|
print(len(li))
|
|
print(li)
|
|
all1={}
|
|
max_threads = 5
|
|
with ThreadPoolExecutor(max_workers=max_threads) as executor:
|
|
future_to_url = {executor.submit(ocr_1, url): url for url in li}
|
|
for future in as_completed(future_to_url):
|
|
url, result = future.result()
|
|
if result is not None:
|
|
all1[url] = result
|
|
print(all1)
|
|
with open('a11.json','w',encoding='utf-8') as f:
|
|
json.dump(all1, f, ensure_ascii=False, indent=4)
|