def score_audio_plus(audio, api_plan, return_json):
Browse files12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849import gradio as grimport requestsimport osELSA_API_TOKEN = os.getenv("ELSA_API_TOKEN")def score_audio_plus(audio, api_plan, return_json):"""Call the ELSA 'score_audio_plus' endpoint with the provided audio file."""url = "https://api.elsanow.io/api/v1/score_audio_plus"headers = {"Authorization": f"ELSA {ELSA_API_TOKEN}"}# Prepare files and data for POST requestfiles = {'audio_file': (audio.name, audio.file, 'audio/wav')}data = {'api_plan': api_plan,'return_json': "true" if return_json else "false"}# Send POST requestresponse = requests.post(url, files=files, data=data, headers=headers)if response.status_code == 200:# Successfully made the requestreturn response.textelse:# Error handlingreturn f"Error: {response.status_code} - {response.text}"# Gradio interface setupiface = gr.Interface(fn=score_audio_plus,inputs=[gr.Audio(label="Upload your audio file", type="file", tool="microphone"),gr.Dropdown(choices=["basic", "premium"], label="API Plan"),gr.Checkbox(label="Return JSON", value=True)],outputs="text",title="Score Audio Plus API",description="Upload your audio file and choose settings to score the audio.")# Launch the interfaceiface.launch()
app.py+49