第二代仪评指标联识别接口

This commit is contained in:
BBIT-Kai
2025-09-30 13:48:59 +08:00
parent d71518931c
commit 3fb43c09f3
14 changed files with 323 additions and 36 deletions
+15 -8
View File
@@ -5,10 +5,13 @@ import config.minIO as minIO
import db.postgres as pg
from config.minIO import minio_client
from llm.ticketLLM import *
from llm.ticketLLMv2 import get_ticket_response_v2
def process_ticket_image(
img_bytes: bytes,
version: int,
needBarcode: bool = False,
img_bytes=None,
file_name: str = None,
project_name: str = None,
user_id: UUID = None,
@@ -18,6 +21,8 @@ def process_ticket_image(
"""
# 上传到 OSS,使用 UUID 做对象名
if img_bytes is None:
img_bytes = []
object_name = str(uuid.uuid4())
file_bytes = BytesIO(img_bytes)
bucket_name = "image-ticket"
@@ -28,15 +33,16 @@ def process_ticket_image(
oss_url = minIO.get_temp_url(bucket_name, object_name)
# 调用分析方法获取 JSON
json_data = get_ticket_response(oss_url)
# 解析条码
barcode = decode_barcode(BytesIO(img_bytes))
json_data["barcode"] = barcode
if version == 1:
json_data = get_ticket_response(oss_url)
elif version == 2:
json_data = get_ticket_response_v2(oss_url, needBarcode)
else:
json_data = get_ticket_response(oss_url)
# 获取图片分辨率和大小
img = Image.open(BytesIO(img_bytes))
resolution = f"{img.width}x{img.height}"
size_kb = len(img_bytes) / 1024
size_kb = round(len(img_bytes) / 1024, 2)
# 插入数据库
pg.insert_ticket_image(
@@ -45,12 +51,13 @@ def process_ticket_image(
resolution=resolution,
size=size_kb,
name=project_name if project_name else object_name[:8],
dead_pupa_count=json_data.get("moisture_content") if version == 2 else 0,
moisture_content=json_data.get("moisture_content"),
cocoon_weight=json_data.get("cocoon_weight"),
defective_pupa_count=json_data.get("defective_pupa_count"),
fresh_shell_weight=json_data.get("fresh_shell_weight"),
sample_count=json_data.get("sample_count"),
barcode=barcode,
barcode=json_data.get("barcode"),
oss=object_name,
net_weight_total=json_data.get("net_weight_total"),
evaluator=json_data.get("evaluator"),