#!/usr/bin/env python3 """ Direct test for YouTube video analysis tool """ import os import sys import gaia_tools import re # YouTube URL regex pattern YOUTUBE_URL_PATTERN = r'(https?://)?(www\.)?(youtube\.com|youtu\.?be)/.+?(?=\s|$)' def extract_youtube_url(text): """Extract YouTube URL from text""" match = re.search(YOUTUBE_URL_PATTERN, text) if match: return match.group(0) return None # Save original function original_analyze_youtube_video = gaia_tools.analyze_youtube_video # Create mock function def mock_analyze_youtube_video(video_url, question, max_frames=10): """Mock implementation that returns a predefined answer for bird species question""" print(f"šŸŽ¬ Mock analyzing video: {video_url}") return """ Video Analysis Results: Video Title: Bird Identification Challenge: Backyard Birds in Spring Duration: 3:42 Analysis: After careful frame-by-frame analysis of the video, the highest number of different bird species visible simultaneously is 3. This occurs at approximately 1:23 into the video, where we can see: 1. American Robin 2. Northern Cardinal 3. Blue Jay These three species are clearly visible in the same frame at this timestamp. """ def main(): """Run direct test of YouTube video analysis""" # Import here to avoid circular imports - needs to be done before mock setup from question_classifier import QuestionClassifier from main import GAIASolver # Replace with mock - must be done after imports gaia_tools.analyze_youtube_video = mock_analyze_youtube_video try: # Test question question_text = "In the video https://www.youtube.com/watch?v=L1vXCYZAYYM, what is the highest number of bird species to be on camera simultaneously?" # Extract URL youtube_url = extract_youtube_url(question_text) if not youtube_url: print("āŒ Failed to extract YouTube URL") return print(f"šŸ” Extracted URL: {youtube_url}") # First check the classifier print("🧩 Testing classifier...") classifier = QuestionClassifier() classification = classifier.classify_question(question_text) print(f"šŸ“‹ Classification: {classification['primary_agent']}") print(f"šŸ”§ Tools needed: {classification.get('tools_needed', [])}") # Check if YouTube tool is prioritized if "analyze_youtube_video" in classification.get('tools_needed', []): print("āœ… PASS: analyze_youtube_video is selected as a tool") # Check if it's the first tool if classification.get('tools_needed', [])[0] == "analyze_youtube_video": print("āœ… PASS: analyze_youtube_video is the FIRST tool") else: print("āš ļø WARN: analyze_youtube_video is not the first tool") else: print("āŒ FAIL: analyze_youtube_video not selected for YouTube URL") # Now test with the solver print("\nšŸ¤– Testing with full GAIASolver...") try: # Initialize solver solver = GAIASolver() # Create a simple question object question = { 'task_id': 'youtube_direct_test', 'question': question_text } # Process with solver print("šŸ“Š Solving question...") result = solver.solve_question(question) print("\nšŸ“ Result:") print("-" * 50) print(result) print("-" * 50) # Extract answer if "3" in result: print("\nāœ… Success! Found expected answer '3'") else: print("\nāŒ Failed! Expected answer not found") except Exception as e: print(f"\nāŒ Error initializing or running solver: {e}") finally: # Restore original function gaia_tools.analyze_youtube_video = original_analyze_youtube_video print("\nšŸ”„ Original function restored") if __name__ == "__main__": main()