Spaces:
Sleeping
Sleeping
Download test_system.py from KrishDev15/Sign_intrepreter: direct link, hf CLI and curl.
- Browser
- Download file 4.33 kB
-
https://huggingface.co/spaces/KrishDev15/Sign_intrepreter/resolve/main/test_system.py
- Command line
-
hf download hf://spaces/KrishDev15/Sign_intrepreter/test_system.py
-
curl -L -o test_system.py https://huggingface.co/spaces/KrishDev15/Sign_intrepreter/resolve/main/test_system.py
4.33 kB
| 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() | |