# Patch to fix 'ANTIALIAS' attribute error in Pillow 10.0.0+ from PIL import Image from pkg_resources import parse_version if parse_version(Image.__version__) >= parse_version('10.0.0'): Image.ANTIALIAS = Image.Resampling.LANCZOS import gradio as gr from moviepy.editor import * import os def process_videos(video_paths, logo_path, outro_path, logo_size): output_paths = [] # Loop through each uploaded video path for i, video_path in enumerate(video_paths): main_video = VideoFileClip(video_path.name) # Use .name to get the file path # Position the logo in the bottom right corner logo = (ImageClip(logo_path) .set_duration(main_video.duration) .resize(height=int(logo_size)) .margin(right=8, bottom=8, opacity=0) .set_pos(("right", "bottom"))) outro_video = VideoFileClip(outro_path) # Add the watermark to the main video final_video = CompositeVideoClip([main_video, logo]) # Concatenate the watermarked video with the outro final_video = concatenate_videoclips([final_video, outro_video]) # Create a unique output path for each video output_path = f"final_video_{i}.mp4" final_video.write_videofile(output_path, codec="libx264") output_paths.append(output_path) return output_paths # Define the Gradio interface with gr.Blocks() as demo: gr.Markdown("## Bulk Video Watermarker and Outro Adder") with gr.Row(): with gr.Column(): # Use gr.File for multiple uploads videos_input = gr.File(label="Upload Your Videos", file_types=["video"], file_count="multiple") logo_input = gr.Image(label="Upload Your Logo", type="filepath") outro_input = gr.Video(label="Upload Your Outro") logo_size = gr.Slider(label="Logo Size", minimum=50, maximum=500, step=10, value=100) process_button = gr.Button("Process Videos") with gr.Column(): # Use gr.Gallery to display multiple output videos video_outputs = gr.Gallery(label="Processed Videos") process_button.click( fn=process_videos, inputs=[videos_input, logo_input, outro_input, logo_size], outputs=video_outputs ) demo.launch()