new4u commited on
Commit
61fd23f
·
verified ·
1 Parent(s): 408571e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -1
app.py CHANGED
@@ -107,7 +107,32 @@ def yt_transcribe(yt_url, task):
107
  text= convert_to_srt(text)
108
  return html_embed_str, text
109
 
110
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
111
  demo = gr.Blocks()
112
  mf_transcribe = gr.Interface(
113
  fn=transcribe,
 
107
  text= convert_to_srt(text)
108
  return html_embed_str, text
109
 
110
+ # SRT prepare
111
+ # Assuming srt format is a sequence of subtitles with index, time range and text
112
+ def convert_to_srt(input):
113
+ output = ""
114
+ index = 1
115
+ for chunk in input["chunks"]:
116
+ start, end = chunk["timestamp"]
117
+ text = chunk["text"]
118
+ if end is None:
119
+ end = "None"
120
+ # Convert seconds to hours:minutes:seconds,milliseconds format
121
+ start = format_time(start)
122
+ end = format_time(end)
123
+ output += f"{index}\n{start} --> {end}\n{text}\n\n"
124
+ index += 1
125
+ return output
126
+
127
+ # Helper function to format time
128
+ def format_time(seconds):
129
+ if seconds == "None":
130
+ return seconds
131
+ hours = int(seconds // 3600)
132
+ minutes = int((seconds % 3600) // 60)
133
+ seconds = int(seconds % 60)
134
+ milliseconds = int((seconds % 1) * 1000)
135
+ return f"{hours:02}:{minutes:02}:{seconds:02},{milliseconds:03}"
136
  demo = gr.Blocks()
137
  mf_transcribe = gr.Interface(
138
  fn=transcribe,