Lenylvt commited on
Commit
7f1b106
·
verified ·
1 Parent(s): fc9312a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +32 -15
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
- gr.Markdown("# Text to SRT Converter")
45
- gr.Markdown("### ⚠️ For information, the process can be really long.")
 
46
 
47
- with gr.Group():
48
- video_input = gr.Video(label="Video", interactive=True)
49
- subtitle_input = gr.File(label="Subtitle", file_types=[".srt", ".vtt"])
50
- subtitle_language_input = gr.Textbox(label="Subtitle Language (ISO 639-1 code, 'en' for English)")
51
- submit_button = gr.Button("Submit")
 
 
 
52
 
53
- output_video = gr.Video(label="Processed Video")
 
 
 
 
 
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()