jilijeanlouis's picture
Update app.py
0cce4e4
raw
history blame
1.25 kB
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="json"
)
iface.launch()