fix: 添加分析错误处理和调试输出
This commit is contained in:
14
analyzer.py
14
analyzer.py
@@ -34,6 +34,17 @@ class ImageAnalyzer:
|
|||||||
self.api_key = config_mgr.get('vision_api_key')
|
self.api_key = config_mgr.get('vision_api_key')
|
||||||
self.model = config_mgr.get('vision_model')
|
self.model = config_mgr.get('vision_model')
|
||||||
|
|
||||||
|
# 检查配置
|
||||||
|
if not self.api_url:
|
||||||
|
return {'success': False, 'error': 'Vision API URL 未配置'}
|
||||||
|
if not self.api_key:
|
||||||
|
return {'success': False, 'error': 'Vision API Key 未配置'}
|
||||||
|
if not self.model:
|
||||||
|
return {'success': False, 'error': 'Vision Model 未配置'}
|
||||||
|
|
||||||
|
print(f"[Analyzer] Analyzing: {image_path}")
|
||||||
|
print(f"[Analyzer] API: {self.api_url}, Model: {self.model}")
|
||||||
|
|
||||||
# 编码图片
|
# 编码图片
|
||||||
image_base64 = self.encode_image(image_path)
|
image_base64 = self.encode_image(image_path)
|
||||||
|
|
||||||
@@ -73,7 +84,10 @@ class ImageAnalyzer:
|
|||||||
timeout=30
|
timeout=30
|
||||||
)
|
)
|
||||||
|
|
||||||
|
print(f"[Analyzer] Response status: {response.status_code}")
|
||||||
|
|
||||||
if response.status_code != 200:
|
if response.status_code != 200:
|
||||||
|
print(f"[Analyzer] Error response: {response.text}")
|
||||||
return {
|
return {
|
||||||
'success': False,
|
'success': False,
|
||||||
'error': f"API 错误: {response.status_code} - {response.text}"
|
'error': f"API 错误: {response.status_code} - {response.text}"
|
||||||
|
|||||||
39
scheduler.py
39
scheduler.py
@@ -152,24 +152,27 @@ class VisionScheduler:
|
|||||||
|
|
||||||
def analyze_now(self, image_id):
|
def analyze_now(self, image_id):
|
||||||
"""立即分析指定图片"""
|
"""立即分析指定图片"""
|
||||||
image = db.get_image_by_id(image_id)
|
try:
|
||||||
if not image:
|
image = db.get_image_by_id(image_id)
|
||||||
return {'success': False, 'error': '图片不存在'}
|
if not image:
|
||||||
|
return {'success': False, 'error': '图片不存在'}
|
||||||
result = self.analyzer.analyze(image['path'])
|
|
||||||
|
result = self.analyzer.analyze(image['path'])
|
||||||
if result['success']:
|
|
||||||
for event in result['events']:
|
if result['success']:
|
||||||
db.add_event(
|
for event in result['events']:
|
||||||
image_id,
|
db.add_event(
|
||||||
event['event_type'],
|
image_id,
|
||||||
event['description'],
|
event['event_type'],
|
||||||
event['confidence']
|
event['description'],
|
||||||
)
|
event['confidence']
|
||||||
db.mark_image_analyzed(image_id)
|
)
|
||||||
self.last_analyze_time = datetime.datetime.now().isoformat()
|
db.mark_image_analyzed(image_id)
|
||||||
|
self.last_analyze_time = datetime.datetime.now().isoformat()
|
||||||
return result
|
|
||||||
|
return result
|
||||||
|
except Exception as e:
|
||||||
|
return {'success': False, 'error': str(e)}
|
||||||
|
|
||||||
def analyze_unanalyzed(self):
|
def analyze_unanalyzed(self):
|
||||||
"""分析所有未分析的图片"""
|
"""分析所有未分析的图片"""
|
||||||
|
|||||||
Reference in New Issue
Block a user