| import gradio as gr |
| import torch |
| import joblib |
| import librosa |
| import numpy as np |
|
|
| |
| model = torch.load("voice_recognition_fullmodel.pth") |
| label_encoder = joblib.load("label_encoder.joblib") |
|
|
| def predict(audio_file): |
| |
| features = extract_features(audio_file) |
| if features is None: |
| return "Error processing audio" |
| |
| |
| input_tensor = torch.tensor(features).unsqueeze(0).unsqueeze(0).float() |
| |
| |
| with torch.no_grad(): |
| outputs = model(input_tensor) |
| _, predicted = torch.max(outputs, 1) |
| |
| user = label_encoder.inverse_transform([predicted.item()])[0] |
| return f"Recognized user: {user}" |
|
|
| |
| iface = gr.Interface( |
| fn=predict, |
| inputs=gr.Audio(source="microphone", type="filepath"), |
| outputs="text", |
| title="Voice Recognition Security System", |
| description="Upload an audio file or record your voice to test user recognition." |
| ) |
|
|
| iface.launch() |