FernanOrtega commited on
Commit
6e1ca58
1 Parent(s): ca90b9e

First version

Browse files
Files changed (2) hide show
  1. app.py +47 -0
  2. requirements.txt +4 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pathlib
2
+ import time
3
+
4
+ import gradio as gr
5
+ import youtube_dl
6
+ import whisper
7
+
8
+ ydl_opts = {
9
+ 'format': 'bestaudio/best',
10
+ 'forcefilename': True
11
+ }
12
+ ydl = youtube_dl.YoutubeDL(ydl_opts)
13
+
14
+ models = {
15
+ "tiny": whisper.load_model("tiny"),
16
+ "base": whisper.load_model("base"),
17
+ "small": whisper.load_model("small")
18
+ }
19
+
20
+
21
+ def get_lyrics(model_v, video_url, language):
22
+ t_init = time.time()
23
+ info = ydl.extract_info(video_url, download=False)
24
+ print(time.time() - t_init)
25
+ file_path = ydl.prepare_filename(info)
26
+ print(time.time() - t_init)
27
+ # ydl.download([video_url])
28
+ if not pathlib.Path(file_path).exists():
29
+ ydl.process_info(info)
30
+ print(time.time() - t_init)
31
+
32
+ return info["title"], file_path, models[model_v].transcribe(file_path, language=language, fp16=False)["text"]
33
+
34
+
35
+ iface = gr.Interface(fn=get_lyrics,
36
+ inputs=[
37
+ gr.Dropdown(choices=list(models.keys()), value="base"),
38
+ "text",
39
+ gr.Dropdown(choices=["en", "es", "fr", "pt", "it", "ge", "ko", "ch", "ja", "de", "nr", "sw",
40
+ "ar"], value="en")
41
+ ],
42
+ outputs=[
43
+ gr.Text(label="Título"),
44
+ gr.Audio(label="Audio"),
45
+ gr.Textbox(label="Letra")
46
+ ])
47
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ transformers
2
+ git+https://github.com/ytdl-org/youtube-dl@master
3
+ gradio
4
+ git+https://github.com/openai/whisper@main