File size: 1,667 Bytes
6c226f9
 
b7fa1b5
85b6c52
6c226f9
68d9bb9
6c226f9
8f427be
3c0cd8e
bab1585
 
6c226f9
8f427be
 
6c226f9
 
13e0565
1faae08
13e0565
6c226f9
3c0cd8e
85b6c52
 
b7fa1b5
8f427be
85b6c52
 
 
 
 
 
 
8f427be
85b6c52
 
 
 
 
 
 
 
 
 
8f427be
 
6c226f9
 
5208902
 
7097513
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

import gradio as gr
from whisper import generate
from AinaTheme import theme

MODEL_NAME = "openai/whisper-large-v3"

def transcribe(inputs, model_version):
    if inputs is None:
        raise gr.Error("Cap fitxer d'脿udio introduit! Si us plau pengeu un fitxer "\
                       "o enregistreu un 脿udio abans d'enviar la vostra sol路licitud")

    usev4 = model_version=="v0.4"
    return generate(audio_path=inputs, use_v4=usev4)


description_string = "Transcripci贸 autom脿tica de micr貌fon o de fitxers d'脿udio.\n Aquest demostrador s'ha desenvolupat per"\
              " comprovar els models de reconeixement de parla per a m贸bils. Per ara utilitza el checkpoint "\
              f"[{MODEL_NAME}](https://huggingface.co/{MODEL_NAME}) i la llibreria de 馃 Transformers per a la transcripci贸."


def clear():
     return (
          None,
          "v0.3"
     )


with gr.Blocks(theme=theme) as demo:
    gr.Markdown(description_string)
    with gr.Row():
        with gr.Column(scale=1):
            model_version = gr.Dropdown(label="Model Version", choices=["v0.3", "v0.4"], value="v0.3")
            input = gr.Audio(sources=["upload", "microphone"], type="filepath", label="Audio")

        with gr.Column(scale=1):
            output = gr.Textbox(label="Output", lines=8)
    
    with gr.Row(variant="panel"):
            clear_btn = gr.Button("Clear")
            submit_btn = gr.Button("Submit", variant="primary")


    submit_btn.click(fn=transcribe, inputs=[input, model_version], outputs=[output])
    clear_btn.click(fn=clear,inputs=[], outputs=[input, model_version], queue=False,)


if __name__ == "__main__":
    demo.launch()