Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -374,22 +374,36 @@ def process_video(url, type):
|
|
| 374 |
srt_string = read_srt_file(subtitle_file)
|
| 375 |
google_translate = translate_text(api_key, source_language, target_language, srt_string)
|
| 376 |
write_google(google_translate)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 377 |
video = VideoFileClip(input_video)
|
| 378 |
audio = AudioFileClip(input_audio)
|
| 379 |
video = video.with_audio(audio)
|
| 380 |
print(video)
|
| 381 |
subtitles = pysrt.open("google_translate.srt", encoding="utf-8")
|
| 382 |
output_video_file = input_video_name + '_subtitled' + ".mp4"
|
| 383 |
-
subtitle_clips = create_subtitle_clips(subtitles, video.size,
|
| 384 |
final_video = CompositeVideoClip([video] + subtitle_clips)
|
| 385 |
final_video.write_videofile(output_video_file, codec="libx264", audio_codec="aac", logger=None)
|
| 386 |
print('final')
|
| 387 |
-
google = read_srt_file("google_translate.srt")
|
| 388 |
-
return output_video_file, google
|
| 389 |
-
|
| 390 |
-
#def download_file(file_path):
|
| 391 |
-
# return gr.File.update(file_path)
|
| 392 |
|
| 393 |
-
|
| 394 |
-
|
| 395 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 374 |
srt_string = read_srt_file(subtitle_file)
|
| 375 |
google_translate = translate_text(api_key, source_language, target_language, srt_string)
|
| 376 |
write_google(google_translate)
|
| 377 |
+
srt = read_srt_file("google_translate.srt")
|
| 378 |
+
return srt, input_video
|
| 379 |
+
|
| 380 |
+
def video_edit(srt, input_video, input_audio= "audio.mp3"):
|
| 381 |
+
|
| 382 |
+
input_video_name = input_video.replace(".mp4", "")
|
| 383 |
video = VideoFileClip(input_video)
|
| 384 |
audio = AudioFileClip(input_audio)
|
| 385 |
video = video.with_audio(audio)
|
| 386 |
print(video)
|
| 387 |
subtitles = pysrt.open("google_translate.srt", encoding="utf-8")
|
| 388 |
output_video_file = input_video_name + '_subtitled' + ".mp4"
|
| 389 |
+
subtitle_clips = create_subtitle_clips(subtitles, video.size, 32, 'arial.ttf', 'white', False)
|
| 390 |
final_video = CompositeVideoClip([video] + subtitle_clips)
|
| 391 |
final_video.write_videofile(output_video_file, codec="libx264", audio_codec="aac", logger=None)
|
| 392 |
print('final')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 393 |
|
| 394 |
+
|
| 395 |
+
with gr.Blocks() as demo:
|
| 396 |
+
gr.Markdown("Start typing below and then click **Run** to see the output.")
|
| 397 |
+
with gr.Row():
|
| 398 |
+
inp = gr.Textbox(placeholder="Enter URL or upload")
|
| 399 |
+
drp = gr.Dropdown(["insta", "youtube"])
|
| 400 |
+
btn = gr.Button("transcribe")
|
| 401 |
+
out = gr.Textbox(interactive=True)
|
| 402 |
+
video_path_output = gr.Textbox(label="Video Path", visible=False)
|
| 403 |
+
btn.click(fn=process_video, inputs=[inp, drp], outputs=[out, video_path_output])
|
| 404 |
+
with gr.Row():
|
| 405 |
+
vid_out = gr.Video()
|
| 406 |
+
btn2 = gr.Button("transcribe")
|
| 407 |
+
btn2.click(video_edit, [out, video_path_output], vid_out)
|
| 408 |
+
|
| 409 |
+
demo.launch(debug=True)
|