KarthickAdopleAI commited on
Commit
b57ac3c
·
verified ·
1 Parent(s): 9d63019

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -300,6 +300,32 @@ class VideoQA:
300
  # Use moviepy to cut both video and audio
301
  video_clip = VideoFileClip(input_file).subclip(start_time, end_time)
302
  video_clip.write_videofile(output_file, codec='libx264', audio_codec='aac', temp_audiofile='temp-audio.m4a', remove_temp=True)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
303
 
304
  def main(self,input_video_path,question):
305
 
@@ -309,7 +335,8 @@ class VideoQA:
309
 
310
  subrip_text = self.results_to_sentence_srt(subtitle)
311
  result = self.extract_timestamps_and_text(subrip_text)
312
- start_time,end_time = self.start_end_timestamp(result,answer)
 
313
  output_video_path = 'output_video.mp4'
314
 
315
  self.cut_video(input_video_path, output_video_path, start_time, end_time)
 
300
  # Use moviepy to cut both video and audio
301
  video_clip = VideoFileClip(input_file).subclip(start_time, end_time)
302
  video_clip.write_videofile(output_file, codec='libx264', audio_codec='aac', temp_audiofile='temp-audio.m4a', remove_temp=True)
303
+
304
+ def sentence_timestamp(self,data):
305
+ result_sentences = []
306
+
307
+ current_sentence = ""
308
+ current_start_timestamp = ""
309
+
310
+ for entry in data:
311
+ text = entry['text']
312
+ start_timestamp = entry['start_timestamp']
313
+ end_timestamp = entry['end_timestamp']
314
+
315
+ # If the current sentence is empty, update start timestamp
316
+ if not current_sentence:
317
+ current_start_timestamp = start_timestamp
318
+
319
+ # Concatenate sentences until a sentence ends with a full stop
320
+ current_sentence += " " + text
321
+ if text.endswith('.'):
322
+ result_sentences.append({
323
+ 'start_timestamp': current_start_timestamp,
324
+ 'end_timestamp': end_timestamp,
325
+ 'text': current_sentence.strip()
326
+ })
327
+ current_sentence = ""
328
+ return result_sentences
329
 
330
  def main(self,input_video_path,question):
331
 
 
335
 
336
  subrip_text = self.results_to_sentence_srt(subtitle)
337
  result = self.extract_timestamps_and_text(subrip_text)
338
+ sent = self.sentence_timestamp(result)
339
+ start_time,end_time = self.start_end_timestamp(sent,answer)
340
  output_video_path = 'output_video.mp4'
341
 
342
  self.cut_video(input_video_path, output_video_path, start_time, end_time)