Spaces:
Runtime error
Runtime error
import os | |
import requests | |
import gradio as gr | |
from languages import LANGUAGES | |
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 multiple 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 :/" | |
output = response.json()["prediction_raw"] | |
del output["metadata"]["original_mediainfo"] | |
return output | |
iface = gr.Interface( | |
fn=greet, | |
inputs=[ | |
gr.Audio(source="upload", type="filepath"), | |
gr.Dropdown( | |
label="Language transcription behaviour", | |
choices=ACCEPTED_LANGUAGE_BEHAVIOUR, | |
value=ACCEPTED_LANGUAGE_BEHAVIOUR[1], | |
type="value", | |
), | |
gr.Dropdown( | |
choices=[language_name for language_name in LANGUAGES.keys()], | |
label="Language (only if language behaviour is set to manual)", | |
value="english", | |
type="value", | |
), | |
], | |
outputs="json" | |
) | |
iface.launch() | |