feat: localize logs, colorize streams, and fix draw pipeline params
Some checks failed
Pre-commit / run (ubuntu-latest) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_en (ubuntu-latest, 3.10) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_zh (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.12) (push) Has been cancelled
Some checks failed
Pre-commit / run (ubuntu-latest) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_en (ubuntu-latest, 3.10) (push) Has been cancelled
Deploy Sphinx documentation to Pages / build_zh (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (macos-15, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (ubuntu-latest, 3.12) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.10) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.11) (push) Has been cancelled
Python Unittest Coverage / test (windows-latest, 3.12) (push) Has been cancelled
This commit is contained in:
@@ -6,9 +6,12 @@ import uuid
|
||||
from typing import Any
|
||||
|
||||
import requests
|
||||
from .logger import setup_logger
|
||||
|
||||
from .config import AUTO_DRAW_TIMEOUT_SECONDS
|
||||
|
||||
logger = setup_logger()
|
||||
|
||||
|
||||
async def auto_draw_preview(
|
||||
image_url: str,
|
||||
@@ -22,16 +25,19 @@ async def auto_draw_preview(
|
||||
3) 上传图绘,返回可外发 URL
|
||||
"""
|
||||
try:
|
||||
logger.info("[作图] 开始 customer=%s image=%s", customer_id, image_url)
|
||||
from services.service_gemini import GeminiExtractV2Service # type: ignore
|
||||
from services.service_tuhui_upload import upload_to_tuhui # type: ignore
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": f"import_failed:{e}"}
|
||||
logger.error("[作图] 依赖加载失败: %s", e)
|
||||
return {"ok": False, "error": f"依赖加载失败:{e}"}
|
||||
|
||||
prompt = requirement.strip() or "按原图做高清修复,保留主体细节,输出清晰可用版本"
|
||||
input_path = os.path.join(tempfile.gettempdir(), f"qjcs_in_{uuid.uuid4().hex}.jpg")
|
||||
output_path = os.path.join(tempfile.gettempdir(), f"qjcs_out_{uuid.uuid4().hex}.jpg")
|
||||
|
||||
try:
|
||||
logger.info("[作图] 下载原图中")
|
||||
headers = {
|
||||
"User-Agent": (
|
||||
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) "
|
||||
@@ -43,10 +49,13 @@ async def auto_draw_preview(
|
||||
}
|
||||
resp = requests.get(image_url, headers=headers, timeout=AUTO_DRAW_TIMEOUT_SECONDS)
|
||||
if resp.status_code != 200:
|
||||
return {"ok": False, "error": f"download_http_{resp.status_code}"}
|
||||
logger.error("[作图] 原图下载失败: http_%s", resp.status_code)
|
||||
return {"ok": False, "error": f"原图下载失败:http_{resp.status_code}"}
|
||||
with open(input_path, "wb") as f:
|
||||
f.write(resp.content)
|
||||
logger.info("[作图] 原图下载完成 size=%s", len(resp.content))
|
||||
|
||||
logger.info("[作图] Gemini 生成中")
|
||||
service = GeminiExtractV2Service()
|
||||
ok_extract, msg_extract, _ = await service.extract_pattern(
|
||||
input_path=input_path,
|
||||
@@ -55,10 +64,14 @@ async def auto_draw_preview(
|
||||
aspect_ratio="1:1",
|
||||
)
|
||||
if not ok_extract:
|
||||
return {"ok": False, "error": f"extract_failed:{msg_extract}"}
|
||||
logger.error("[作图] Gemini 生成失败: %s", msg_extract)
|
||||
return {"ok": False, "error": f"生成失败:{msg_extract}"}
|
||||
if not os.path.exists(output_path):
|
||||
return {"ok": False, "error": "extract_no_output_file"}
|
||||
logger.error("[作图] Gemini 未产出文件")
|
||||
return {"ok": False, "error": "生成失败:未产出文件"}
|
||||
logger.info("[作图] Gemini 生成完成")
|
||||
|
||||
logger.info("[作图] 上传图绘中")
|
||||
ok_upload, link, _ = await upload_to_tuhui(
|
||||
output_path,
|
||||
title=f"客户{customer_id[-4:]}-预览图" if customer_id else "预览图",
|
||||
@@ -66,10 +79,13 @@ async def auto_draw_preview(
|
||||
price=1,
|
||||
)
|
||||
if not ok_upload:
|
||||
return {"ok": False, "error": f"upload_failed:{link}"}
|
||||
logger.error("[作图] 图绘上传失败: %s", link)
|
||||
return {"ok": False, "error": f"上传失败:{link}"}
|
||||
logger.info("[作图] 上传成功 url=%s", link)
|
||||
return {"ok": True, "url": str(link)}
|
||||
except Exception as e:
|
||||
return {"ok": False, "error": str(e)}
|
||||
logger.exception("[作图] 异常")
|
||||
return {"ok": False, "error": f"作图异常:{e}"}
|
||||
finally:
|
||||
try:
|
||||
if os.path.exists(input_path):
|
||||
|
||||
Reference in New Issue
Block a user