anzorq commited on
Commit
9f4fdf3
1 Parent(s): 14f36e9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -5
app.py CHANGED
@@ -25,20 +25,27 @@ def replace_symbols_back(text):
25
  return reverse_pattern.sub(lambda match: reverse_replacements[match.group(0)], text)
26
 
27
  @spaces.GPU
28
- def transcribe_speech(audio):
29
- if audio is None:
30
  return "No audio received."
 
 
31
  transcription = pipe(audio, chunk_length_s=10)['text']
 
 
32
  return replace_symbols_back(transcription)
33
 
34
- def transcribe_from_youtube(url):
 
35
  # Download audio from YouTube using pytube
36
  audio_path = YouTube(url).streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
37
 
 
38
  transcription = transcribe_speech(audio_path)
39
 
40
  os.remove(audio_path)
41
-
 
42
  return transcription
43
 
44
  def populate_metadata(url):
@@ -75,7 +82,7 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
75
  transcribe_button = gr.Button("Transcribe")
76
  transcription_output = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
77
 
78
- transcribe_button.click(fn=transcribe_from_youtube, inputs=youtube_url, outputs=transcription_output)
79
  youtube_url.change(populate_metadata, inputs=[youtube_url], outputs=[img, title])
80
 
81
  demo.launch()
 
25
  return reverse_pattern.sub(lambda match: reverse_replacements[match.group(0)], text)
26
 
27
  @spaces.GPU
28
+ def transcribe_speech(audio, progress=gr.Progress()):
29
+ if audio is None: # Handle the NoneType error for microphone input
30
  return "No audio received."
31
+
32
+ progress(0, desc="Transcribing audio...")
33
  transcription = pipe(audio, chunk_length_s=10)['text']
34
+ progress(1, desc="Transcription finished")
35
+
36
  return replace_symbols_back(transcription)
37
 
38
+ def transcribe_from_youtube(url, progress=gr.Progress()):
39
+ progress(0, "Starting YouTube audio download...")
40
  # Download audio from YouTube using pytube
41
  audio_path = YouTube(url).streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
42
 
43
+ progress(50, "Transcribing audio...")
44
  transcription = transcribe_speech(audio_path)
45
 
46
  os.remove(audio_path)
47
+
48
+ progress(100, "Done!")
49
  return transcription
50
 
51
  def populate_metadata(url):
 
82
  transcribe_button = gr.Button("Transcribe")
83
  transcription_output = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
84
 
85
+ transcribe_button.click(fn=transcribe_from_youtube, inputs=youtube_url, outputs=transcription_output, progress=True)
86
  youtube_url.change(populate_metadata, inputs=[youtube_url], outputs=[img, title])
87
 
88
  demo.launch()