isaakkamau commited on
Commit
956a43b
·
1 Parent(s): a3d60eb

updated multilingual app

Browse files
Files changed (1) hide show
  1. app.py +7 -14
app.py CHANGED
@@ -141,12 +141,10 @@ remove_files(7)
141
 
142
 
143
 
144
- #from pydub import AudioSegment
145
-
146
  #Download the model
147
  model = whisper.load_model("small")
148
 
149
-
150
  def video2mp3(video_file, output_ext="mp3"):
151
  filename, ext = os.path.splitext(video_file)
152
  subprocess.call(["ffmpeg", "-y", "-i", video_file, f"{filename}.{output_ext}"],
@@ -162,24 +160,20 @@ def translate(input_video):
162
  translate_options = dict(task="translate", **options)
163
  result = model.transcribe(audio_file, **translate_options)
164
 
165
- output_dir = "content" # Specify the desired output directory
166
- os.makedirs(output_dir, exist_ok=True) # Create the directory if it doesn't exist
167
- audio_path = os.path.splitext(os.path.basename(audio_file))[0]
168
- subtitle_path = os.path.join(output_dir, audio_path + ".vtt")
169
 
170
- with open(subtitle_path, "w") as vtt:
171
  write_vtt(result["segments"], file=vtt)
172
 
173
- output_video = os.path.join(output_dir, audio_path + "_subtitled.mp4")
 
174
 
175
- subprocess.call(["ffmpeg", "-i", input_video, "-vf", f"subtitles={subtitle_path}:scodec=srt,force_style='[email protected],FontSize=30'", output_video],
176
- stdout=subprocess.DEVNULL,
177
- stderr=subprocess.STDOUT)
178
 
179
  return output_video
180
 
181
 
182
-
183
  st.title("MultiLingual AI: Add Caption to Videos")
184
 
185
  uploaded_file = st.file_uploader("Upload your video", type=["mp4"])
@@ -199,7 +193,6 @@ if uploaded_file is not None:
199
  # Remove temporary files
200
  os.remove("temp_video.mp4")
201
 
202
-
203
  st.markdown(
204
  '''
205
  <style>
 
141
 
142
 
143
 
 
 
144
  #Download the model
145
  model = whisper.load_model("small")
146
 
147
+
148
  def video2mp3(video_file, output_ext="mp3"):
149
  filename, ext = os.path.splitext(video_file)
150
  subprocess.call(["ffmpeg", "-y", "-i", video_file, f"{filename}.{output_ext}"],
 
160
  translate_options = dict(task="translate", **options)
161
  result = model.transcribe(audio_file, **translate_options)
162
 
163
+ output_dir = '/content/'
164
+ audio_path = audio_file.split(".")[0]
 
 
165
 
166
+ with open(os.path.join(output_dir, audio_path + ".vtt"), "w") as vtt:
167
  write_vtt(result["segments"], file=vtt)
168
 
169
+ subtitle = audio_path + ".vtt"
170
+ output_video = audio_path + "_subtitled.mp4"
171
 
172
+ os.system(f"ffmpeg -i {input_video} -vf subtitles={subtitle} {output_video}")
 
 
173
 
174
  return output_video
175
 
176
 
 
177
  st.title("MultiLingual AI: Add Caption to Videos")
178
 
179
  uploaded_file = st.file_uploader("Upload your video", type=["mp4"])
 
193
  # Remove temporary files
194
  os.remove("temp_video.mp4")
195
 
 
196
  st.markdown(
197
  '''
198
  <style>