geokanaan commited on
Commit
95ce231
·
verified ·
1 Parent(s): 3581f0e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -10
app.py CHANGED
@@ -3,7 +3,7 @@ from transformers import pipeline
3
  import os
4
 
5
 
6
- pipe = pipeline(task="automatic-speech-recognition", model="geokanaan/Whisper_Base_Lebanese_Arabizi")
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
- iface = gr.Interface(
19
- fn=transcribe,
20
- inputs=[
21
- gr.Audio(sources="microphone", type="filepath"),
22
- gr.Textbox(label="Actual Transcription")
23
- ],
24
- outputs="text",
 
 
 
 
 
 
 
 
 
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
- iface.launch(share=True)
 
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()