Spaces:
Runtime error
Runtime error
ok
Browse files- app.py +11 -0
- convert.py +58 -0
- requirements.txt +6 -1
app.py
CHANGED
@@ -2,6 +2,7 @@ import os
|
|
2 |
os.system("pip install git+https://github.com/openai/whisper.git")
|
3 |
import gradio as gr
|
4 |
import whisper
|
|
|
5 |
|
6 |
model = whisper.load_model("small")
|
7 |
|
@@ -19,6 +20,9 @@ def inference(audio):
|
|
19 |
print(result.text)
|
20 |
return result.text
|
21 |
|
|
|
|
|
|
|
22 |
|
23 |
title="Whisper"
|
24 |
|
@@ -158,6 +162,13 @@ with block:
|
|
158 |
text = gr.Textbox(show_label=False)
|
159 |
|
160 |
btn.click(inference, inputs=[audio], outputs=[text])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
161 |
|
162 |
gr.HTML('''
|
163 |
<div class="footer">
|
|
|
2 |
os.system("pip install git+https://github.com/openai/whisper.git")
|
3 |
import gradio as gr
|
4 |
import whisper
|
5 |
+
from convert import main
|
6 |
|
7 |
model = whisper.load_model("small")
|
8 |
|
|
|
20 |
print(result.text)
|
21 |
return result.text
|
22 |
|
23 |
+
def inference2(url):
|
24 |
+
return main(url)
|
25 |
+
|
26 |
|
27 |
title="Whisper"
|
28 |
|
|
|
162 |
text = gr.Textbox(show_label=False)
|
163 |
|
164 |
btn.click(inference, inputs=[audio], outputs=[text])
|
165 |
+
|
166 |
+
# add another textbox to get url from user
|
167 |
+
url = gr.Textbox(label="URL", show_label=False)
|
168 |
+
btn2 = gr.Button("Transcribe")
|
169 |
+
text2 = gr.Textbox(show_label=False)
|
170 |
+
btn2.click(inference2, inputs=[url], outputs=[text2])
|
171 |
+
|
172 |
|
173 |
gr.HTML('''
|
174 |
<div class="footer">
|
convert.py
ADDED
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pytube
|
2 |
+
from moviepy.editor import VideoFileClip
|
3 |
+
import pywhisper
|
4 |
+
import os
|
5 |
+
|
6 |
+
def download_video(url):
|
7 |
+
video = pytube.YouTube(url)
|
8 |
+
stream = video.streams.get_by_itag(18)
|
9 |
+
stream.download()
|
10 |
+
return stream.default_filename
|
11 |
+
|
12 |
+
def convert_to_mp3(filename):
|
13 |
+
clip = VideoFileClip(filename)
|
14 |
+
clip.audio.write_audiofile(filename[:-4] + ".mp3")
|
15 |
+
clip.close()
|
16 |
+
|
17 |
+
def AudiotoText(filename):
|
18 |
+
model = pywhisper.load_model("base")
|
19 |
+
result = model.transcribe(filename)
|
20 |
+
print(result["text"])
|
21 |
+
sonuc = result["text"]
|
22 |
+
return sonuc
|
23 |
+
|
24 |
+
def main(url):
|
25 |
+
print('''
|
26 |
+
This tool will convert Youtube videos to mp3 files and then transcribe them to text using Whisper.
|
27 |
+
''')
|
28 |
+
|
29 |
+
print("Downloading video... Please wait.")
|
30 |
+
try:
|
31 |
+
filename = download_video(url)
|
32 |
+
print("Downloaded video as " + filename)
|
33 |
+
except:
|
34 |
+
print("Not a valid link..")
|
35 |
+
return
|
36 |
+
try:
|
37 |
+
convert_to_mp3(filename)
|
38 |
+
print("Converted video to mp3")
|
39 |
+
except:
|
40 |
+
print("Error converting video to mp3")
|
41 |
+
return
|
42 |
+
try:
|
43 |
+
model = pywhisper.load_model("base")
|
44 |
+
result = model.transcribe(filename[:-4] + ".mp3")
|
45 |
+
print(result["text"])
|
46 |
+
result = result["text"]
|
47 |
+
os.remove(filename)
|
48 |
+
os.remove(filename[:-4] + ".mp3")
|
49 |
+
print("Removed video and audio files")
|
50 |
+
print("Done!")
|
51 |
+
return result
|
52 |
+
except:
|
53 |
+
print("Error transcribing audio to text")
|
54 |
+
return
|
55 |
+
|
56 |
+
|
57 |
+
if __name__ == "__main__":
|
58 |
+
main()
|
requirements.txt
CHANGED
@@ -1,2 +1,7 @@
|
|
1 |
gradio
|
2 |
-
whisper
|
|
|
|
|
|
|
|
|
|
|
|
1 |
gradio
|
2 |
+
whisper
|
3 |
+
pytube
|
4 |
+
moviepy
|
5 |
+
pywhisper
|
6 |
+
flask
|
7 |
+
static-ffmpeg
|