def score_audio_plus(audio, api_plan, return_json):
Browse files
app.py
CHANGED
|
@@ -0,0 +1,49 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
ELSA_API_TOKEN = os.getenv("ELSA_API_TOKEN")
|
| 6 |
+
|
| 7 |
+
def score_audio_plus(audio, api_plan, return_json):
|
| 8 |
+
"""
|
| 9 |
+
Call the ELSA 'score_audio_plus' endpoint with the provided audio file.
|
| 10 |
+
"""
|
| 11 |
+
url = "https://api.elsanow.io/api/v1/score_audio_plus"
|
| 12 |
+
headers = {
|
| 13 |
+
"Authorization": f"ELSA {ELSA_API_TOKEN}"
|
| 14 |
+
}
|
| 15 |
+
|
| 16 |
+
# Prepare files and data for POST request
|
| 17 |
+
files = {
|
| 18 |
+
'audio_file': (audio.name, audio.file, 'audio/wav')
|
| 19 |
+
}
|
| 20 |
+
data = {
|
| 21 |
+
'api_plan': api_plan,
|
| 22 |
+
'return_json': "true" if return_json else "false"
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
# Send POST request
|
| 26 |
+
response = requests.post(url, files=files, data=data, headers=headers)
|
| 27 |
+
|
| 28 |
+
if response.status_code == 200:
|
| 29 |
+
# Successfully made the request
|
| 30 |
+
return response.text
|
| 31 |
+
else:
|
| 32 |
+
# Error handling
|
| 33 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 34 |
+
|
| 35 |
+
# Gradio interface setup
|
| 36 |
+
iface = gr.Interface(
|
| 37 |
+
fn=score_audio_plus,
|
| 38 |
+
inputs=[
|
| 39 |
+
gr.Audio(label="Upload your audio file", type="file", tool="microphone"),
|
| 40 |
+
gr.Dropdown(choices=["basic", "premium"], label="API Plan"),
|
| 41 |
+
gr.Checkbox(label="Return JSON", value=True)
|
| 42 |
+
],
|
| 43 |
+
outputs="text",
|
| 44 |
+
title="Score Audio Plus API",
|
| 45 |
+
description="Upload your audio file and choose settings to score the audio."
|
| 46 |
+
)
|
| 47 |
+
|
| 48 |
+
# Launch the interface
|
| 49 |
+
iface.launch()
|