feat: add simulator page and image quote analyzer
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:
@@ -67,6 +67,13 @@ class GeminiExtractV2Service:
|
||||
# DEFAULT_PROMPT = "生成图片,把衣服的图案展开起来做成数码印花印刷平面图。去掉皱褶,生成图案增强细节。排除衣服图案以外内容"
|
||||
def __init__(self):
|
||||
self.session = None
|
||||
|
||||
@staticmethod
|
||||
def _clip_text(text: str, limit: int = 120) -> str:
|
||||
if not text:
|
||||
return ""
|
||||
compact = re.sub(r"\s+", " ", str(text)).strip()
|
||||
return compact if len(compact) <= limit else f"{compact[:limit]}..."
|
||||
|
||||
def image_to_base64(self, image_path: str) -> str:
|
||||
"""将图片文件转换为base64编码字符串"""
|
||||
@@ -108,6 +115,12 @@ class GeminiExtractV2Service:
|
||||
|
||||
# 使用自定义提示词或默认提示词
|
||||
prompt = custom_prompt or self.DEFAULT_PROMPT
|
||||
logger.info(
|
||||
"图片识别任务开始: 输入=%s 输出=%s 提示词=%s",
|
||||
input_path,
|
||||
output_path,
|
||||
self._clip_text(prompt, 100),
|
||||
)
|
||||
|
||||
# 按优先级逐个尝试API配置
|
||||
for config_index, config in enumerate(self.API_CONFIGS):
|
||||
@@ -117,6 +130,12 @@ class GeminiExtractV2Service:
|
||||
for attempt in range(config['max_retries']):
|
||||
try:
|
||||
logger.info(f"开始Gemini V2印花提取 - {config['name']} (第{attempt + 1}/{config['max_retries']}次尝试): {input_path}")
|
||||
logger.info(
|
||||
"%s 模型参数: model=%s aspect_ratio=%s",
|
||||
config["name"],
|
||||
config["api_model"],
|
||||
aspect_ratio,
|
||||
)
|
||||
|
||||
# 准备请求数据和URL
|
||||
if config.get('use_gemini_format', False):
|
||||
@@ -271,7 +290,15 @@ class GeminiExtractV2Service:
|
||||
# 根据API格式提取内容
|
||||
if config.get('use_gemini_format', False):
|
||||
# Gemini原生API格式: candidates[0].content.parts[0]
|
||||
content_parts = result['candidates'][0]['content']['parts']
|
||||
candidates = result.get("candidates", [])
|
||||
logger.info("%s 返回候选数量: %s", api_name, len(candidates))
|
||||
if not candidates:
|
||||
logger.error("%s 响应缺少candidates", api_name)
|
||||
return False, "响应缺少candidates", {}
|
||||
finish_reason = candidates[0].get("finishReason", "")
|
||||
if finish_reason:
|
||||
logger.info("%s 返回结束原因: %s", api_name, finish_reason)
|
||||
content_parts = candidates[0]['content']['parts']
|
||||
|
||||
# 查找包含图片数据的part
|
||||
image_data = None
|
||||
@@ -287,6 +314,8 @@ class GeminiExtractV2Service:
|
||||
except Exception as e:
|
||||
logger.error(f"{api_name} Base64解码失败: {e}")
|
||||
return False, f"Base64解码失败: {e}", {}
|
||||
elif "text" in part:
|
||||
logger.info("%s 模型文本输出: %s", api_name, self._clip_text(part.get("text", ""), 160))
|
||||
|
||||
if not image_data:
|
||||
logger.error(f"{api_name} 在Gemini响应中未找到图片数据")
|
||||
|
||||
Reference in New Issue
Block a user