NadiAhmdi97 commited on
Commit
b20f620
·
verified ·
1 Parent(s): 0eb328a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -8
app.py CHANGED
@@ -1,27 +1,35 @@
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- asr = pipeline("automatic-speech-recognition",
 
5
  model = "openai/whisper-large-v3")
6
 
 
 
 
7
  demo = gr.Blocks()
8
 
9
- def transcribe_speech(filepath):
10
- if filepath is None:
 
11
  gr.Warning("No audio file found, please retry!")
12
  return ""
13
- output = asr(filepath)
14
- return output["text"]
15
 
 
16
  mic_transcribe = gr.Interface(
17
- fn = transcribe_speech,
18
  inputs = gr.Audio(sources = "microphone",
19
  type = "filepath"),
20
  outputs = gr.Textbox(label = "Transcription",
21
  lines = 3),
22
- allow_flagging = "never"
23
  )
24
 
 
25
  file_transcribe = gr.Interface (
26
  fn = transcribe_speech,
27
  inputs = gr.Audio(sources = "upload",
@@ -31,6 +39,8 @@ file_transcribe = gr.Interface (
31
  allow_flagging = "never"
32
  )
33
 
 
 
34
  with demo:
35
  gr.TabbedInterface(
36
  [mic_transcribe,
@@ -38,4 +48,4 @@ with demo:
38
  ["Transcribe Microphone",
39
  "Transcribe Audio File"],
40
  )
41
- demo.launch()
 
1
+ # Importing gradio for demo application and Transformers to use pipeline
2
  import gradio as gr
3
  from transformers import pipeline
4
 
5
+ # Using the "whisper-large-v3" fine-tuned model for Automatic Speech Recognition ASR tasks
6
+ asr = pipeline(task = "automatic-speech-recognition",
7
  model = "openai/whisper-large-v3")
8
 
9
+
10
+ # Set up a Gradio application with the Blocks class, which can be used to define and configure input and output blocks for the application's interface
11
+ import gradio as gr
12
  demo = gr.Blocks()
13
 
14
+ # Perform speech transcription using the automatic speech recognition (asr) pipeline
15
+ def transcribe_speech(filepath): #path to the audio file
16
+ if filepath is None: #if so, it displays a warning and return empty string
17
  gr.Warning("No audio file found, please retry!")
18
  return ""
19
+ output = asr(filepath) #invokes the asr pipeline on the audio file specified by filepath and
20
+ return output["text"] #returns the transcribed text from the output dictionary
21
 
22
+ # Initialize a Gradio interface for Microphone Transcribe
23
  mic_transcribe = gr.Interface(
24
+ fn = transcribe_speech, #specifies the function to be executed when the interface receives input
25
  inputs = gr.Audio(sources = "microphone",
26
  type = "filepath"),
27
  outputs = gr.Textbox(label = "Transcription",
28
  lines = 3),
29
+ allow_flagging = "never" #specifies whether users are allowed to flag results or not
30
  )
31
 
32
+ # Gradio interface for transcribing speech from an uploaded audio file.
33
  file_transcribe = gr.Interface (
34
  fn = transcribe_speech,
35
  inputs = gr.Audio(sources = "upload",
 
39
  allow_flagging = "never"
40
  )
41
 
42
+ # Create a tabbed interface using Gradio, that allows users to switch between two different interfaces:
43
+ # (mic_transcribe and file_transcribe) for transcribing speech
44
  with demo:
45
  gr.TabbedInterface(
46
  [mic_transcribe,
 
48
  ["Transcribe Microphone",
49
  "Transcribe Audio File"],
50
  )
51
+ demo.launch(debug = True )