import gradio as gr import subprocess import os def combine_video_subtitle(video_file, subtitle_file): # Output video file name output_file = "output_combined.mp4" # Run ffmpeg command to combine video and subtitle cmd = [ "ffmpeg", "-i", video_file.name, "-i", subtitle_file.name, "-c:v", "copy", "-c:a", "copy", "-c:s", "mov_text", "-map", "0:v:0", "-map", "0:a:0", "-map", "1", output_file ] subprocess.run(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return output_file # Create Gradio interface inputs = [ gr.inputs.File(label="Video File"), gr.inputs.File(label="Subtitle File") ] outputs = gr.outputs.File(label="Combined Video with Subtitle") title = "Video Subtitle Combiner" description = "Combine a video file and a subtitle file using ffmpeg." iface = gr.Interface(fn=combine_video_subtitle, inputs=inputs, outputs=outputs, title=title, description=description) # Launch the Gradio interface iface.launch()