Spaces:
Sleeping
Sleeping
| #!/usr/bin/env python3 | |
| """ | |
| Simple test for YouTube video analysis mocking | |
| This script directly tests the YouTube video analysis functionality | |
| using a mock function to avoid actual YouTube access | |
| """ | |
| import gaia_tools | |
| # Store the original function for restoration | |
| original_analyze_youtube_video = gaia_tools.analyze_youtube_video | |
| # Create a mock function that returns a predefined answer | |
| 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 YouTube video: {video_url}") | |
| # For the specific test URL | |
| if "L1vXCYZAYYM" in 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. | |
| """ | |
| # Generic response for other URLs | |
| return "Error: No predefined response for this URL" | |
| def main(): | |
| """Run a simple test of YouTube video analysis mocking""" | |
| try: | |
| # Replace the real function with our mock | |
| print("Replacing YouTube analysis function with mock...") | |
| gaia_tools.analyze_youtube_video = mock_analyze_youtube_video | |
| # Test with our target video URL | |
| video_url = "https://www.youtube.com/watch?v=L1vXCYZAYYM" | |
| question = "What is the highest number of bird species to be on camera simultaneously?" | |
| print(f"\nTesting with URL: {video_url}") | |
| print(f"Question: {question}\n") | |
| # Call the function directly | |
| result = gaia_tools.analyze_youtube_video(video_url, question) | |
| print("Analysis result:") | |
| print("-" * 50) | |
| print(result) | |
| print("-" * 50) | |
| # Extract the answer from the result text | |
| if "highest number of different bird species visible simultaneously is 3" in result: | |
| print("\n✅ Successfully extracted answer: 3") | |
| else: | |
| print("\n❌ Failed to find expected answer in result") | |
| finally: | |
| # Restore the original function | |
| print("\nRestoring original YouTube analysis function...") | |
| gaia_tools.analyze_youtube_video = original_analyze_youtube_video | |
| if __name__ == "__main__": | |
| main() | |