31d1b4050f
- Changed min_confidence from 50.0 to 0.5 (Vision uses 0.0-1.0 range) - Changed min_size from 32 to 1 (was filtering out all small faces) - Changed min_capture_quality from 25.0 to 0.25 - Fixes issue where all videos showed 0 faces detected Root cause: admin_config.rs used wrong defaults (50.0/32) instead of config.rs constants (0.5/1), causing Vision framework to filter out ALL faces because confidence threshold exceeded valid range. Verified: IMG_9449 now correctly detects 191 faces (was 0).
129 lines
4.3 KiB
Python
129 lines
4.3 KiB
Python
#!/opt/homebrew/bin/python3.11
|
|
"""
|
|
Admin Config Loader for Python Scripts
|
|
|
|
Loads configuration from config/admin_config.json
|
|
"""
|
|
|
|
import json
|
|
from pathlib import Path
|
|
from typing import Optional, Dict, Any
|
|
import os
|
|
|
|
class AdminConfigManager:
|
|
_instance = None
|
|
_config = None
|
|
|
|
@classmethod
|
|
def get_instance(cls):
|
|
if cls._instance is None:
|
|
cls._instance = cls()
|
|
return cls._instance
|
|
|
|
def __init__(self):
|
|
config_path = os.environ.get(
|
|
"MOMENTRY_ADMIN_CONFIG_PATH",
|
|
str(Path(__file__).parent.parent / "config" / "admin_config.json")
|
|
)
|
|
self._config = self._load_config(config_path)
|
|
|
|
def _load_config(self, config_path: str) -> Dict[str, Any]:
|
|
if not Path(config_path).exists():
|
|
raise FileNotFoundError(f"Config file not found: {config_path}")
|
|
|
|
with open(config_path, 'r') as f:
|
|
return json.load(f)
|
|
|
|
def get_vlm_prompt(self, key: str) -> Optional[Dict[str, Any]]:
|
|
"""Get VLM prompt by key"""
|
|
prompts = self._config.get('vlm_prompts', {})
|
|
return prompts.get(key)
|
|
|
|
def get_prompt_text(self, key: str) -> Optional[str]:
|
|
"""Get prompt text by key"""
|
|
prompt_data = self.get_vlm_prompt(key)
|
|
if not prompt_data:
|
|
return None
|
|
return prompt_data.get('prompt') or prompt_data.get('system_prompt')
|
|
|
|
def get_max_tokens(self, key: str) -> int:
|
|
"""Get max tokens for prompt"""
|
|
prompt_data = self.get_vlm_prompt(key)
|
|
return prompt_data.get('max_tokens', 100) if prompt_data else 100
|
|
|
|
def get_llm_config(self, key: str) -> Optional[Dict[str, Any]]:
|
|
"""Get LLM config by key"""
|
|
return self._config.get('llm_config', {}).get(key)
|
|
|
|
def get_processor_config(self, key: str) -> Optional[Dict[str, Any]]:
|
|
"""Get processor config by key"""
|
|
return self._config.get('processor_config', {}).get(key)
|
|
|
|
def get_system_config(self) -> Dict[str, Any]:
|
|
"""Get system config"""
|
|
return self._config.get('system_config', {})
|
|
|
|
def get_all_vlm_prompts(self) -> Dict[str, Any]:
|
|
"""Get all VLM prompts"""
|
|
return self._config.get('vlm_prompts', {})
|
|
|
|
def reload(self):
|
|
"""Reload config from file"""
|
|
config_path = os.environ.get(
|
|
"MOMENTRY_ADMIN_CONFIG_PATH",
|
|
str(Path(__file__).parent.parent / "config" / "admin_config.json")
|
|
)
|
|
self._config = self._load_config(config_path)
|
|
|
|
# Convenience functions
|
|
def get_vlm_prompt(key: str) -> Optional[Dict[str, Any]]:
|
|
"""Get VLM prompt by key"""
|
|
return AdminConfigManager.get_instance().get_vlm_prompt(key)
|
|
|
|
def get_prompt_text(key: str) -> Optional[str]:
|
|
"""Get prompt text by key"""
|
|
return AdminConfigManager.get_instance().get_prompt_text(key)
|
|
|
|
def get_max_tokens(key: str) -> int:
|
|
"""Get max tokens for prompt"""
|
|
return AdminConfigManager.get_instance().get_max_tokens(key)
|
|
|
|
def get_llm_config(key: str) -> Optional[Dict[str, Any]]:
|
|
"""Get LLM config by key"""
|
|
return AdminConfigManager.get_instance().get_llm_config(key)
|
|
|
|
def get_processor_config(key: str) -> Optional[Dict[str, Any]]:
|
|
"""Get processor config by key"""
|
|
return AdminConfigManager.get_instance().get_processor_config(key)
|
|
|
|
def get_system_config() -> Dict[str, Any]:
|
|
"""Get system config"""
|
|
return AdminConfigManager.get_instance().get_system_config()
|
|
|
|
def get_all_vlm_prompts() -> Dict[str, Any]:
|
|
"""Get all VLM prompts"""
|
|
return AdminConfigManager.get_instance().get_all_vlm_prompts()
|
|
|
|
if __name__ == "__main__":
|
|
# Test
|
|
print("Testing Admin Config Loader...")
|
|
|
|
manager = AdminConfigManager.get_instance()
|
|
|
|
print("\n1. Testing VLM prompts:")
|
|
for key in ["rust_vlm_summary", "trace_desc", "scene_desc"]:
|
|
prompt = manager.get_vlm_prompt(key)
|
|
if prompt:
|
|
print(f" {key}: {prompt.get('description', 'N/A')}")
|
|
|
|
print("\n2. Testing LLM config:")
|
|
for key in ["chat", "vision", "embedding"]:
|
|
config = manager.get_llm_config(key)
|
|
if config:
|
|
print(f" {key}: {config.get('model', 'N/A')}")
|
|
|
|
print("\n3. Testing system config:")
|
|
sys_config = manager.get_system_config()
|
|
print(f" Output dir: {sys_config.get('output_dir', 'N/A')}")
|
|
|
|
print("\n✅ Admin Config Loader test passed") |