Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import torch
|
| 3 |
+
from transformers import Wav2Vec2ForSequenceClassification, Wav2Vec2Processor
|
| 4 |
+
|
| 5 |
+
# Load the model and processor from Hugging Face
|
| 6 |
+
model = Wav2Vec2ForSequenceClassification.from_pretrained("HareemFatima/distilhubert-finetuned-stutterdetection")
|
| 7 |
+
processor = Wav2Vec2Processor.from_pretrained("HareemFatima/distilhubert-finetuned-stutterdetection")
|
| 8 |
+
|
| 9 |
+
# Define a function for stutter detection
|
| 10 |
+
def detect_stutter(audio):
|
| 11 |
+
# Preprocess the audio
|
| 12 |
+
inputs = processor(audio, sampling_rate=16000, return_tensors="pt", padding=True)
|
| 13 |
+
|
| 14 |
+
# Get model predictions
|
| 15 |
+
with torch.no_grad():
|
| 16 |
+
logits = model(**inputs).logits
|
| 17 |
+
predicted_class = logits.argmax(-1).item()
|
| 18 |
+
|
| 19 |
+
# Map prediction to stutter type
|
| 20 |
+
stutter_types = {0: "Non Stutter", 1: "Beginner Stutter", 2: "Middle Stutter", 3: "End Stutter"}
|
| 21 |
+
return stutter_types.get(predicted_class, "Unknown Stutter")
|
| 22 |
+
|
| 23 |
+
# Create Gradio interface
|
| 24 |
+
iface = gr.Interface(fn=detect_stutter, inputs=gr.Audio(source="microphone", type="numpy"), outputs="text")
|
| 25 |
+
|
| 26 |
+
# Launch the interface
|
| 27 |
+
iface.launch()
|