Spaces:
Running
Running
File size: 4,222 Bytes
37cadfb |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
#!/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()
|