youtube-summarizer/test_simple_youtube.py

108 lines
3.7 KiB
Python

#!/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)