This commit is contained in:
HuangHai
2026-01-13 21:58:42 +08:00
parent 46f17aed11
commit e25aa5b756
11 changed files with 309 additions and 34 deletions

View File

@@ -50,13 +50,52 @@ class ReadImageKit:
"""
try:
res_text = await self.vlm.analyze_image(image_path, prompt)
# 强制写入文件调试
# debug_file = r"d:\dsWork\aiData\vlm_response_debug.txt"
# with open(debug_file, "a", encoding="utf-8") as f:
# f.write(f"\n\n=== {os.path.basename(image_path)} ===\n")
# f.write(str(res_text))
# f.write("\n====================================\n")
# 增加调试日志,查看 VLM 原始返回
logger.info(f"VLM Price Analysis Result for {os.path.basename(image_path)}: {res_text[:200]}...")
json_str = self.vlm.extract_json(res_text)
prices = json.loads(json_str)
# 兼容性处理:如果 VLM 返回了 time_range 字段,进行转换
normalized_prices = []
if isinstance(prices, list):
return prices
for p in prices:
new_p = p.copy()
# 处理时间段
if 'time_range' in p and ('start' not in p or 'end' not in p):
tr = p['time_range'].replace('~', '-').replace(' ', '')
parts = tr.split('-')
if len(parts) >= 2:
new_p['start'] = parts[0]
new_p['end'] = parts[1]
# 处理价格字段
if 'price' not in p:
if 'total_price' in p:
new_p['price'] = p['total_price']
elif 'elec_price' in p and 'service_price' in p:
try:
new_p['price'] = float(p['elec_price']) + float(p['service_price'])
except:
pass
normalized_prices.append(new_p)
return normalized_prices
return []
except Exception as e:
logger.error(f"分析电价详情失败: {e}")
if 'res_text' in locals():
logger.error(f"Failed VLM Response: {res_text}")
return []
@classmethod
@@ -157,26 +196,3 @@ class ReadImageKit:
except Exception as e:
logger.error(f"Hybrid 分析列表页失败: {e}")
return []
async def analyze_detail_price(self, image_path):
"""
分析详情页或三级价格页图片,提取分时电价
"""
prompt = """
分析这张充电站价格详情截图,提取完整的分时价格信息。
输出格式为 JSON 数组,每个对象包含:
- "time_range": 时间段 (例如 "00:00-08:00")
- "total_price": 总价 (电费+服务费)
- "elec_price": 电费 (如果能看到)
- "service_price": 服务费 (如果能看到)
如果没有看到分时段价格,请尝试寻找“价格详情”或“分时电价”按钮的坐标。
"""
try:
res_text = await self.vlm.analyze_image(image_path, prompt)
json_str = self.vlm.extract_json(res_text)
return json.loads(json_str)
except Exception as e:
logger.error(f"VLM 分析价格页失败: {e}")
return []