younes21000 commited on
Commit
79fc358
·
verified ·
1 Parent(s): 35575b2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -13
app.py CHANGED
@@ -19,7 +19,6 @@ def generate_subtitles(video_path, target_language):
19
  transcription = asr(audio_file)["text"]
20
 
21
  # Translate transcription to the target language using M2M100
22
- # The forced_bos_token_id is set based on the target language
23
  translation_pipeline = pipeline('translation', model='facebook/m2m100_418M')
24
  translated_subtitles = translation_pipeline(
25
  transcription,
@@ -35,6 +34,18 @@ def subtitle_video(video_file, target_language):
35
  video_path = video_file.name
36
  return generate_subtitles(video_path, target_language)
37
 
 
 
 
 
 
 
 
 
 
 
 
 
38
  # Gradio app layout
39
  interface = gr.Interface(
40
  fn=subtitle_video,
@@ -42,18 +53,9 @@ interface = gr.Interface(
42
  gr.Video(label="Upload Video"),
43
  gr.Dropdown( # Dropdown for language selection
44
  label="Choose Target Language",
45
- choices=[
46
- "fa", # Persian
47
- "fr", # French
48
- "es", # Spanish
49
- "de", # German
50
- "zh", # Chinese
51
- "ar", # Arabic
52
- "hi", # Hindi
53
- "ru" # Russian
54
- ],
55
- value="fa", # Default to Persian
56
- ),
57
  ],
58
  outputs="text",
59
  title="Automatic Video Subtitler & Translator"
 
19
  transcription = asr(audio_file)["text"]
20
 
21
  # Translate transcription to the target language using M2M100
 
22
  translation_pipeline = pipeline('translation', model='facebook/m2m100_418M')
23
  translated_subtitles = translation_pipeline(
24
  transcription,
 
34
  video_path = video_file.name
35
  return generate_subtitles(video_path, target_language)
36
 
37
+ # List of supported languages with their codes for M2M100
38
+ languages = {
39
+ "Persian (fa)": "fa",
40
+ "French (fr)": "fr",
41
+ "Spanish (es)": "es",
42
+ "German (de)": "de",
43
+ "Chinese (zh)": "zh",
44
+ "Arabic (ar)": "ar",
45
+ "Hindi (hi)": "hi",
46
+ "Russian (ru)": "ru"
47
+ }
48
+
49
  # Gradio app layout
50
  interface = gr.Interface(
51
  fn=subtitle_video,
 
53
  gr.Video(label="Upload Video"),
54
  gr.Dropdown( # Dropdown for language selection
55
  label="Choose Target Language",
56
+ choices=list(languages.keys()), # Display language names in the dropdown
57
+ value="Persian (fa)" # Default language
58
+ )
 
 
 
 
 
 
 
 
 
59
  ],
60
  outputs="text",
61
  title="Automatic Video Subtitler & Translator"