Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -16,18 +16,11 @@ def add_subtitle_to_video(input_video, subtitle_file, subtitle_language, soft_su
|
|
16 |
output_video = f"/tmp/output-{input_video_name}.mp4"
|
17 |
subtitle_track_title = os.path.splitext(os.path.basename(subtitle_file))[0]
|
18 |
|
19 |
-
if soft_subtitle:
|
20 |
stream = ffmpeg.output(
|
21 |
video_input_stream, subtitle_input_stream, output_video,
|
22 |
**{"c": "copy", "c:s": "mov_text"},
|
23 |
**{"metadata:s:s:0": f"language={subtitle_language}",
|
24 |
"metadata:s:s:0": f"title={subtitle_track_title}"}
|
25 |
-
)
|
26 |
-
else:
|
27 |
-
stream = ffmpeg.output(
|
28 |
-
video_input_stream, output_video,
|
29 |
-
vf=f"subtitles={subtitle_file}"
|
30 |
-
)
|
31 |
|
32 |
ffmpeg.run(stream, overwrite_output=True)
|
33 |
return output_video
|
@@ -41,18 +34,42 @@ def video_demo(video, subtitle, subtitle_type, subtitle_language):
|
|
41 |
return video
|
42 |
|
43 |
with gr.Blocks() as demo:
|
44 |
-
|
45 |
-
gr.Markdown("
|
|
|
46 |
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
|
|
|
|
|
|
52 |
|
53 |
-
|
|
|
|
|
|
|
|
|
|
|
54 |
|
|
|
55 |
submit_button.click(fn=video_demo, inputs=[video_input, subtitle_input, subtitle_language_input], outputs=output_video)
|
56 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
if __name__ == "__main__":
|
58 |
demo.launch()
|
|
|
16 |
output_video = f"/tmp/output-{input_video_name}.mp4"
|
17 |
subtitle_track_title = os.path.splitext(os.path.basename(subtitle_file))[0]
|
18 |
|
|
|
19 |
stream = ffmpeg.output(
|
20 |
video_input_stream, subtitle_input_stream, output_video,
|
21 |
**{"c": "copy", "c:s": "mov_text"},
|
22 |
**{"metadata:s:s:0": f"language={subtitle_language}",
|
23 |
"metadata:s:s:0": f"title={subtitle_track_title}"}
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
ffmpeg.run(stream, overwrite_output=True)
|
26 |
return output_video
|
|
|
34 |
return video
|
35 |
|
36 |
with gr.Blocks() as demo:
|
37 |
+
# Header and information
|
38 |
+
gr.Markdown("<h1 style='text-align: center;'>Text to SRT Converter</h1>", unsafe_allow_html=True)
|
39 |
+
gr.Markdown("<h3 style='text-align: center; color: #FF5733;'>⚠️ Note: The processing can take some time depending on the video length and size.</h3>", unsafe_allow_html=True)
|
40 |
|
41 |
+
# Inputs section
|
42 |
+
with gr.Row():
|
43 |
+
with gr.Column(scale=1):
|
44 |
+
video_input = gr.Video(label="Upload Video")
|
45 |
+
with gr.Column(scale=1):
|
46 |
+
subtitle_input = gr.File(label="Upload Subtitle File", file_types=[".srt", ".vtt"])
|
47 |
+
with gr.Column(scale=1):
|
48 |
+
subtitle_language_input = gr.Textbox(label="Subtitle Language (ISO 639-1, e.g., 'en')")
|
49 |
|
50 |
+
# Submit button
|
51 |
+
with gr.Row():
|
52 |
+
submit_button = gr.Button("Process Video", elem_id="process_button")
|
53 |
+
|
54 |
+
# Output video
|
55 |
+
output_video = gr.Video(label="Processed Video", elem_id="output_video")
|
56 |
|
57 |
+
# Button click action
|
58 |
submit_button.click(fn=video_demo, inputs=[video_input, subtitle_input, subtitle_language_input], outputs=output_video)
|
59 |
|
60 |
+
# Custom CSS to enhance visual appearance
|
61 |
+
demo.style(
|
62 |
+
'''
|
63 |
+
<style>
|
64 |
+
#process_button { background-color: #4CAF50; color: white; border: none; padding: 15px 32px; text-align: center; text-decoration: none; display: inline-block; font-size: 16px; margin: 4px 2px; cursor: pointer; border-radius: 8px; }
|
65 |
+
#output_video { border: 2px solid #4CAF50; border-radius: 8px; }
|
66 |
+
.gr-column { padding: 10px; }
|
67 |
+
.gr-row { justify-content: center; margin-top: 20px; }
|
68 |
+
</style>
|
69 |
+
''',
|
70 |
+
unsafe_allow_html=True
|
71 |
+
)
|
72 |
+
|
73 |
+
|
74 |
if __name__ == "__main__":
|
75 |
demo.launch()
|