Edward Tan commited on
Commit
c976dc3
·
1 Parent(s): 1d99247

Adding example

Browse files
Files changed (3) hide show
  1. app.py +10 -11
  2. example_audio/.DS_Store +0 -0
  3. example_audio/conference.wav +0 -0
app.py CHANGED
@@ -6,26 +6,25 @@ local_model_name = "wav2vec2_model_pipeline"
6
  speech_recognizer = pipeline("automatic-speech-recognition", model = local_model_name)
7
 
8
  def greet_and_transcribe(name, intensity, input_audio):
9
- try:
10
- input_audio_rs = librosa.resample(
11
- input_audio[1].astype(float),
12
- orig_sr=input_audio[0],
13
- target_sr=speech_recognizer.feature_extractor.sampling_rate)
14
- transcribed_audio = speech_recognizer(input_audio_rs)["text"]
15
- return "Hello, " + name + "!" * int(intensity), transcribed_audio
16
- except Exception as err:
17
- return "Hello, " + name + "!" * int(intensity), err
18
 
19
  demo = gr.Interface(
20
  title="A simple audio transcribing model",
21
  description="This is an application to test gradio functionalities",
22
-
23
  fn=greet_and_transcribe,
24
  inputs=[
25
  gr.Text(placeholder="input your name here"),
26
  gr.Slider(minimum=1, maximum=5, value=3),
27
  gr.Audio()],
28
  outputs=[gr.Text(label="Greeting"), gr.Text(label="Transcribed output")],
29
- allow_flagging="auto"
 
 
 
30
  )
31
  demo.launch(share=True)
 
6
  speech_recognizer = pipeline("automatic-speech-recognition", model = local_model_name)
7
 
8
  def greet_and_transcribe(name, intensity, input_audio):
9
+ input_audio_rs = librosa.resample(
10
+ input_audio[1].astype(float),
11
+ orig_sr=input_audio[0],
12
+ target_sr=speech_recognizer.feature_extractor.sampling_rate)
13
+ transcribed_audio = speech_recognizer(input_audio_rs)["text"]
14
+ return "Hello, " + name + "!" * int(intensity), transcribed_audio
 
 
 
15
 
16
  demo = gr.Interface(
17
  title="A simple audio transcribing model",
18
  description="This is an application to test gradio functionalities",
 
19
  fn=greet_and_transcribe,
20
  inputs=[
21
  gr.Text(placeholder="input your name here"),
22
  gr.Slider(minimum=1, maximum=5, value=3),
23
  gr.Audio()],
24
  outputs=[gr.Text(label="Greeting"), gr.Text(label="Transcribed output")],
25
+ cache_examples="lazy",
26
+ allow_flagging="auto",
27
+ examples=[["Jacob", 3, "example_audio/conference.wav"]]
28
+ # article="<p style='text-align: center'><a href='https://tmabraham.github.io/blog/gradio_hf_spaces_tutorial' target='_blank'>Blog post</a></p>"
29
  )
30
  demo.launch(share=True)
example_audio/.DS_Store ADDED
Binary file (6.15 kB). View file
 
example_audio/conference.wav ADDED
Binary file (472 kB). View file