tdurzynski commited on
Commit
f28ce48
·
verified ·
1 Parent(s): b7aaa7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -35
app.py CHANGED
@@ -1,46 +1,31 @@
1
  from transformers import pipeline
2
  import gradio as gr
 
3
 
 
4
  asr = pipeline(task="automatic-speech-recognition",
5
  model="./models/distil-whisper/distil-small.en")
6
 
7
- demo = gr.Blocks()
8
-
9
  def transcribe_long_form(filepath):
10
  if filepath is None:
11
- gr.Warning("No audio found, please retry.")
12
- return ""
13
- output = asr(
14
- filepath,
15
- max_new_tokens=256,
16
- chunk_length_s=30,
17
- batch_size=8,
18
- )
19
- return output["text"]
20
 
21
- mic_transcribe = gr.Interface(
22
- fn=transcribe_long_form,
23
- inputs=gr.Audio(sources="microphone",
24
- type="filepath"),
25
- outputs=gr.Textbox(label="Transcription",
26
- lines=3),
27
- allow_flagging="never")
28
 
29
- file_transcribe = gr.Interface(
30
- fn=transcribe_long_form,
31
- inputs=gr.Audio(sources="upload",
32
- type="filepath"),
33
- outputs=gr.Textbox(label="Transcription",
34
- lines=3),
35
- allow_flagging="never",
36
- )
37
 
38
- with demo:
39
- gr.TabbedInterface(
40
- [mic_transcribe,
41
- file_transcribe],
42
- ["Transcribe Microphone",
43
- "Transcribe Audio File"],
44
- )
45
- demo.launch(share=True,
46
- server_port=int(os.environ['PORT1']))
 
1
  from transformers import pipeline
2
  import gradio as gr
3
+ import os
4
 
5
+ # Load the ASR model
6
  asr = pipeline(task="automatic-speech-recognition",
7
  model="./models/distil-whisper/distil-small.en")
8
 
9
+ # Define the transcription function
 
10
  def transcribe_long_form(filepath):
11
  if filepath is None:
12
+ return "No audio file provided, please upload a file or record one."
13
+ output = asr(filepath)
14
+ return output['text']
 
 
 
 
 
 
15
 
16
+ # Set up the Gradio interface
17
+ with gr.Blocks() as demo:
18
+ with gr.Tab("Transcribe Audio"):
19
+ with gr.Row():
20
+ audio_input = gr.Audio(sources=["microphone", "upload"], type="filepath")
21
+ submit_button = gr.Button("Transcribe")
22
+ transcription_output = gr.Textbox(label="Transcription", lines=3)
23
 
24
+ submit_button.click(
25
+ transcribe_long_form,
26
+ inputs=[audio_input],
27
+ outputs=[transcription_output]
28
+ )
 
 
 
29
 
30
+ # Launch the Gradio app
31
+ demo.launch(share=True, server_port=int(os.environ.get('PORT1', 7860))) # Default port 7860 if PORT1 is not set