#!/usr/bin/env python3 """ Test script to verify video analysis for a GAIA YouTube question. """ import requests from tools import video_analysis_tool def test_youtube_video_question(): api_url = "https://agents-course-unit4-scoring.hf.space" questions_url = f"{api_url}/questions" print("=== Testing YouTube Video Question ===") # 1. Fetch questions print("1. Fetching questions...") try: response = requests.get(questions_url, timeout=15) response.raise_for_status() questions_data = response.json() print(f"✅ Fetched {len(questions_data)} questions") except Exception as e: print(f"❌ Failed to fetch questions: {e}") return # 2. Find a question with a YouTube link in the question text or file_name youtube_question = None for i, question in enumerate(questions_data): qtext = question.get('question', '').lower() fname = question.get('file_name', '').lower() if 'youtube.com' in qtext or 'youtu.be' in qtext or 'youtube.com' in fname or 'youtu.be' in fname: youtube_question = (i, question) break if not youtube_question: print("❌ No YouTube video questions found.") return idx, question = youtube_question question_text = question.get('question') file_name = question.get('file_name', '') print(f"\n2. Found YouTube video question {idx+1}:") print(f" Question: {question_text[:120]}...") print(f" File name: {file_name}") # 3. Extract YouTube URL # Try to find a YouTube URL in the question text or file_name import re yt_url = None yt_pattern = r'(https?://(?:www\.)?(?:youtube\.com|youtu\.be)[^\s]*)' match = re.search(yt_pattern, question_text) if match: yt_url = match.group(1) elif file_name and ('youtube.com' in file_name or 'youtu.be' in file_name): yt_url = file_name if not yt_url: print("❌ Could not extract YouTube URL from question.") return print(f"3. YouTube URL: {yt_url}") # 4. Analyze the video print("4. Analyzing video with video_analysis_tool...") result = video_analysis_tool.invoke(yt_url) print(f"5. Tool result:") print(f" {result[:500]}...") print("\n✅ YouTube video analysis test complete!") if __name__ == "__main__": test_youtube_video_question()