Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -99,48 +99,33 @@ def add_subtitle_to_video(input_video, subtitle_file, subtitle_language, soft_su
|
|
99 |
ffmpeg.run(stream, overwrite_output=True)
|
100 |
return output_video
|
101 |
|
102 |
-
#
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
description="Automatically transcribe the audio from your video into subtitles and add them to the video."
|
130 |
-
)
|
131 |
-
|
132 |
-
translation_interface = gr.Interface(
|
133 |
-
fn=translate_video,
|
134 |
-
inputs=[file_input, source_language_dropdown, target_language_dropdown],
|
135 |
-
outputs=[gr.Video(label="Video with Translated Subtitles"), gr.File(label="Translated Subtitles (.srt)")],
|
136 |
-
title="Video Translation",
|
137 |
-
description="Translate the subtitles of your video into another language and add them to the video."
|
138 |
-
)
|
139 |
-
|
140 |
-
tabs = gr.Tabs([
|
141 |
-
gr.Tab(transcription_interface, label="Transcribe"),
|
142 |
-
gr.Tab(translation_interface, label="Translate")
|
143 |
-
])
|
144 |
|
145 |
# Lancement de l'application
|
146 |
-
|
|
|
99 |
ffmpeg.run(stream, overwrite_output=True)
|
100 |
return output_video
|
101 |
|
102 |
+
# Initialisation de Gradio Blocks
|
103 |
+
with gr.Blocks() as blocks_app:
|
104 |
+
with gr.Row():
|
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.name, "tiny")
|
116 |
+
srt_path = text_to_srt(transcription)
|
117 |
+
output_video_path = add_subtitle_to_video(video_file.name, 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.name, "tiny")
|
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.name, 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()
|