younes21000 commited on
Commit
d9de6ec
1 Parent(s): b2110ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -5
app.py CHANGED
@@ -179,12 +179,20 @@ def write_ppt(transcription, output_file, tokenizer=None, translation_model=None
179
 
180
  # Transcribing video and generating output
181
  def transcribe_video(video_file, video_url, language, target_language, output_format):
182
- video_file_path = video_file.name
 
 
 
 
 
 
183
  result = model.transcribe(video_file_path, language=language)
184
  video_name = os.path.splitext(video_file_path)[0]
185
-
186
  if target_language != "en":
187
- tokenizer, translation_model = load_translation_model(target_language)
 
 
 
188
  else:
189
  tokenizer, translation_model = None, None
190
 
@@ -195,8 +203,11 @@ def transcribe_video(video_file, video_url, language, target_language, output_fo
195
  return srt_file
196
  elif output_format == "Video with Hardsub":
197
  output_video = f"{video_name}_with_subtitles.mp4"
198
- embed_hardsub_in_video(video_file_path, srt_file, output_video)
199
- return output_video
 
 
 
200
  elif output_format == "Word":
201
  word_file = f"{video_name}.docx"
202
  write_word(result, word_file, tokenizer, translation_model, target_language)
@@ -210,6 +221,7 @@ def transcribe_video(video_file, video_url, language, target_language, output_fo
210
  write_ppt(result, ppt_file, tokenizer, translation_model)
211
  return ppt_file
212
 
 
213
  # Gradio interface with YouTube URL
214
  iface = gr.Interface(
215
  fn=transcribe_video,
 
179
 
180
  # Transcribing video and generating output
181
  def transcribe_video(video_file, video_url, language, target_language, output_format):
182
+ if video_url:
183
+ video_file_path = download_youtube_video(video_url)
184
+ elif video_file is not None: # Ensure the video_file is not None
185
+ video_file_path = video_file.name
186
+ else:
187
+ raise ValueError("No video file provided. Please upload a video file or provide a YouTube link.")
188
+
189
  result = model.transcribe(video_file_path, language=language)
190
  video_name = os.path.splitext(video_file_path)[0]
 
191
  if target_language != "en":
192
+ try:
193
+ tokenizer, translation_model = load_translation_model(target_language)
194
+ except Exception as e:
195
+ raise RuntimeError(f"Error loading translation model: {e}")
196
  else:
197
  tokenizer, translation_model = None, None
198
 
 
203
  return srt_file
204
  elif output_format == "Video with Hardsub":
205
  output_video = f"{video_name}_with_subtitles.mp4"
206
+ try:
207
+ embed_hardsub_in_video(video_file_path, srt_file, output_video)
208
+ return output_video
209
+ except Exception as e:
210
+ raise RuntimeError(f"Error embedding subtitles in video: {e}")
211
  elif output_format == "Word":
212
  word_file = f"{video_name}.docx"
213
  write_word(result, word_file, tokenizer, translation_model, target_language)
 
221
  write_ppt(result, ppt_file, tokenizer, translation_model)
222
  return ppt_file
223
 
224
+
225
  # Gradio interface with YouTube URL
226
  iface = gr.Interface(
227
  fn=transcribe_video,