init xiaoxiang project
This commit is contained in:
+54
@@ -0,0 +1,54 @@
|
||||
import json
|
||||
from newsetting import All_Setting
|
||||
import requests
|
||||
from io import BytesIO
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
|
||||
tent2 = All_Setting(host="183.6.7.91", port=33016, db="tk_test")
|
||||
|
||||
|
||||
def ocr_1(img_url):
|
||||
url = "http://192.168.5.2:9002/infer"
|
||||
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 img_url, r.json()["full_text"]
|
||||
|
||||
|
||||
sql3 = "SELECT show_contents FROM product_data"
|
||||
result = tent2.get_shoppingmalls(sql3)
|
||||
li = []
|
||||
print("返回类型:", type(result))
|
||||
for i in result:
|
||||
da23 = i[0]
|
||||
try:
|
||||
da = json.loads(da23)
|
||||
except Exception:
|
||||
da = eval(da23)
|
||||
for d in da:
|
||||
if d not in li:
|
||||
li.append(d)
|
||||
|
||||
print(f"共 {len(li)} 个 URL,开始 OCR...")
|
||||
|
||||
all1 = {}
|
||||
max_threads = 20
|
||||
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):
|
||||
try:
|
||||
url, text = future.result()
|
||||
if text is not None:
|
||||
all1[url] = text
|
||||
print(f"[done] {url}")
|
||||
except Exception as e:
|
||||
print(f"[error] {future_to_url[future]}: {e}")
|
||||
|
||||
print(f"\n共处理 {len(all1)} 条结果")
|
||||
|
||||
with open("a11.json", "w", encoding="utf-8") as f:
|
||||
json.dump(all1, f, ensure_ascii=False, indent=4)
|
||||
|
||||
print("已写入 a11.json")
|
||||
Reference in New Issue
Block a user