Mei000 commited on
Commit
95d373f
1 Parent(s): 6877610

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -13,18 +13,27 @@ class GradioInference():
13
  if self.yt is None:
14
  self.yt = YouTube(link)
15
  path = self.yt.streams.filter(only_audio=True).all()
16
- voice=path[0].download(filename="tmp.mp4")
17
- results_text = self.loaded_model(voice)["text"]
18
- return results_text
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
19
 
20
- #if url:
21
- # video=YouTube(url).streams.filter(only_audio=True).all()
22
- # audio=video[0].download()
23
- # text = pipe(audio)["text"]
24
- # return text
25
- # if subs == "None":
26
- # return results["text"]
27
-
28
 
29
  def populate_metadata(self, link):
30
  self.yt = YouTube(link)
@@ -52,6 +61,7 @@ with block:
52
  with gr.Group():
53
  with gr.Box():
54
  with gr.Row().style(equal_height=True):
 
55
  link = gr.Textbox(label="YouTube Link")
56
  title = gr.Label(label="Video Title")
57
  with gr.Row().style(equal_height=True):
@@ -59,6 +69,6 @@ with block:
59
  text = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
60
  with gr.Row().style(equal_height=True):
61
  btn = gr.Button("Transcribe")
62
- btn.click(gio, inputs=[link], outputs=[text])
63
  link.change(gio.populate_metadata, inputs=[link], outputs=[img, title])
64
  block.launch()
 
13
  if self.yt is None:
14
  self.yt = YouTube(link)
15
  path = self.yt.streams.filter(only_audio=True).all()
16
+ voice=path[0].download()
17
+ results_text = self.loaded_model(voice)
18
+ return self.srt(results_text["segments"])
19
+
20
+
21
+ def format_time(self, time):
22
+ hours = time//3600
23
+ minutes = (time - hours*3600)//60
24
+ seconds = time - hours*3600 - minutes*60
25
+ milliseconds = (time - int(time))*1000
26
+ return f"{int(hours):02d}:{int(minutes):02d}:{int(seconds):02d},{int(milliseconds):03d}"
27
+
28
+ def srt(self, segments):
29
+ output = ""
30
+ for i, segment in enumerate(segments):
31
+ output += f"{i+1}\n"
32
+ output += f"{self.format_time(segment['start'])} --> {self.format_time(segment['end'])}\n"
33
+ output += f"{segment['text']}\n\n"
34
+ return output
35
+
36
 
 
 
 
 
 
 
 
 
37
 
38
  def populate_metadata(self, link):
39
  self.yt = YouTube(link)
 
61
  with gr.Group():
62
  with gr.Box():
63
  with gr.Row().style(equal_height=True):
64
+ wt = gr.Radio(["None", ".srt", ".csv"], label="With Timestamps?")
65
  link = gr.Textbox(label="YouTube Link")
66
  title = gr.Label(label="Video Title")
67
  with gr.Row().style(equal_height=True):
 
69
  text = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
70
  with gr.Row().style(equal_height=True):
71
  btn = gr.Button("Transcribe")
72
+ btn.click(gio, inputs=[link, wt], outputs=[text])
73
  link.change(gio.populate_metadata, inputs=[link], outputs=[img, title])
74
  block.launch()