File size: 6,449 Bytes
1619dcb
6c226f9
c01ffa1
1619dcb
 
 
 
 
a808f78
 
 
 
 
 
 
5e126a0
a808f78
 
 
 
 
 
 
 
 
 
 
 
 
 
3c0cd8e
a808f78
 
 
 
1619dcb
 
 
 
 
 
 
6c226f9
 
1619dcb
a808f78
1619dcb
3c0cd8e
1619dcb
 
a808f78
 
1619dcb
 
 
 
85b6c52
1619dcb
 
 
 
 
 
 
 
a808f78
1619dcb
 
 
 
 
a808f78
 
 
 
 
 
 
1619dcb
 
3d88604
a808f78
 
 
 
 
 
5e126a0
a808f78
 
85b6c52
a808f78
 
 
 
 
 
85b6c52
1619dcb
a808f78
 
1619dcb
a808f78
1619dcb
 
 
 
 
 
 
 
 
 
a808f78
1619dcb
 
 
 
 
a808f78
 
 
 
 
 
 
1619dcb
 
 
 
 
 
a808f78
 
 
 
 
 
 
 
5e126a0
a808f78
 
 
 
 
 
 
 
 
6c226f9
a808f78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6c226f9
5208902
5e126a0
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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
import os
import gradio as gr
import spaces
from whisper_cs_fase_1 import generate_fase_1
from whisper_cs_fase_2 import generate_fase_2
from AinaTheme import theme


def generate_fase(audio_path, model_version, civil_channel, fase):
    if fase == 1:
        text = generate_fase_1(
            audio_path,
            model_version=model_version,
            civil_channel=civil_channel
        )
        return text

    elif fase == 2:
        text, sex, age, silence_event, shout_event, meteo_event = generate_fase_2(
            audio_path,
            model_version=model_version,
            civil_channel=civil_channel
        )
        return text, sex, age, silence_event, shout_event, meteo_event

    else:
        raise ValueError("Invalid fase. Must be 1 or 2.")

@spaces.GPU
def transcribe(inputs: str, model_version: str, civil_channel: str, fase: int):
    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"
        )
    return generate_fase(inputs, model_version, civil_channel, fase)


def clear_fase_1(model_version, civil_channel):
    return None, model_version, civil_channel

def clear_fase_2(model_version, civil_channel):
    return None, model_version, civil_channel, "", "", "", "", "", ""


with gr.Blocks(theme=theme) as demo:

    gr.Markdown("## 🗣️ Transcripció automàtica d'àudio — Mode amb dues fases")

    with gr.Tabs():
        with gr.Tab("Fase 1"):

            gr.Markdown(
                "### 🎧 Transcripció de trucades multilingüe de bona qualitat per a transcripció fiable\n"
                "- **v2_fast**: Inclou separació de canals i inferència ràpida.\n"
                "- **v1.0**: Inclou inferència moderada sense separació de canals."
            )

            with gr.Row():
                with gr.Column(scale=1):
                    model_version_1 = gr.Dropdown(
                        label="Model Version",
                        choices=["v2_fast", "v1.0"],
                        value="v2_fast",
                        elem_id="fase1-model-version",
                    )

                    civil_channel_1 = gr.Dropdown(
                        label="Canal del Civil (persona que truca)",
                        choices=["Left", "Right"],
                        value="Left",
                    )

                    input_1 = gr.Audio(
                        sources=["upload", "microphone"],
                        type="filepath",
                        label="Audio",
                    )

                with gr.Column(scale=1):
                    output_1 = 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_1, model_version_1, civil_channel_1, gr.Number(value=1, visible=False)],
                        outputs=[output_1],
                    )

                    clear_btn.click(
                        fn=clear_fase_1,
                        inputs=[model_version_1, civil_channel_1],
                        outputs=[input_1, model_version_1, civil_channel_1],
                        queue=False,
                    )

        with gr.Tab("Fase 2"):

            gr.Markdown(
                "### 🧠 Transcripció de trucades multilingüe de bona qualitat per a anàlisi d'informe\n"
                "- **v2_fast_and_detection_v1**: Inclou inferència ràpida, separació de parlants i explotació d'informació detectada."
            )

            with gr.Row():
                with gr.Column(scale=1):
                    model_version_2 = gr.Dropdown(
                        label="Model Version",
                        choices=["v2_fast_and_detection_v1"],
                        value="v2_fast_and_detection_v1",
                        elem_id="fase2-model-version",
                    )

                    civil_channel_2 = gr.Dropdown(
                        label="Canal del Civil (persona que truca)",
                        choices=["Left", "Right"],
                        value="Left",
                    )

                    input_2 = gr.Audio(
                        sources=["upload", "microphone"],
                        type="filepath",
                        label="Audio",
                    )

                with gr.Column(scale=1):
                    output_text = gr.Textbox(label="Transcripció ASR", lines=8)
                    output_sex = gr.Textbox(label="Gènere", lines=1)
                    output_age = gr.Textbox(label="Edat", lines=1)
                    output_silence = gr.Textbox(label="Detecció de silenci", lines=2)
                    output_shout = gr.Textbox(label="Detecció de crits", lines=2)
                    output_meteo = gr.Textbox(label="Detecció meteo", lines=2)

                with gr.Row(variant="panel"):
                    clear_btn2 = gr.Button("Clear")
                    submit_btn2 = gr.Button("Submit", variant="primary")

                    submit_btn2.click(
                        fn=transcribe,
                        inputs=[input_2, model_version_2, civil_channel_2, gr.Number(value=2, visible=False)],
                        outputs=[
                            output_text,
                            output_sex,
                            output_age,
                            output_silence,
                            output_shout,
                            output_meteo,
                        ],
                    )

                    clear_btn2.click(
                        fn=clear_fase_2,
                        inputs=[model_version_2, civil_channel_2],
                        outputs=[
                            input_2,
                            model_version_2,
                            civil_channel_2,
                            output_text,
                            output_sex,
                            output_age,
                            output_silence,
                            output_shout,
                            output_meteo,
                        ],
                        queue=False,
                    )

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