Spaces:
Runtime error
Runtime error
GIanlucaRub
commited on
Commit
•
7fe7ac2
1
Parent(s):
1a0509b
Update app.py
Browse files
app.py
CHANGED
@@ -2,6 +2,7 @@ import gradio as gr
|
|
2 |
from pytube import YouTube
|
3 |
from transformers import pipeline
|
4 |
import os
|
|
|
5 |
|
6 |
|
7 |
pipe = pipeline(model="GIanlucaRub/whisper-tiny-it-6") # change to "your-username/the-name-you-picked"
|
@@ -21,8 +22,17 @@ def populate_metadata(link):
|
|
21 |
yt = YouTube(link)
|
22 |
return yt.thumbnail_url, yt.title
|
23 |
|
24 |
-
|
25 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
26 |
block = gr.Blocks()
|
27 |
|
28 |
with block:
|
@@ -30,10 +40,10 @@ with block:
|
|
30 |
"""
|
31 |
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
32 |
<div>
|
33 |
-
<h1>
|
34 |
</div>
|
35 |
<p style="margin-bottom: 10px; font-size: 94%">
|
36 |
-
|
37 |
</p>
|
38 |
</div>
|
39 |
"""
|
@@ -46,19 +56,22 @@ with block:
|
|
46 |
lines=5)
|
47 |
|
48 |
microphone=gr.Audio(source="microphone", type="filepath")
|
49 |
-
|
50 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
51 |
btn_microphone = gr.Button("Transcribe microphone audio")
|
52 |
|
53 |
audio_uploaded=gr.Audio(source="upload", type="filepath")
|
54 |
-
|
55 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
56 |
btn_audio_uploaded = gr.Button("Transcribe audio uploaded")
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
link = gr.Textbox(label="YouTube Link")
|
59 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
60 |
btn_youtube = gr.Button("Transcribe Youtube video")
|
61 |
-
|
62 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
63 |
title = gr.Label(label="Video Title", placeholder="Title")
|
64 |
img = gr.Image(label="Thumbnail")
|
@@ -69,6 +82,7 @@ with block:
|
|
69 |
btn_youtube.click(transcribe_yt, inputs=[link], outputs=[text])
|
70 |
btn_microphone.click(transcribe_audio, inputs=[microphone], outputs=[text])
|
71 |
btn_audio_uploaded.click(transcribe_audio, inputs=[audio_uploaded], outputs=[text])
|
|
|
72 |
link.change(populate_metadata, inputs=[link], outputs=[img, title])
|
73 |
|
74 |
block.launch(debug=True)
|
|
|
2 |
from pytube import YouTube
|
3 |
from transformers import pipeline
|
4 |
import os
|
5 |
+
from moviepy.editor import VideoFileClip
|
6 |
|
7 |
|
8 |
pipe = pipeline(model="GIanlucaRub/whisper-tiny-it-6") # change to "your-username/the-name-you-picked"
|
|
|
22 |
yt = YouTube(link)
|
23 |
return yt.thumbnail_url, yt.title
|
24 |
|
25 |
+
def transcribe_video(video):
|
26 |
+
clip = VideoFileClip(video)
|
27 |
+
audio = video[:-4] + ".mp3"
|
28 |
+
clip.audio.write_audiofile(audio)
|
29 |
+
clip.close()
|
30 |
+
os.remove(video)
|
31 |
+
text = transcribe_audio(audio)
|
32 |
+
os.remove(audio)
|
33 |
+
|
34 |
+
return text
|
35 |
+
|
36 |
block = gr.Blocks()
|
37 |
|
38 |
with block:
|
|
|
40 |
"""
|
41 |
<div style="text-align: center; max-width: 500px; margin: 0 auto;">
|
42 |
<div>
|
43 |
+
<h1>Whisper Tiny Italian</h1>
|
44 |
</div>
|
45 |
<p style="margin-bottom: 10px; font-size: 94%">
|
46 |
+
Realtime demo for Italian speech recognition using a fine-tuned Whisper tiny model.
|
47 |
</p>
|
48 |
</div>
|
49 |
"""
|
|
|
56 |
lines=5)
|
57 |
|
58 |
microphone=gr.Audio(source="microphone", type="filepath")
|
|
|
59 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
60 |
btn_microphone = gr.Button("Transcribe microphone audio")
|
61 |
|
62 |
audio_uploaded=gr.Audio(source="upload", type="filepath")
|
|
|
63 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
64 |
btn_audio_uploaded = gr.Button("Transcribe audio uploaded")
|
65 |
+
|
66 |
+
video_uploaded = gr.Video(source = "upload")
|
67 |
+
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
68 |
+
btn_video_uploaded = gr.Button("Transcribe video uploaded")
|
69 |
+
|
70 |
|
71 |
link = gr.Textbox(label="YouTube Link")
|
72 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
73 |
btn_youtube = gr.Button("Transcribe Youtube video")
|
74 |
+
|
75 |
with gr.Row().style(mobile_collapse=False, equal_height=True):
|
76 |
title = gr.Label(label="Video Title", placeholder="Title")
|
77 |
img = gr.Image(label="Thumbnail")
|
|
|
82 |
btn_youtube.click(transcribe_yt, inputs=[link], outputs=[text])
|
83 |
btn_microphone.click(transcribe_audio, inputs=[microphone], outputs=[text])
|
84 |
btn_audio_uploaded.click(transcribe_audio, inputs=[audio_uploaded], outputs=[text])
|
85 |
+
btn_video_uploaded.click(transcribe_video, inputs=[video_uploaded], outputs=[text])
|
86 |
link.change(populate_metadata, inputs=[link], outputs=[img, title])
|
87 |
|
88 |
block.launch(debug=True)
|