Shangkhonil's picture
Create app.py
1f01380 verified
raw
history blame contribute delete
865 Bytes
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()