younes21000 commited on
Commit
38fcd18
·
verified ·
1 Parent(s): 79fc358

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -15
app.py CHANGED
@@ -8,7 +8,22 @@ asr = pipeline("automatic-speech-recognition", model="openai/whisper-large")
8
  # MarianMT or M2M100 for translation (multi-language)
9
  translator = pipeline("translation", model="facebook/m2m100_418M")
10
 
11
- def generate_subtitles(video_path, target_language):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  # Extract audio from video
13
  video = mp.VideoFileClip(video_path)
14
  audio = video.audio
@@ -30,21 +45,9 @@ def generate_subtitles(video_path, target_language):
30
  return subtitles
31
 
32
  # Define Gradio interface
33
- def subtitle_video(video_file, target_language):
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(
 
8
  # MarianMT or M2M100 for translation (multi-language)
9
  translator = pipeline("translation", model="facebook/m2m100_418M")
10
 
11
+ # Supported languages with their codes
12
+ languages = {
13
+ "Persian (fa)": "fa",
14
+ "French (fr)": "fr",
15
+ "Spanish (es)": "es",
16
+ "German (de)": "de",
17
+ "Chinese (zh)": "zh",
18
+ "Arabic (ar)": "ar",
19
+ "Hindi (hi)": "hi",
20
+ "Russian (ru)": "ru"
21
+ }
22
+
23
+ def generate_subtitles(video_path, language_name):
24
+ # Extract the target language code from the selected language name
25
+ target_language = languages[language_name]
26
+
27
  # Extract audio from video
28
  video = mp.VideoFileClip(video_path)
29
  audio = video.audio
 
45
  return subtitles
46
 
47
  # Define Gradio interface
48
+ def subtitle_video(video_file, language_name):
49
  video_path = video_file.name
50
+ return generate_subtitles(video_path, language_name)
 
 
 
 
 
 
 
 
 
 
 
 
51
 
52
  # Gradio app layout
53
  interface = gr.Interface(