File size: 790 Bytes
3f69c92
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import pipeline

# Load the model
pipe = pipeline("audio-classification", model="dima806/english_accents_classification")

# Define the inference function
def classify_accent(audio):
    result = pipe(audio)
    top_result = result[0]
    top3 = "\n".join([f"{r['label']}: {r['score']:.2f}" for r in result[:3]])
    return f"🎤 Top Prediction: {top_result['label']} ({top_result['score']:.2f})\n\nTop 3:\n{top3}"

# Launch the app
gr.Interface(
    fn=classify_accent,
    inputs=gr.Audio(type="filepath"),
    outputs=gr.Textbox(),
    title="Accent Classifier 🎧",
    description="Upload an English audio sample to detect the speaker's accent.\nSupported: American, British, Indian, African, Australian.",
    allow_flagging="never"
).launch()