import gradio as gr from moviepy.editor import VideoFileClip, AudioFileClip, CompositeVideoClip def video_editor(video, audio, music, width, height, output_title): # Load video and audio clips video_clip = VideoFileClip(video.name) audio_clip = AudioFileClip(audio.name) # Resize video using width and height if width and height: video_clip = video_clip.resize(newsize=(width, height)) # Add background music if provided if music is not None: music_clip = AudioFileClip(music.name) final_audio = CompositeVideoClip([audio_clip, music_clip.set_duration(video_clip.duration)]) else: final_audio = audio_clip # Combine video with the final audio final_clip = video_clip.set_audio(final_audio) # Define output file path output_file = f"{output_title}.mp4" # Write the final video file final_clip.write_videofile(output_file, codec="libx264") return output_file # Define the Gradio interface inputs = [ gr.File(label="Video File"), gr.File(label="Audio File"), gr.File(label="Background Music (Optional)"), # No optional keyword, just handle it in the function gr.Number(label="Screen Width"), gr.Number(label="Screen Height"), gr.Textbox(label="Output File Title") ] outputs = gr.File(label="Edited Video File") # Launch the Gradio interface gr.Interface(fn=video_editor, inputs=inputs, outputs=outputs, title="Simple Video Editor").launch()