Files
tw/image/image_precheck.py
ZuoWei a6c42d505a feat: 完整功能部署 v1.0
新增功能:
- 天网协作系统 (HTTP API 端口 6060)
- 三种工作流 (查找图片/处理图片/转人工派单)
- 图片任务数据库 (支持客户后续增加需求)
- 图绘派单系统集成 (API: 8005)
- 文字检测与加价 (60-80 元高价值订单)
- 风险评估与接单判断
- 作图失败自动转人工

新增文档:
- 项目功能汇总.md
- 三种工作流功能说明.md
- 文字加价功能说明.md
- 风险评估功能说明.md
- 图片任务数据库功能说明.md
- 图绘派单系统集成说明.md
- 作图失败转接人工说明.md
- DEPLOYMENT.md
- TIANWANG_INTEGRATION.md

核心修改:
- core/pydantic_ai_agent.py
- core/workflow.py
- core/websocket_client.py
- image/image_analyzer.py
- services/service_tuhui_dispatch.py
- db/image_tasks_db.py

版本:v1.0
日期:2026-02-28
2026-02-28 11:20:40 +08:00

48 lines
1.8 KiB
Python
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# -*- coding: utf-8 -*-
"""
图片预检 - 下载后检查尺寸/格式/是否损坏,不合格直接拒单
"""
import os
import logging
from typing import Tuple
logger = logging.getLogger(__name__)
# 可配置
MIN_WIDTH = int(os.getenv("IMAGE_PRECHECK_MIN_WIDTH", "50"))
MIN_HEIGHT = int(os.getenv("IMAGE_PRECHECK_MIN_HEIGHT", "50"))
MAX_WIDTH = int(os.getenv("IMAGE_PRECHECK_MAX_WIDTH", "8000"))
MAX_HEIGHT = int(os.getenv("IMAGE_PRECHECK_MAX_HEIGHT", "8000"))
MIN_SIZE = int(os.getenv("IMAGE_PRECHECK_MIN_BYTES", "100")) # 至少 100 字节
MAX_SIZE = int(os.getenv("IMAGE_PRECHECK_MAX_BYTES", "0")) # 0=不限制
SUPPORTED_FORMATS = (".jpg", ".jpeg", ".png", ".gif", ".webp", ".bmp")
def precheck(local_path: str) -> Tuple[bool, str]:
"""
预检图片文件。
Returns:
(ok, message) - ok=False 时 message 为拒单原因
"""
if not os.path.exists(local_path):
return False, "图片文件不存在"
size = os.path.getsize(local_path)
if size < MIN_SIZE:
return False, f"图片太小({size} 字节),可能损坏或格式异常"
if MAX_SIZE > 0 and size > MAX_SIZE:
return False, f"图片过大({size/1024/1024:.1f}MB超过 {MAX_SIZE/1024/1024:.0f}MB 限制"
try:
from PIL import Image
with Image.open(local_path) as img:
w, h = img.size
if w < MIN_WIDTH or h < MIN_HEIGHT:
return False, f"图片尺寸过小({w}x{h}),最小 {MIN_WIDTH}x{MIN_HEIGHT}"
if w > MAX_WIDTH or h > MAX_HEIGHT:
return False, f"图片尺寸过大({w}x{h}),最大 {MAX_WIDTH}x{MAX_HEIGHT}"
img.verify()
except Exception as e:
return False, f"图片无法读取或已损坏:{str(e)[:50]}"
return True, ""