Spaces:
Runtime error
Runtime error
File size: 1,084 Bytes
97901dd |
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 |
import gradio as gr
import torch
from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2Processor
# Load the model and processor from Hugging Face
model = Wav2Vec2ForSequenceClassification.from_pretrained("HareemFatima/distilhubert-finetuned-stutterdetection")
processor = Wav2Vec2Processor.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()
|