import gradio as gr import torch from transformers import pipeline username = "ardneebwar" ## Complete your username model_id = f"{username}/facebook/hubert-base-ls960" device = "cuda:0" if torch.cuda.is_available() else "cpu" pipe = pipeline("audio-classification", model=model_id, device=device) def classify_audio(filepath): import time start_time = time.time() # Assuming `pipe` is your model pipeline for inference preds = pipe(filepath) outputs = {} for p in preds: outputs[p["label"]] = p["score"] end_time = time.time() prediction_time = end_time - start_time return outputs, prediction_time title = "🎵 Animal Sound Classifier" description = """ Animal Sound Classifier model (Fine-tuned "ntu-spml/distilhubert") Dataset: ESC-50 from Github (only the animal sounds) """ filenames = ['dog.wav', 'cat.wav', 'cow.wav'] filenames = [f"./{f}" for f in filenames] demo = gr.Interface( fn=classify_audio, inputs=gr.Audio(type="filepath"), outputs=[gr.Label(), gr.Number(label="Prediction time (s)")], title=title, description=description, ) demo.launch()