Yilin98 commited on
Commit
3a09a61
1 Parent(s): f64dbb0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -4
app.py CHANGED
@@ -4,6 +4,17 @@ import gradio as gr
4
 
5
  pipe = pipeline(model="Yilin98/whisper-small-hi") # change to "your-username/the-name-you-picked"
6
 
 
 
 
 
 
 
 
 
 
 
 
7
  def transcribe(audio=None, file=None, youtube=None):
8
  if (audio is None) and (file is None) and (youtube is None):
9
  return "No audio provided!"
@@ -12,10 +23,7 @@ def transcribe(audio=None, file=None, youtube=None):
12
  elif file is not None:
13
  input=file
14
  elif youtube is not None:
15
- yt=YouTube(youtube)
16
- stream=yt.streams.filter(only_audio=True)[0]
17
- stream.download(filename="audio.mp3")
18
- input=audio
19
  text = pipe(input)["text"]
20
  return text
21
 
 
4
 
5
  pipe = pipeline(model="Yilin98/whisper-small-hi") # change to "your-username/the-name-you-picked"
6
 
7
+ def get_audio(url):
8
+ yt = YouTube(url)
9
+ stream = yt.streams.filter(only_audio=True).first()
10
+ out_file=stream.download(output_path=".")
11
+ base, ext = os.path.splitext(out_file)
12
+ new_file = base+'.mp3'
13
+ os.rename(out_file, new_file)
14
+ audio = new_file
15
+ return audio
16
+
17
+
18
  def transcribe(audio=None, file=None, youtube=None):
19
  if (audio is None) and (file is None) and (youtube is None):
20
  return "No audio provided!"
 
23
  elif file is not None:
24
  input=file
25
  elif youtube is not None:
26
+ input=get_audio(youtube)
 
 
 
27
  text = pipe(input)["text"]
28
  return text
29