新增证件识别接口
This commit is contained in:
@@ -3,6 +3,7 @@ from uuid import UUID
|
||||
|
||||
import config.minIO as minIO
|
||||
import db.postgres as pg
|
||||
from agent.licenseImageAgent import get_license_response
|
||||
from config.minIO import minio_client
|
||||
from llm.ticketLLM import *
|
||||
from llm.ticketLLMv2 import get_ticket_response_v2
|
||||
@@ -65,3 +66,43 @@ def process_ticket_image(
|
||||
)
|
||||
|
||||
return json_data
|
||||
|
||||
|
||||
def process_license_image(
|
||||
img_bytes=None,
|
||||
file_name: str = None,
|
||||
project_name: str = None,
|
||||
user_id: UUID = None,
|
||||
):
|
||||
# 上传到 OSS,使用 UUID 做对象名
|
||||
if img_bytes is None:
|
||||
img_bytes = []
|
||||
object_name = str(uuid.uuid4())
|
||||
file_bytes = BytesIO(img_bytes)
|
||||
bucket_name = "image-license"
|
||||
if not minio_client.bucket_exists(bucket_name):
|
||||
minio_client.make_bucket(bucket_name)
|
||||
|
||||
minIO.push_file(bucket_name, object_name, file_bytes, img_bytes, "image/jpeg")
|
||||
oss_url = minIO.get_temp_url(bucket_name, object_name)
|
||||
|
||||
# 调用分析方法获取 JSON
|
||||
json_data = get_license_response(oss_url)
|
||||
# 获取图片分辨率和大小
|
||||
img = Image.open(BytesIO(img_bytes))
|
||||
resolution = f"{img.width}x{img.height}"
|
||||
size_kb = round(len(img_bytes) / 1024, 2)
|
||||
|
||||
# 插入数据库
|
||||
pg.insert_license_image(
|
||||
created_by=user_id,
|
||||
file_name=file_name,
|
||||
resolution=resolution,
|
||||
size=size_kb,
|
||||
name=project_name if project_name else object_name[:8],
|
||||
oss=object_name,
|
||||
type=json_data.get("type"),
|
||||
content=json_data.get("content"),
|
||||
)
|
||||
|
||||
return json_data
|
||||
|
||||
Reference in New Issue
Block a user