File size: 1,009 Bytes
fa2111b |
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 |
import gradio as gr
import torch
import joblib
import librosa
import numpy as np
# Load model (adjust paths as needed)
model = torch.load("voice_recognition_fullmodel.pth")
label_encoder = joblib.load("label_encoder.joblib")
def predict(audio_file):
# Extract features
features = extract_features(audio_file)
if features is None:
return "Error processing audio"
# Prepare input
input_tensor = torch.tensor(features).unsqueeze(0).unsqueeze(0).float()
# Predict
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}"
# Create interface
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() |