salmanmapkar commited on
Commit
cded514
1 Parent(s): e2cb302

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +50 -12
app.py CHANGED
@@ -14,6 +14,7 @@ import pprint
14
  from urllib.error import HTTPError
15
  import subprocess
16
  import gradio as gr
 
17
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization", use_auth_token="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")
18
 
19
 
@@ -105,6 +106,21 @@ def Transcribe(audio="temp_audio.wav"):
105
  except OSError:
106
  pass
107
  return t_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
108
 
109
  def VideoTranscribe(video):
110
  command = f"ffmpeg -i {video} -ab 160k -ac 2 -ar 44100 -vn temp_audio.wav"
@@ -143,16 +159,38 @@ def YoutubeTranscribe(URL, retries = 5):
143
  else:
144
  raise gr.Error(f"Unable to get video from {URL}")
145
 
146
- with gr.Blocks() as i:
147
- with gr.Column():
148
- video = gr.Video()
149
- text = gr.Textbox(label="Youtube Link", placeholder="https://www.youtube.com/watch?v=GECcjrYHH8w")
150
- btn = gr.Button("Run")
151
- with gr.Column():
152
- output = gr.Textbox(label="Transcribed Text", lines=10)
153
- if not video and not text:
154
- raise gr.Error("Either input url or video (not both)")
155
- else:
156
- btn.click(fn=YoutubeTranscribe, inputs=text, outputs=output)
157
- i.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
158
  # YoutubeTranscribe('https://www.youtube.com/watch?v=GECcjrYHH8w')
 
14
  from urllib.error import HTTPError
15
  import subprocess
16
  import gradio as gr
17
+ import traceback
18
  pipeline = Pipeline.from_pretrained("pyannote/speaker-diarization", use_auth_token="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")
19
 
20
 
 
106
  except OSError:
107
  pass
108
  return t_text
109
+ # subprocess.call(['ffmpeg', '-i', 'audio.mp3',
110
+ # 'audio.wav'])
111
+
112
+ def AudioTranscribe(audio, retries=5):
113
+ if retries:
114
+ try:
115
+ subprocess.call(['ffmpeg', '-i', audio,'temp_audio.wav'])
116
+ except Exception as ex:
117
+ traceback.print_exc()
118
+ return AudioTranscribe(audio, retries-1)
119
+ if not (os.path.exist("temp_audio.wav")):
120
+ return AudioTranscribe(audio, retries-1)
121
+ return Transcribe()
122
+ else:
123
+ raise gr.Error("There is some issue ith Audio Transcriber. Please try again later!")
124
 
125
  def VideoTranscribe(video):
126
  command = f"ffmpeg -i {video} -ab 160k -ac 2 -ar 44100 -vn temp_audio.wav"
 
159
  else:
160
  raise gr.Error(f"Unable to get video from {URL}")
161
 
162
+ # with gr.Blocks() as i:
163
+ # with gr.Row():
164
+ # with gr.Column():
165
+ # with gr.Row():
166
+ # video = gr.Video()
167
+ # audio = gr.Audio()
168
+ # text = gr.Textbox(label="Youtube Link", placeholder="https://www.youtube.com/watch?v=GECcjrYHH8w")
169
+ # btn = gr.Button("Run")
170
+ # with gr.Row():
171
+ # output = gr.Textbox(label="Transcribed Text", lines=15)
172
+ # if not video and not text:
173
+ # raise gr.Error("Either input url or video (not both)")
174
+ # else:
175
+ # btn.click(fn=YoutubeTranscribe, inputs=text, outputs=output)
176
+ # i.launch()
177
+
178
+ ut = gr.Interface(
179
+ fn=YoutubeTranscribe,
180
+ inputs=gr.Textbox(label="Youtube Link", placeholder="https://www.youtube.com/watch?v=GECcjrYHH8w"),
181
+ outputs=gr.Textbox(label="Transcribed Text", lines=15)
182
+ )
183
+ vt = gr.Interface(
184
+ fn=VideoTranscribe,
185
+ inputs='video',
186
+ outputs=gr.Textbox(label="Transcribed Text", lines=15)
187
+ )
188
+ at = gr.Interface(
189
+ fn=AudioTranscribe,
190
+ inputs='audio',
191
+ outputs=gr.Textbox(label="Transcribed Text", lines=15)
192
+ )
193
+
194
+ demo = gr.TabbedInterface([ut, vt, at], ["Youtube URL", "Video", "Audio"])
195
+ demo.launch()
196
  # YoutubeTranscribe('https://www.youtube.com/watch?v=GECcjrYHH8w')