Spaces:
Runtime error
Runtime error
import requests | |
import gradio as gr | |
import os | |
import requests | |
GLADIA_API_KEY = os.environ.get('GLADIA_API_KEY') | |
headers = { | |
'accept': 'application/json', | |
'x-gladia-key': GLADIA_API_KEY, | |
} | |
ACCEPTED_LANGUAGE_BEHAVIOUR = [ | |
'manual', | |
'automatic single language', | |
'automatic mul language', | |
] | |
def greet(audio, language_behaviour, Language: str): | |
files = { | |
'audio': ("colors.wav", open(audio, 'rb'), 'audio/wav'), | |
'language': (None, Language), | |
'language_behaviour': (None, language_behaviour), | |
} | |
response = requests.post( | |
'https://api.gladia.io/audio/text/audio-transcription/', | |
headers=headers, | |
files=files | |
) | |
if response.status_code != 200: | |
print(response.content, response.status_code) | |
return "Sorry, an error occured with you request :/" | |
return response.json()["prediction"] | |
iface = gr.Interface( | |
fn=greet, | |
inputs=[ | |
gr.Audio(source="upload", type="filepath"), | |
gr.Dropdown( | |
choices=ACCEPTED_LANGUAGE_BEHAVIOUR, | |
value=ACCEPTED_LANGUAGE_BEHAVIOUR[1], | |
type="value", | |
), | |
gr.Textbox(placeholder="english", max_lines=1), | |
], | |
outputs="text" | |
) | |
iface.launch() | |