Spaces:
Sleeping
Sleeping
| import os | |
| import sys | |
| import numpy as np | |
| import soundfile as sf | |
| # Setup path to import backend modules | |
| sys.path.append(os.path.join(os.path.dirname(__file__), '..')) | |
| try: | |
| from backend.model_manager import EmotionClassifier | |
| except ImportError: | |
| # Fallback if running from backend dir directly | |
| from model_manager import EmotionClassifier | |
| def create_dummy_wav(path): | |
| sr = 22050 | |
| t = np.linspace(0, 1, sr) | |
| audio = np.sin(2*np.pi*440*t) | |
| sf.write(path, audio, sr) | |
| def test_prediction(): | |
| print("Initializing Classifier...") | |
| try: | |
| classifier = EmotionClassifier() | |
| except Exception as e: | |
| print(f"FAILED to initialize classifier: {e}") | |
| return | |
| # Create a dummy file | |
| test_file = "test_audio_prediction.wav" | |
| create_dummy_wav(test_file) | |
| print(f"Created dummy file: {test_file}") | |
| print("Attempting prediction...") | |
| try: | |
| result = classifier.predict_emotion(test_file) | |
| print("Prediction Success!") | |
| print(f"Result: {result}") | |
| except Exception as e: | |
| print("Prediction FAILED.") | |
| print(f"Error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| finally: | |
| if os.path.exists(test_file): | |
| os.remove(test_file) | |
| if __name__ == "__main__": | |
| test_prediction() | |