AI-DHD commited on
Commit
265c64d
·
1 Parent(s): 9c72e3a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -31
app.py CHANGED
@@ -6,7 +6,6 @@ import os
6
  class GradioInference():
7
  def __init__(self):
8
  self.sizes = list(whisper._MODELS.keys())
9
- self.file = "Upload audio/video"
10
  self.current_size = "base"
11
  self.loaded_model = whisper.load_model(self.current_size)
12
  self.yt = None
@@ -14,37 +13,14 @@ class GradioInference():
14
  def __call__(self, link, file, size, subs):
15
  if self.yt is None:
16
  self.yt = YouTube(link)
17
- path = self.yt.streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
18
-
19
- if self.file == None:
20
- self.file = path
21
 
22
  if size != self.current_size:
23
  self.loaded_model = whisper.load_model(size)
24
  self.current_size = size
25
  results = self.loaded_model.transcribe(path)
26
 
27
- if subs == "None":
28
- return results["text"]
29
- elif subs == ".srt":
30
- return self.srt(results["segments"])
31
- elif ".csv" == ".csv":
32
- return self.csv(results["segments"])
33
-
34
- def srt(self, segments):
35
- output = ""
36
- for i, segment in enumerate(segments):
37
- output += f"{i+1}\n"
38
- output += f"{self.format_time(segment['start'])} --> {self.format_time(segment['end'])}\n"
39
- output += f"{segment['text']}\n\n"
40
- return output
41
-
42
- def csv(self, segments):
43
- output = ""
44
- for segment in segments:
45
- output += f"{segment['start']},{segment['end']},{segment['text']}\n"
46
- return output
47
-
48
  def format_time(self, time):
49
  hours = time//3600
50
  minutes = (time - hours*3600)//60
@@ -79,16 +55,13 @@ with block:
79
  with gr.Box():
80
  with gr.Row().style(equal_height=True):
81
  sz = gr.Dropdown(label="Model Size", choices=gio.sizes, value='base')
82
- file = gr.File(label="Upload Video/Audio")
83
- with gr.Row().style(equal_height=True):
84
- wt = gr.Radio(["None", ".srt", ".csv"], label="With Timestamps?")
85
  link = gr.Textbox(label="YouTube Link")
86
  title = gr.Label(label="Video Title")
87
  with gr.Row().style(equal_height=True):
88
  img = gr.Image(label="Thumbnail")
89
- text = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
90
  with gr.Row().style(equal_height=True):
91
  btn = gr.Button("Transcribe")
92
- btn.click(gio, inputs=[link, file, sz, wt], outputs=[text])
93
  link.change(gio.populate_metadata, inputs=[link], outputs=[img, title])
94
  block.launch()
 
6
  class GradioInference():
7
  def __init__(self):
8
  self.sizes = list(whisper._MODELS.keys())
 
9
  self.current_size = "base"
10
  self.loaded_model = whisper.load_model(self.current_size)
11
  self.yt = None
 
13
  def __call__(self, link, file, size, subs):
14
  if self.yt is None:
15
  self.yt = YouTube(link)
16
+
17
+ path = self.yt.streams.filter(only_audio=True)[0].download(filename="tmp.mp4")
 
 
18
 
19
  if size != self.current_size:
20
  self.loaded_model = whisper.load_model(size)
21
  self.current_size = size
22
  results = self.loaded_model.transcribe(path)
23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
  def format_time(self, time):
25
  hours = time//3600
26
  minutes = (time - hours*3600)//60
 
55
  with gr.Box():
56
  with gr.Row().style(equal_height=True):
57
  sz = gr.Dropdown(label="Model Size", choices=gio.sizes, value='base')
 
 
 
58
  link = gr.Textbox(label="YouTube Link")
59
  title = gr.Label(label="Video Title")
60
  with gr.Row().style(equal_height=True):
61
  img = gr.Image(label="Thumbnail")
62
+ >>> text = gr.Textbox(label="Transcription", placeholder="Transcription Output", lines=10)
63
  with gr.Row().style(equal_height=True):
64
  btn = gr.Button("Transcribe")
65
+ btn.click(gio, inputs=[link, sz, wt], outputs=[text])
66
  link.change(gio.populate_metadata, inputs=[link], outputs=[img, title])
67
  block.launch()