Lenylvt commited on
Commit
b7a9c79
1 Parent(s): eb5718c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -43
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
- # Fonction de transcription pour Gradio avec ajout de sous-titres à la vidéo
103
- def transcribe_video(video_file):
104
- transcription = transcribe(video_file.name, "tiny")
105
- srt_path = text_to_srt(transcription)
106
- # Ajouter les sous-titres à la vidéo
107
- output_video_path = add_subtitle_to_video(video_file.name, srt_path, subtitle_language="eng", soft_subtitle=False)
108
- return output_video_path, srt_path
109
-
110
- # Fonction de traduction pour Gradio qui utilise maintenant add_subtitle_to_video
111
- def translate_video(video_file, source_language_code, target_language_code):
112
- transcription = transcribe(video_file.name, "tiny")
113
- srt_path = text_to_srt(transcription)
114
- translated_srt_path = translate_srt(srt_path, source_language_code, target_language_code)
115
- # Ajoutez les sous-titres traduits à la vidéo
116
- output_video_path = add_subtitle_to_video(video_file.name, translated_srt_path, target_language_code, soft_subtitle=False)
117
- return output_video_path, translated_srt_path
118
-
119
- # Interface Gradio
120
- file_input = gr.Video(label="Video File")
121
- source_language_dropdown = gr.Dropdown(choices=language_options, label="Source Language")
122
- target_language_dropdown = gr.Dropdown(choices=language_options, label="Target Language")
123
-
124
- transcription_interface = gr.Interface(
125
- fn=transcribe_video,
126
- inputs=file_input,
127
- outputs=[gr.Video(label="Video with Subtitles"), gr.File(label="Transcription File (.srt)")],
128
- title="Video Transcription",
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
- tabs.launch()
 
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()