Aboubacar OUATTARA - kaira commited on
Commit
4273f74
·
1 Parent(s): 589123e

add examples files

Browse files
Files changed (1) hide show
  1. app.py +25 -2
app.py CHANGED
@@ -1,7 +1,11 @@
 
 
1
  import spaces
2
  import torch
3
  from transformers import pipeline
4
  import gradio as gr
 
 
5
  from bambara_utils import BambaraWhisperTokenizer
6
 
7
  # Determine the appropriate device (GPU or CPU)
@@ -31,15 +35,34 @@ def transcribe(audio):
31
  text = pipe(audio)["text"]
32
  return text
33
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  def main():
 
 
 
36
  # Setup Gradio interface
37
  iface = gr.Interface(
38
  fn=transcribe,
39
- inputs=gr.Audio(type="filepath"),
40
  outputs="text",
41
  title="Bambara Automatic Speech Recognition",
42
- description="Realtime demo for Bambara speech recognition based on a fine-tuning of the Whisper model."
 
43
  )
44
 
45
  # Launch the interface
 
1
+ import os
2
+
3
  import spaces
4
  import torch
5
  from transformers import pipeline
6
  import gradio as gr
7
+ # Please note that the below import will override whisper LANGUAGES to add bambara
8
+ # this is not the best way to do it but at least it works. for more info check the bambara_utils code
9
  from bambara_utils import BambaraWhisperTokenizer
10
 
11
  # Determine the appropriate device (GPU or CPU)
 
35
  text = pipe(audio)["text"]
36
  return text
37
 
38
+ def get_wav_files(directory):
39
+ """
40
+ Returns a list of absolute paths to all .wav files in the specified directory.
41
+
42
+ Args:
43
+ directory (str): The directory to search for .wav files.
44
+
45
+ Returns:
46
+ list: A list of absolute paths to the .wav files.
47
+ """
48
+ # List all files in the directory
49
+ files = os.listdir(directory)
50
+ # Filter for .wav files and create absolute paths
51
+ wav_files = [os.path.abspath(os.path.join(directory, file)) for file in files if file.endswith('.wav')]
52
+ return wav_files
53
 
54
  def main():
55
+ # Get a list of all .wav files in the examples directory
56
+ example_files = get_wav_files("./examples")
57
+
58
  # Setup Gradio interface
59
  iface = gr.Interface(
60
  fn=transcribe,
61
+ inputs=gr.Audio(type="filepath", value=example_files[0]),
62
  outputs="text",
63
  title="Bambara Automatic Speech Recognition",
64
+ description="Realtime demo for Bambara speech recognition based on a fine-tuning of the Whisper model.",
65
+ examples=example_files,
66
  )
67
 
68
  # Launch the interface