-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Expand file tree
/
Copy pathtest_setup.py
More file actions
123 lines (95 loc) · 3.46 KB
/
test_setup.py
File metadata and controls
123 lines (95 loc) · 3.46 KB
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
#!/usr/bin/env python3
"""
Test script to verify the setup for Video RAG with Gemini
"""
import sys
import os
from dotenv import load_dotenv
def test_imports():
"""Test if all required packages are installed"""
print("🔍 Testing imports...")
try:
import streamlit
print(f"✅ Streamlit: {streamlit.__version__}")
except ImportError:
print("❌ Streamlit not installed. Run: pip install streamlit")
return False
try:
import google.generativeai as genai
print(f"✅ Google GenerativeAI: {genai.__version__}")
except ImportError:
print("❌ Google GenerativeAI not installed. Run: pip install google-generativeai")
return False
try:
from dotenv import load_dotenv
print("✅ Python-dotenv: Available")
except ImportError:
print("❌ Python-dotenv not installed. Run: pip install python-dotenv")
return False
return True
def test_api_key():
"""Test if API key is configured"""
print("\n🔑 Testing API key configuration...")
load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")
if not api_key:
print("⚠️ GEMINI_API_KEY not found in environment")
print(" You can either:")
print(" 1. Create a .env file with GEMINI_API_KEY=your_key")
print(" 2. Enter the API key directly in the Streamlit app")
print(" Get your key from: https://aistudio.google.com/app/apikey")
return False
if len(api_key) < 10:
print("⚠️ API key seems too short, please verify")
return False
print("✅ API key found and looks valid")
return True
def test_gemini_connection():
"""Test connection to Gemini API"""
print("\n🌐 Testing Gemini API connection...")
load_dotenv()
api_key = os.getenv("GEMINI_API_KEY")
if not api_key:
print("⚠️ Skipping connection test - no API key")
return False
try:
import google.generativeai as genai
genai.configure(api_key=api_key)
# Try to list models to test connection
models = list(genai.list_models())
print(f"✅ Connected to Gemini API - {len(models)} models available")
# Check if the required model is available
model_names = [m.name for m in models]
if 'models/gemini-1.5-pro' in model_names:
print("✅ Gemini 1.5 Pro model is available")
else:
print("⚠️ Gemini 1.5 Pro model not found in available models")
print(" Available models:", [m.name for m in models[:3]])
return True
except Exception as e:
print(f"❌ Failed to connect to Gemini API: {e}")
return False
def main():
"""Run all tests"""
print("🧪 Video RAG Setup Test")
print("=" * 30)
all_passed = True
# Test imports
if not test_imports():
all_passed = False
# Test API key
if not test_api_key():
all_passed = False
# Test connection
if not test_gemini_connection():
all_passed = False
print("\n" + "=" * 30)
if all_passed:
print("🎉 All tests passed! You're ready to run the Video RAG app.")
print(" Run: streamlit run app.py")
else:
print("⚠️ Some tests failed. Please fix the issues above.")
return all_passed
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)