#!/usr/bin/env python3 """Simple test of Gemini with YouTube video using direct summarization endpoint.""" import requests import json def test_simple_youtube_gemini(): """Test Gemini with a simple YouTube video request.""" video_url = "https://www.youtube.com/watch?v=DCquejfz04A" print("šŸŽ¬ Simple Gemini Test with YouTube Video") print(f"šŸ“ŗ Video URL: {video_url}") # Test the /api/summarize endpoint (simple one) print("\n=== Testing Direct Summarization Endpoint ===") request_data = { "video_url": video_url, "options": { "summary_length": "brief", "focus_areas": ["main points"], "force_model": "google" # Try to force Google/Gemini } } try: print("šŸ“¤ Sending request to /api/summarize...") response = requests.post( "http://localhost:8000/api/summarize", json=request_data, headers={"Content-Type": "application/json"}, timeout=120 # 2 minute timeout ) print(f"šŸ“Ø Response status: {response.status_code}") if response.status_code == 200: result = response.json() print("āœ… SUCCESS! Video summarized") # Display key results if 'summary' in result: summary = result['summary'] print(f"\nšŸ“‹ Summary: {summary[:300]}...") if 'key_points' in result: key_points = result.get('key_points', []) print(f"\nšŸ”‘ Key Points ({len(key_points)} found):") for i, point in enumerate(key_points[:3], 1): print(f" {i}. {point}") if 'metadata' in result: metadata = result['metadata'] model_used = metadata.get('model_used', 'N/A') processing_time = metadata.get('processing_time', 'N/A') print(f"\nšŸ¤– Model used: {model_used}") print(f"⚔ Processing time: {processing_time}") return True elif response.status_code == 400: error = response.json() print(f"āŒ Bad request: {error}") elif response.status_code == 500: error_text = response.text print(f"āŒ Server error: {error_text}") # Try to parse error JSON try: error_json = response.json() detail = error_json.get('detail', 'Unknown error') print(f" Error detail: {detail}") except: pass else: print(f"āŒ Unexpected status {response.status_code}: {response.text}") return False except requests.exceptions.Timeout: print("ā° Request timed out after 2 minutes") return False except Exception as e: print(f"āŒ Error making request: {e}") return False if __name__ == "__main__": print("šŸš€ Simple YouTube + Gemini Test") print("=" * 50) success = test_simple_youtube_gemini() if success: print("\nšŸŽ‰ āœ… Test PASSED! Gemini processed YouTube video successfully!") else: print("\nāŒ Test FAILED - see details above") # Suggest checking backend logs print("\nšŸ’” Troubleshooting:") print(" - Check if backend is running: curl http://localhost:8000/health") print(" - Check available models: curl http://localhost:8000/api/models/available") print(" - View backend logs for detailed error information") print("=" * 50)