Spaces:
Running
Running
import gradio as gr | |
import os | |
from acrcloud import ACRCloud | |
# Retrieve ACRCloud credentials from environment variables | |
acr_access_key = os.environ.get('ACR_ACCESS_KEY') | |
acr_access_secret = os.environ.get('ACR_ACCESS_SECRET') | |
# Initialize ACRCloud client | |
acr = ACRCloud('eu-west-1.api.acrcloud.com', acr_access_key, acr_access_secret) | |
def identify_audio(file): | |
# Save the uploaded file temporarily | |
file_path = "temp_audio_file.ogg" | |
file.save(file_path) | |
# Identify the audio using ACRCloud | |
metadata = acr.identify(file_path) | |
# Return the metadata as the output | |
return metadata | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=identify_audio, | |
inputs=gr.File(label="Upload Audio File"), | |
outputs=gr.JSON(label="Audio Metadata"), | |
title="Audio Search by File", | |
description="Upload an audio file to identify it using ACRCloud." | |
) | |
# Launch the interface | |
iface.launch() | |