-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_setup.py
More file actions
221 lines (180 loc) · 6.27 KB
/
test_setup.py
File metadata and controls
221 lines (180 loc) · 6.27 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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
#!/usr/bin/env python3
"""
Test script to verify the Sign Language Learning App setup
"""
import sys
import importlib
import os
def test_imports():
"""Test if all required packages can be imported"""
print("🔍 Testing package imports...")
required_packages = [
'flask',
'cv2',
'cvzone',
'mediapipe',
'firebase_admin',
'google.generativeai',
'dotenv'
]
failed_imports = []
for package in required_packages:
try:
importlib.import_module(package)
print(f"✅ {package}")
except ImportError as e:
print(f"❌ {package}: {e}")
failed_imports.append(package)
if failed_imports:
print(f"\n❌ Failed to import: {', '.join(failed_imports)}")
print("Please install missing packages: pip install -r requirements.txt")
return False
else:
print("\n✅ All packages imported successfully!")
return True
def test_environment():
"""Test environment configuration"""
print("\n🔍 Testing environment configuration...")
# Check if .env file exists
if os.path.exists('.env'):
print("✅ .env file found")
else:
print("⚠️ .env file not found")
print(" Copy env_example.txt to .env and configure your API keys")
# Check if firebase credentials exist
if os.path.exists('firebase-credentials.json'):
print("✅ Firebase credentials found")
else:
print("⚠️ firebase-credentials.json not found")
print(" Download from Firebase Console and save in project root")
# Check for required environment variables
from dotenv import load_dotenv
load_dotenv()
required_vars = ['SECRET_KEY', 'GEMINI_API_KEY']
missing_vars = []
for var in required_vars:
if os.getenv(var):
print(f"✅ {var} is set")
else:
print(f"❌ {var} is not set")
missing_vars.append(var)
if missing_vars:
print(f"\n⚠️ Missing environment variables: {', '.join(missing_vars)}")
print(" Please set them in your .env file")
return False
return True
def test_flask_app():
"""Test Flask app initialization"""
print("\n🔍 Testing Flask app...")
try:
from app import app
print("✅ Flask app imported successfully")
# Test basic route
with app.test_client() as client:
response = client.get('/')
if response.status_code == 200:
print("✅ Home route working")
else:
print(f"❌ Home route failed: {response.status_code}")
return False
return True
except Exception as e:
print(f"❌ Flask app test failed: {e}")
return False
def test_opencv():
"""Test OpenCV functionality"""
print("\n🔍 Testing OpenCV...")
try:
import cv2
print("✅ OpenCV imported successfully")
# Test camera access
cap = cv2.VideoCapture(0)
if cap.isOpened():
print("✅ Camera access working")
cap.release()
else:
print("⚠️ Camera not accessible (this is normal if no camera is connected)")
return True
except Exception as e:
print(f"❌ OpenCV test failed: {e}")
return False
def test_firebase():
"""Test Firebase connection"""
print("\n🔍 Testing Firebase...")
try:
import firebase_admin
from firebase_admin import credentials, firestore
# Check if already initialized
if not firebase_admin._apps:
if os.path.exists('firebase-credentials.json'):
cred = credentials.Certificate("firebase-credentials.json")
firebase_admin.initialize_app(cred)
print("✅ Firebase initialized successfully")
else:
print("⚠️ Firebase credentials not found")
return False
else:
print("✅ Firebase already initialized")
# Test Firestore connection
db = firestore.client()
print("✅ Firestore client created")
return True
except Exception as e:
print(f"❌ Firebase test failed: {e}")
return False
def test_gemini():
"""Test Gemini AI connection"""
print("\n🔍 Testing Gemini AI...")
try:
import google.generativeai as genai
from dotenv import load_dotenv
load_dotenv()
api_key = os.getenv('GEMINI_API_KEY')
if not api_key:
print("❌ GEMINI_API_KEY not found in environment")
return False
genai.configure(api_key=api_key)
model = genai.GenerativeModel('gemini-pro')
print("✅ Gemini AI configured successfully")
return True
except Exception as e:
print(f"❌ Gemini AI test failed: {e}")
return False
def main():
"""Run all tests"""
print("🚀 Sign Language Learning App - Setup Test")
print("=" * 50)
tests = [
test_imports,
test_environment,
test_flask_app,
test_opencv,
test_firebase,
test_gemini
]
passed = 0
total = len(tests)
for test in tests:
try:
if test():
passed += 1
except Exception as e:
print(f"❌ Test failed with exception: {e}")
print("\n" + "=" * 50)
print(f"📊 Test Results: {passed}/{total} tests passed")
if passed == total:
print("🎉 All tests passed! Your setup is ready.")
print("\nTo run the application:")
print("python app.py")
print("\nThen visit: http://localhost:5000")
else:
print("⚠️ Some tests failed. Please check the issues above.")
print("\nCommon solutions:")
print("1. Install dependencies: pip install -r requirements.txt")
print("2. Set up environment variables in .env file")
print("3. Download Firebase credentials")
print("4. Get Gemini AI API key from Google AI Studio")
return passed == total
if __name__ == "__main__":
success = main()
sys.exit(0 if success else 1)