Spaces:
Sleeping
Sleeping
Aditya DN
commited on
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import os
|
| 3 |
+
from acrcloud import ACRCloud
|
| 4 |
+
|
| 5 |
+
# Retrieve ACRCloud credentials from environment variables
|
| 6 |
+
acr_access_key = os.environ.get('ACR_ACCESS_KEY')
|
| 7 |
+
acr_access_secret = os.environ.get('ACR_ACCESS_SECRET')
|
| 8 |
+
|
| 9 |
+
# Initialize ACRCloud client
|
| 10 |
+
acr = ACRCloud('eu-west-1.api.acrcloud.com', acr_access_key, acr_access_secret)
|
| 11 |
+
|
| 12 |
+
def identify_audio(file):
|
| 13 |
+
# Save the uploaded file temporarily
|
| 14 |
+
file_path = "temp_audio_file.ogg"
|
| 15 |
+
file.save(file_path)
|
| 16 |
+
|
| 17 |
+
# Identify the audio using ACRCloud
|
| 18 |
+
metadata = acr.identify(file_path)
|
| 19 |
+
|
| 20 |
+
# Return the metadata as the output
|
| 21 |
+
return metadata
|
| 22 |
+
|
| 23 |
+
# Create Gradio interface
|
| 24 |
+
iface = gr.Interface(
|
| 25 |
+
fn=identify_audio,
|
| 26 |
+
inputs=gr.File(label="Upload Audio File"),
|
| 27 |
+
outputs=gr.JSON(label="Audio Metadata"),
|
| 28 |
+
title="Audio Search by File",
|
| 29 |
+
description="Upload an audio file to identify it using ACRCloud."
|
| 30 |
+
)
|
| 31 |
+
|
| 32 |
+
# Launch the interface
|
| 33 |
+
iface.launch()
|