younes21000 commited on
Commit
79df839
1 Parent(s): d43d2ac

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -6
app.py CHANGED
@@ -13,8 +13,14 @@ from pptx import Presentation
13
  import subprocess
14
  import shlex
15
 
16
- # Load the Whisper model (smaller model for faster transcription)
17
- model = whisper.load_model("tiny")
 
 
 
 
 
 
18
 
19
  # Load M2M100 translation model for different languages
20
  def load_translation_model(target_language):
@@ -178,7 +184,10 @@ def write_ppt(transcription, output_file, tokenizer=None, translation_model=None
178
  ppt.save(output_file)
179
 
180
  # Transcribing video and generating output
181
- def transcribe_video(video_file, language, target_language, output_format):
 
 
 
182
  if video_file is not None: # Ensure the video_file is not None
183
  video_file_path = video_file.name
184
  else:
@@ -218,15 +227,17 @@ def transcribe_video(video_file, language, target_language, output_format):
218
  ppt_file = f"{video_name}.pptx"
219
  write_ppt(result, ppt_file, tokenizer, translation_model)
220
  return ppt_file
 
 
221
 
222
-
223
- # Gradio interface without YouTube URL
224
  iface = gr.Interface(
225
  fn=transcribe_video,
226
  inputs=[
227
- gr.File(label="Upload Video File"),
228
  gr.Dropdown(label="Select Original Video Language", choices=["en", "es", "fr", "de", "it", "pt"], value="en"),
229
  gr.Dropdown(label="Select Subtitle Translation Language", choices=["en", "fa", "es", "de", "fr", "it", "pt"], value="fa"),
 
230
  gr.Radio(label="Choose Output Format", choices=["SRT", "Video with Hardsub", "Word", "PDF", "PowerPoint"], value="Video with Hardsub")
231
  ],
232
  outputs=gr.File(label="Download File"),
 
13
  import subprocess
14
  import shlex
15
 
16
+ # Define available Whisper models
17
+ whisper_models = {
18
+ "Tiny (Fast, Less Accurate)": "tiny",
19
+ "Base (Faster, Moderate Accuracy)": "base",
20
+ "Small (Moderate Speed, Good Accuracy)": "small",
21
+ "Medium (Slower, High Accuracy)": "medium",
22
+ "Large (Slow, Very High Accuracy)": "large",
23
+ }
24
 
25
  # Load M2M100 translation model for different languages
26
  def load_translation_model(target_language):
 
184
  ppt.save(output_file)
185
 
186
  # Transcribing video and generating output
187
+ def transcribe_video(video_file, language, target_language, output_format, model_name):
188
+ actual_model_name = whisper_models[model_name] # Map user selection to model name
189
+ model = whisper.load_model(actual_model_name) # Load the selected model
190
+
191
  if video_file is not None: # Ensure the video_file is not None
192
  video_file_path = video_file.name
193
  else:
 
227
  ppt_file = f"{video_name}.pptx"
228
  write_ppt(result, ppt_file, tokenizer, translation_model)
229
  return ppt_file
230
+ else:
231
+ raise ValueError("Invalid output format selected.")
232
 
233
+ # Gradio interface
 
234
  iface = gr.Interface(
235
  fn=transcribe_video,
236
  inputs=[
237
+ gr.File(label="Upload Video File"),
238
  gr.Dropdown(label="Select Original Video Language", choices=["en", "es", "fr", "de", "it", "pt"], value="en"),
239
  gr.Dropdown(label="Select Subtitle Translation Language", choices=["en", "fa", "es", "de", "fr", "it", "pt"], value="fa"),
240
+ gr.Dropdown(label="Select Whisper Model", choices=list(whisper_models.keys()), value="Tiny (Fast, Less Accurate)"),
241
  gr.Radio(label="Choose Output Format", choices=["SRT", "Video with Hardsub", "Word", "PDF", "PowerPoint"], value="Video with Hardsub")
242
  ],
243
  outputs=gr.File(label="Download File"),