Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -14,6 +14,7 @@ df.columns = ['ISO 639-1', 'ISO 639-2', 'Language Name', 'Native Name']
|
|
14 |
df['ISO 639-1'] = df['ISO 639-1'].str.strip()
|
15 |
|
16 |
language_options = [(row['ISO 639-1'], f"{row['ISO 639-1']}") for index, row in df.iterrows()]
|
|
|
17 |
|
18 |
logging.basicConfig(level=logging.DEBUG)
|
19 |
|
@@ -105,27 +106,28 @@ with gr.Blocks() as blocks_app:
|
|
105 |
video_file = gr.Video(label="Upload Video")
|
106 |
source_language_dropdown = gr.Dropdown(choices=language_options, label="Source Language", value="en")
|
107 |
target_language_dropdown = gr.Dropdown(choices=language_options, label="Target Language", value="fr")
|
|
|
108 |
transcribe_button = gr.Button("Transcribe Video")
|
109 |
translate_button = gr.Button("Translate Subtitles")
|
110 |
|
111 |
output_video = gr.Video(label="Processed Video")
|
112 |
output_srt = gr.File(label="Subtitles File (.srt)")
|
113 |
|
114 |
-
def transcribe_and_add_subtitles(video_file):
|
115 |
-
transcription = transcribe(video_file,
|
116 |
srt_path = text_to_srt(transcription)
|
117 |
output_video_path = add_subtitle_to_video(video_file, srt_path, subtitle_language="eng", soft_subtitle=False)
|
118 |
return output_video_path, srt_path
|
119 |
|
120 |
-
def translate_subtitles_and_add_to_video(video_file, source_language_code, target_language_code):
|
121 |
-
transcription = transcribe(video_file,
|
122 |
srt_path = text_to_srt(transcription)
|
123 |
translated_srt_path = translate_srt(srt_path, source_language_code, target_language_code)
|
124 |
output_video_path = add_subtitle_to_video(video_file, translated_srt_path, target_language_code, soft_subtitle=False)
|
125 |
return output_video_path, translated_srt_path
|
126 |
|
127 |
-
transcribe_button.click(transcribe_and_add_subtitles, inputs=video_file, outputs=[output_video, output_srt])
|
128 |
-
translate_button.click(translate_subtitles_and_add_to_video, inputs=[video_file, source_language_dropdown, target_language_dropdown], outputs=[output_video, output_srt])
|
129 |
|
130 |
# Lancement de l'application
|
131 |
blocks_app.launch()
|
|
|
14 |
df['ISO 639-1'] = df['ISO 639-1'].str.strip()
|
15 |
|
16 |
language_options = [(row['ISO 639-1'], f"{row['ISO 639-1']}") for index, row in df.iterrows()]
|
17 |
+
model_size_options = ["tiny", "base", "small", "medium", "large", "large-v2", "large-v3"] # Add model size options
|
18 |
|
19 |
logging.basicConfig(level=logging.DEBUG)
|
20 |
|
|
|
106 |
video_file = gr.Video(label="Upload Video")
|
107 |
source_language_dropdown = gr.Dropdown(choices=language_options, label="Source Language", value="en")
|
108 |
target_language_dropdown = gr.Dropdown(choices=language_options, label="Target Language", value="fr")
|
109 |
+
model_size_dropdown = gr.Dropdown(choices=model_size_options, label="Model Size", value="large-v2") # Model size dropdown
|
110 |
transcribe_button = gr.Button("Transcribe Video")
|
111 |
translate_button = gr.Button("Translate Subtitles")
|
112 |
|
113 |
output_video = gr.Video(label="Processed Video")
|
114 |
output_srt = gr.File(label="Subtitles File (.srt)")
|
115 |
|
116 |
+
def transcribe_and_add_subtitles(video_file, model_size):
|
117 |
+
transcription = transcribe(video_file, model_size)
|
118 |
srt_path = text_to_srt(transcription)
|
119 |
output_video_path = add_subtitle_to_video(video_file, srt_path, subtitle_language="eng", soft_subtitle=False)
|
120 |
return output_video_path, srt_path
|
121 |
|
122 |
+
def translate_subtitles_and_add_to_video(video_file, source_language_code, target_language_code, model_size):
|
123 |
+
transcription = transcribe(video_file, model_size)
|
124 |
srt_path = text_to_srt(transcription)
|
125 |
translated_srt_path = translate_srt(srt_path, source_language_code, target_language_code)
|
126 |
output_video_path = add_subtitle_to_video(video_file, translated_srt_path, target_language_code, soft_subtitle=False)
|
127 |
return output_video_path, translated_srt_path
|
128 |
|
129 |
+
transcribe_button.click(transcribe_and_add_subtitles, inputs=[video_file, model_size_dropdown], outputs=[output_video, output_srt])
|
130 |
+
translate_button.click(translate_subtitles_and_add_to_video, inputs=[video_file, source_language_dropdown, target_language_dropdown, model_size_dropdown], outputs=[output_video, output_srt])
|
131 |
|
132 |
# Lancement de l'application
|
133 |
blocks_app.launch()
|