File size: 4,327 Bytes
1f4e4ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import cv2
import numpy as np
import os
import sys
from sign_utils import MediaPipeLandmarksModel, SignLanguagePredictor

def test_camera():
    """Test if camera is working."""
    print("Testing camera...")
    cap = cv2.VideoCapture(0)
    
    if not cap.isOpened():
        print("❌ Camera not accessible")
        return False
    
    ret, frame = cap.read()
    if not ret:
        print("❌ Cannot read from camera")
        cap.release()
        return False
    
    print("βœ… Camera working")
    cap.release()
    return True

def test_mediapipe():
    """Test MediaPipe hand detection."""
    print("Testing MediaPipe...")
    try:
        landmark_model = MediaPipeLandmarksModel()
        
        # Create a dummy image
        dummy_image = np.zeros((480, 640, 3), dtype=np.uint8)
        landmarks = landmark_model.predict_landmarks(dummy_image)
        
        print("βœ… MediaPipe working")
        return True
    except Exception as e:
        print(f"❌ MediaPipe error: {e}")
        return False

def test_model_files():
    """Test if model files exist."""
    print("Testing model files...")
    
    model_path = "models/model.tflite"
    labels_path = "models/labels.txt"
    
    if not os.path.exists(model_path):
        print(f"❌ Model file not found: {model_path}")
        return False
    
    if not os.path.exists(labels_path):
        print(f"❌ Labels file not found: {labels_path}")
        return False
    
    print("βœ… Model files found")
    return True

def test_predictor():
    """Test the sign language predictor."""
    print("Testing predictor...")
    
    if not test_model_files():
        return False
    
    try:
        predictor = SignLanguagePredictor(
            model_path="models/model.tflite",
            labels_path="models/labels.txt"
        )
        
        # Create a dummy image
        dummy_image = np.zeros((480, 640, 3), dtype=np.uint8)
        prediction, confidence = predictor.predict(dummy_image)
        
        print(f"βœ… Predictor working - Sample prediction: {prediction} ({confidence:.2f})")
        return True
    except Exception as e:
        print(f"❌ Predictor error: {e}")
        return False

def test_dependencies():
    """Test if all dependencies are installed."""
    print("Testing dependencies...")
    
    required_modules = [
        'cv2', 'numpy', 'tensorflow', 'mediapipe', 
        'streamlit', 'sklearn'
    ]
    
    missing_modules = []
    
    for module in required_modules:
        try:
            __import__(module)
        except ImportError:
            missing_modules.append(module)
    
    if missing_modules:
        print(f"❌ Missing modules: {missing_modules}")
        return False
    
    print("βœ… All dependencies installed")
    return True

def run_full_test():
    """Run complete system test."""
    print("🀟 Sign Language Interpreter - System Test")
    print("=" * 50)
    
    tests = [
        ("Dependencies", test_dependencies),
        ("Camera", test_camera),
        ("MediaPipe", test_mediapipe),
        ("Model Files", test_model_files),
        ("Predictor", test_predictor)
    ]
    
    passed = 0
    total = len(tests)
    
    for test_name, test_func in tests:
        print(f"\n{test_name}:")
        if test_func():
            passed += 1
        else:
            print(f"  Fix this issue before proceeding")
    
    print(f"\n{'='*50}")
    print(f"Test Results: {passed}/{total} tests passed")
    
    if passed == total:
        print("πŸŽ‰ All tests passed! System is ready to use.")
        print("\nNext steps:")
        print("1. Run 'streamlit run app.py' to start the application")
        print("2. Or run 'python data_collection.py' to collect custom data")
    else:
        print("❌ Some tests failed. Please fix the issues above.")
        
        if not test_model_files():
            print("\nπŸ’‘ Tip: Run 'python create_sample_model.py' to create a sample model")

def main():
    if len(sys.argv) > 1 and sys.argv[1] == "--quick":
        # Quick test - just check if basic components work
        if test_dependencies() and test_mediapipe():
            print("βœ… Quick test passed!")
        else:
            print("❌ Quick test failed!")
    else:
        run_full_test()

if __name__ == "__main__":
    main()