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

# Initialize the audio classification pipeline with the MIT model
pipe = pipeline("audio-classification", model="MIT/ast-finetuned-audioset-10-10-0.4593")

# Define the function to classify an audio file
def classify_audio(audio):
    result = pipe(audio)
    return {label['label']: label['score'] for label in result}

# Set up the Gradio interface
app = gr.Interface(
    fn=classify_audio,                  # Function to classify audio
    inputs=gr.Audio(type="filepath"),   # Input for uploading an audio file
    outputs=gr.Label(num_top_classes=3), # Output with top 3 classification results
    title="Audio Classification",        # App title
    description="Upload an audio file to classify it using MIT's fine-tuned AudioSet model."
)

# Launch the app
if __name__ == "__main__":
    app.launch()