David Li commited on
Commit
4de615e
·
1 Parent(s): d255f96

fix: update again

Browse files
Files changed (1) hide show
  1. app.py +12 -2
app.py CHANGED
@@ -3,6 +3,7 @@ import gradio as gr
3
  import ffmpeg
4
  from yt_dlp import YoutubeDL
5
  import os
 
6
 
7
  youtube_livestream_codes = [
8
  91,
@@ -23,7 +24,13 @@ youtube_mp4_codes = [
23
  134
24
  ]
25
 
26
- import sys
 
 
 
 
 
 
27
 
28
  def get_video_metadata(video_url: str = "https://www.youtube.com/watch?v=21X5lGlDOfg&ab_channel=NASA")-> dict:
29
  with YoutubeDL({'outtmpl': '%(id)s.%(ext)s'}) as ydl:
@@ -101,7 +108,9 @@ def get_text_from_mp3_whisper(inputType:str, mp3_file: str, url_path: str, taskN
101
  return "srcLanguage is not set"
102
  if inputType == "url":
103
  filename = get_all_files(url_path)
 
104
  result = model.transcribe(filename, **transcribe_options)
 
105
  else:
106
  result = model.transcribe(mp3_file, **transcribe_options)
107
  # adjust for spacy mode
@@ -116,6 +125,7 @@ def get_text_from_mp3_whisper(inputType:str, mp3_file: str, url_path: str, taskN
116
  lines.append(segment.get("text", "").strip())
117
  lines.append('')
118
  words = '\n'.join(lines)
 
119
  input_file = filename or mp3_file
120
  # ffmpeg -i testing.mp4 -vf subtitles=transcript.srt mysubtitledmovie.mp4
121
  # use ffmpeg bindings to add subtitles to video
@@ -128,7 +138,7 @@ def get_text_from_mp3_whisper(inputType:str, mp3_file: str, url_path: str, taskN
128
 
129
  ffmpeg.run(output_video)
130
  # for spacy use advanced logic to extract and append to html_text using tables?
131
-
132
  # get output_video as mp4
133
  return result.get("segments"), words, "subtitled.mp4"
134
 
 
3
  import ffmpeg
4
  from yt_dlp import YoutubeDL
5
  import os
6
+ import sys
7
 
8
  youtube_livestream_codes = [
9
  91,
 
24
  134
25
  ]
26
 
27
+ def second_to_timecode(x: float) -> str:
28
+ hour, x = divmod(x, 3600)
29
+ minute, x = divmod(x, 60)
30
+ second, x = divmod(x, 1)
31
+ millisecond = int(x * 1000.)
32
+
33
+ return '%.2d:%.2d:%.2d,%.3d' % (hour, minute, second, millisecond)
34
 
35
  def get_video_metadata(video_url: str = "https://www.youtube.com/watch?v=21X5lGlDOfg&ab_channel=NASA")-> dict:
36
  with YoutubeDL({'outtmpl': '%(id)s.%(ext)s'}) as ydl:
 
108
  return "srcLanguage is not set"
109
  if inputType == "url":
110
  filename = get_all_files(url_path)
111
+ print("Retrieved the file")
112
  result = model.transcribe(filename, **transcribe_options)
113
+ print("transcribing the file")
114
  else:
115
  result = model.transcribe(mp3_file, **transcribe_options)
116
  # adjust for spacy mode
 
125
  lines.append(segment.get("text", "").strip())
126
  lines.append('')
127
  words = '\n'.join(lines)
128
+ print("done transcribing")
129
  input_file = filename or mp3_file
130
  # ffmpeg -i testing.mp4 -vf subtitles=transcript.srt mysubtitledmovie.mp4
131
  # use ffmpeg bindings to add subtitles to video
 
138
 
139
  ffmpeg.run(output_video)
140
  # for spacy use advanced logic to extract and append to html_text using tables?
141
+ print(words)
142
  # get output_video as mp4
143
  return result.get("segments"), words, "subtitled.mp4"
144