Spaces:
Runtime error
Runtime error
| import sys | |
| from pathlib import Path | |
| from rich.console import Console | |
| from rich.prompt import Prompt | |
| from src.perception.engine import Qwen2PerceptionEngine | |
| from src.memory.manager import SimpleMemoryManager | |
| from src.core.orchestrator import VideoAgent | |
| from src.config.settings import settings | |
| console = Console() | |
| def main(): | |
| console.rule("[bold blue]Agentic Video Understanding System[/]") | |
| # 1. Initialize Components | |
| with console.status("[bold green]Loading AI Models... (This uses GPU)[/]"): | |
| perception = Qwen2PerceptionEngine() | |
| # Pre-load to avoid delay on first query | |
| try: | |
| perception.load_model(settings.paths.model_path) | |
| except Exception as e: | |
| console.print(f"[bold red]Critical Error:[/] Failed to load Qwen2-VL. {e}") | |
| console.print("Ensure you ran 'python scripts/download_model.py'") | |
| sys.exit(1) | |
| memory = SimpleMemoryManager(storage_dir=settings.paths.data_dir / "metadata") | |
| agent = VideoAgent(perception, memory) | |
| # 2. Select Video | |
| video_id = "test_video" | |
| video_path = settings.paths.data_dir / f"{video_id}.mp4" | |
| if not video_path.exists(): | |
| console.print(f"[yellow]Warning:[/] Video {video_path} not found.") | |
| console.print("Please place a video at data/test_video.mp4") | |
| return | |
| # 3. Initialize Memory for this video | |
| memory.initialize_storage(video_id) | |
| console.print(f"[green]Video Loaded:[/] {video_id}.mp4") | |
| # 4. Interactive Loop | |
| while True: | |
| console.print() | |
| query = Prompt.ask("[bold cyan]Ask a question[/] (or 'exit')") | |
| if query.lower() in ["exit", "quit", "q"]: | |
| break | |
| with console.status("[bold yellow]Agent Thinking...[/]"): | |
| try: | |
| response = agent.ask(query, video_id) | |
| console.print(f"[bold white]Answer:[/] {response}") | |
| except Exception as e: | |
| console.print(f"[bold red]Error:[/] {e}") | |
| if __name__ == "__main__": | |
| main() | |