younes21000 commited on
Commit
cb2049f
·
verified ·
1 Parent(s): 1978f09

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -93,9 +93,17 @@ def download_word():
93
  if not translated_subtitle:
94
  return "No translated subtitle to save!"
95
 
 
96
  doc = docx.Document()
97
  doc.add_heading('Translated Subtitles', 0)
98
- doc.add_paragraph(translated_subtitle)
 
 
 
 
 
 
 
99
 
100
  file_path = "translated_subtitles.docx"
101
  doc.save(file_path)
@@ -121,13 +129,8 @@ def download_video():
121
  # Function to generate subtitle text
122
  generator = lambda txt: TextClip(txt, font='Arial', fontsize=24, color='white')
123
 
124
- # Generate subtitles (each subtitle will last for a fixed time)
125
- subs = []
126
- subtitle_length = 5 # seconds each subtitle will be displayed
127
- for i in range(0, len(translated_subtitle), 50):
128
- start_time = (i // 50) * subtitle_length
129
- subtitle_text = translated_subtitle[i:i + 50] # Get the next 50 characters
130
- subs.append((start_time, subtitle_text)) # Create a tuple for start time and text
131
 
132
  # Create subtitle clips
133
  subtitles = SubtitlesClip(subs, generator)
 
93
  if not translated_subtitle:
94
  return "No translated subtitle to save!"
95
 
96
+ # Prepare the document
97
  doc = docx.Document()
98
  doc.add_heading('Translated Subtitles', 0)
99
+
100
+ # Create timestamps and subtitles
101
+ for i in range(0, len(translated_subtitle), 50):
102
+ start_time = (i // 50) * 5 # Each subtitle lasts for 5 seconds
103
+ subtitle_text = translated_subtitle[i:i + 50] # Get the next 50 characters
104
+
105
+ # Add a formatted string with timestamp and subtitle to the document
106
+ doc.add_paragraph(f"{start_time}s - {subtitle_text}")
107
 
108
  file_path = "translated_subtitles.docx"
109
  doc.save(file_path)
 
129
  # Function to generate subtitle text
130
  generator = lambda txt: TextClip(txt, font='Arial', fontsize=24, color='white')
131
 
132
+ # Generate subtitles (assuming each subtitle appears for 5 seconds)
133
+ subs = [(i * 5, translated_subtitle[i:i+50]) for i in range(0, len(translated_subtitle), 50)]
 
 
 
 
 
134
 
135
  # Create subtitle clips
136
  subtitles = SubtitlesClip(subs, generator)