Spaces:
Runtime error
Runtime error
Small changes
Browse files
app.py
CHANGED
@@ -7,40 +7,14 @@ class GradioInference():
|
|
7 |
self.model = pipeline(model="humeur/lab2_id2223")
|
8 |
self.yt = None
|
9 |
|
10 |
-
def __call__(self, link
|
11 |
if self.yt is None:
|
12 |
self.yt = YouTube(link)
|
13 |
path = self.yt.streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
|
14 |
|
15 |
results = self.model(path)
|
16 |
-
|
17 |
-
if subs == ".srt":
|
18 |
-
return self.srt(results["segments"])
|
19 |
-
elif subs == ".csv":
|
20 |
-
return self.csv(results["segments"])
|
21 |
return results["text"]
|
22 |
|
23 |
-
def srt(self, segments):
|
24 |
-
output = ""
|
25 |
-
for i, segment in enumerate(segments):
|
26 |
-
output += f"{i+1}\n"
|
27 |
-
output += f"{self.format_time(segment['start'])} --> {self.format_time(segment['end'])}\n"
|
28 |
-
output += f"{segment['text']}\n\n"
|
29 |
-
return output
|
30 |
-
|
31 |
-
def csv(self, segments):
|
32 |
-
output = ""
|
33 |
-
for segment in segments:
|
34 |
-
output += f"{segment['start']},{segment['end']},{segment['text']}\n"
|
35 |
-
return output
|
36 |
-
|
37 |
-
def format_time(self, time):
|
38 |
-
hours = time//3600
|
39 |
-
minutes = (time - hours*3600)//60
|
40 |
-
seconds = time - hours*3600 - minutes*60
|
41 |
-
milliseconds = (time - int(time))*1000
|
42 |
-
return f"{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d},{int(milliseconds):03d}"
|
43 |
-
|
44 |
def populate_metadata(self, link):
|
45 |
self.yt = YouTube(link)
|
46 |
return self.yt.thumbnail_url, self.yt.title
|
@@ -65,8 +39,6 @@ with block:
|
|
65 |
)
|
66 |
with gr.Group():
|
67 |
with gr.Box():
|
68 |
-
with gr.Row().style(equal_height=True):
|
69 |
-
wt = gr.Radio(["No", ".srt", ".csv"], label="Result with timestamps?")
|
70 |
link = gr.Textbox(label="YouTube Link")
|
71 |
title = gr.Label(label="Video Title")
|
72 |
with gr.Row().style(equal_height=True):
|
@@ -74,6 +46,6 @@ with block:
|
|
74 |
text = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
|
75 |
with gr.Row().style(equal_height=True):
|
76 |
btn = gr.Button("Transcribe")
|
77 |
-
btn.click(gio, inputs=[link
|
78 |
link.change(gio.populate_metadata, inputs=[link], outputs=[img, title])
|
79 |
block.launch()
|
|
|
7 |
self.model = pipeline(model="humeur/lab2_id2223")
|
8 |
self.yt = None
|
9 |
|
10 |
+
def __call__(self, link):
|
11 |
if self.yt is None:
|
12 |
self.yt = YouTube(link)
|
13 |
path = self.yt.streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
|
14 |
|
15 |
results = self.model(path)
|
|
|
|
|
|
|
|
|
|
|
16 |
return results["text"]
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def populate_metadata(self, link):
|
19 |
self.yt = YouTube(link)
|
20 |
return self.yt.thumbnail_url, self.yt.title
|
|
|
39 |
)
|
40 |
with gr.Group():
|
41 |
with gr.Box():
|
|
|
|
|
42 |
link = gr.Textbox(label="YouTube Link")
|
43 |
title = gr.Label(label="Video Title")
|
44 |
with gr.Row().style(equal_height=True):
|
|
|
46 |
text = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
|
47 |
with gr.Row().style(equal_height=True):
|
48 |
btn = gr.Button("Transcribe")
|
49 |
+
btn.click(gio, inputs=[link], outputs=[text])
|
50 |
link.change(gio.populate_metadata, inputs=[link], outputs=[img, title])
|
51 |
block.launch()
|