Spaces:
Running
Running
| 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() | |