import gradio as gr from moviepy.editor import * from PIL import ImageFont, ImageDraw, Image def edit_video(video_file, name, author, font, filter): # Load the video clip = VideoFileClip(video_file) # Apply the chosen filter clip = eval(f"clip.{filter}()") # Load the font based on user input font_path = f"{font}.ttf" font_size = clip.size[0] // 10 font = ImageFont.truetype(font_path, font_size) # Create an image with the author text author_text = f"Author: {author}" author_image = Image.new('RGB', (clip.w//2, clip.h//8), (0, 0, 0)) author_draw = ImageDraw.Draw(author_image) author_draw.text((10, 10), author_text, font=font, fill=(255, 255, 255)) # Create an image with the bigger text bigger_text = f"Author: {author}" bigger_image = Image.new('RGB', (clip.w//2, clip.h//4), (0, 0, 0)) bigger_draw = ImageDraw.Draw(bigger_image) bigger_draw.text((10, 10), bigger_text, font=font, fill=(255, 255, 255)) # Create a composite video with the texts text_clip1 = ImageClip(author_image).set_duration(4).set_position(("right", "bottom")) text_clip2 = ImageClip(bigger_image).set_duration(4).set_position(("right", "bottom")) composite_clip = CompositeVideoClip([clip, text_clip1, text_clip2]) # Save the edited video output_file = f"{name}_edited.mp4" composite_clip.write_videofile(output_file, codec='libx264') return output_file def video_editor(name, author, font, filter, video_file): edited_video = edit_video(video_file, name, author, font, filter) return edited_video # Define the inputs and outputs for Gradio app inputs = [ gr.inputs.Textbox(label="Video Name"), gr.inputs.Textbox(label="Author Name"), gr.inputs.Radio(["Arial", "Barbie", "MrBeast", "OptiAgle"], label="Font"), gr.inputs.Radio(["blur", "rotate", "resize", "mirror"], label="Filter"), gr.inputs.File(label="Video File") ] outputs = gr.outputs.File(label="Edited Video") # Create a Gradio app interface grapp = gr.Interface(fn=video_editor, inputs=inputs, outputs=outputs, capture_session=True) # Run the Gradio app grapp.launch()