File size: 1,586 Bytes
1c82b7f
 
 
09a1240
 
 
1c82b7f
09a1240
1c82b7f
 
 
 
 
 
 
 
09a1240
1c82b7f
 
09a1240
384d00c
1c82b7f
 
09a1240
1c82b7f
 
 
 
 
 
 
 
 
 
 
 
09a1240
 
 
 
1c82b7f
 
 
 
 
 
 
09a1240
1c82b7f
 
 
 
09a1240
ddfd97b
09a1240
 
 
 
1c82b7f
0cce4e4
1c82b7f
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
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()