Spaces:
Runtime error
Runtime error
File size: 1,081 Bytes
97901dd 10fc44a 97901dd 10fc44a 97901dd 1659bf8 97901dd 1659bf8 |
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 |
import gradio as gr
import torch
from transformers import HubertForSequenceClassification, HubertProcessor
# Load the model and processor from Hugging Face
model = HubertForSequenceClassification.from_pretrained("HareemFatima/distilhubert-finetuned-stutterdetection")
processor = HubertProcessor.from_pretrained("HareemFatima/distilhubert-finetuned-stutterdetection")
# Define a function for stutter detection
def detect_stutter(audio):
# Preprocess the audio
inputs = processor(audio, sampling_rate=16000, return_tensors="pt", padding=True)
# Get model predictions
with torch.no_grad():
logits = model(**inputs).logits
predicted_class = logits.argmax(-1).item()
# Map prediction to stutter type
stutter_types = {0: "Non Stutter", 1: "Beginner Stutter", 2: "Middle Stutter", 3: "End Stutter"}
return stutter_types.get(predicted_class, "Unknown Stutter")
# Create Gradio interface
iface = gr.Interface(fn=detect_stutter, inputs=gr.Audio(source="microphone", type="numpy"), outputs="text")
# Launch the interface
iface.launch()
|