Update app.py
Browse files
app.py
CHANGED
@@ -3,7 +3,7 @@ from transformers import pipeline
|
|
3 |
import os
|
4 |
|
5 |
|
6 |
-
|
7 |
|
8 |
|
9 |
|
@@ -15,17 +15,25 @@ def transcribe(audio, actual_transcription):
|
|
15 |
HF_TOKEN = os.getenv('WRITE')
|
16 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "flagged_Audio_Lebanese")
|
17 |
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
title="arabeasy",
|
26 |
description="Realtime demo for Lebanese Arabizi speech recognition",
|
27 |
allow_flagging='manual', # Enable manual flagging
|
28 |
-
flagging_callback=hf_writer
|
29 |
)
|
30 |
|
31 |
-
|
|
|
3 |
import os
|
4 |
|
5 |
|
6 |
+
transcriber = pipeline(task="automatic-speech-recognition", model="geokanaan/Whisper_Base_Lebanese_Arabizi")
|
7 |
|
8 |
|
9 |
|
|
|
15 |
HF_TOKEN = os.getenv('WRITE')
|
16 |
hf_writer = gr.HuggingFaceDatasetSaver(HF_TOKEN, "flagged_Audio_Lebanese")
|
17 |
|
18 |
+
def transcribe(stream, new_chunk):
|
19 |
+
sr, y = new_chunk
|
20 |
+
y = y.astype(np.float32)
|
21 |
+
y /= np.max(np.abs(y))
|
22 |
+
|
23 |
+
if stream is not None:
|
24 |
+
stream = np.concatenate([stream, y])
|
25 |
+
else:
|
26 |
+
stream = y
|
27 |
+
return stream, transcriber({"sampling_rate": sr, "raw": stream})["text"]
|
28 |
+
|
29 |
+
demo = gr.Interface(
|
30 |
+
transcribe,
|
31 |
+
["state", gr.Audio(sources=["microphone"], streaming=True)],
|
32 |
+
["state", "text"],
|
33 |
+
live=True,
|
34 |
title="arabeasy",
|
35 |
description="Realtime demo for Lebanese Arabizi speech recognition",
|
36 |
allow_flagging='manual', # Enable manual flagging
|
|
|
37 |
)
|
38 |
|
39 |
+
demo.launch()
|