Spaces:
Running
Running
File size: 1,093 Bytes
b63d954 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
import requests
import gradio as gr
API_URL = "https://api-inference.huggingface.co/models/MIT/ast-finetuned-audioset-10-10-0.4593"
headers = {"Authorization": f"Bearer {os.environ.get('HF_TOKEN')}"}
def classify_audio(audio_file):
"""
Classify the uploaded audio file using Hugging Face AST model
"""
if audio_file is None:
return "Please upload an audio file."
with open(audio_file.name, "rb") as f:
data = f.read()
response = requests.post(API_URL, headers=headers, data=data)
try:
results = response.json()
return results
except Exception as e:
return f"Error processing audio: {str(e)}"
# Create Gradio interface
iface = gr.Interface(
fn=classify_audio,
inputs=gr.Audio(type="filepath", label="Upload Audio File"),
outputs=gr.JSON(label="Classification Results"),
title="Audio Classification using AST Model",
description="Upload an audio file to get its classification results using the Audio Spectrogram Transformer model.",
examples=[],
)
# Launch the interface
iface.launch()
|