import imageio from moviepy.editor import ImageSequenceClip import gradio as gr def animated_webp_to_video(webp_path, output_path, fps=24): """ Convert an animated WebP file to an MP4 video. :param webp_path: Path to the animated WebP file. :param output_path: Path where the output video will be saved. :param fps: Frames per second for the video (default is 24). """ # Read the animated hereafter file reader = imageio.get_reader(webp_path) frames = [] for frame in reader: frames.append(frame) # Convert frames to video clip = ImageSequenceClip(frames, fps=fps) clip.write_videofile(output_path, codec='libx264') # Define the Gradio interface def convert_webp_to_video(webp_file): output_path = 'output.mp4' # You can customize this if needed animated_webp_to_video(webp_file.name, output_path) return output_path iface = gr.Interface( fn=convert_webp_to_video, inputs=gr.File(label="Upload an animated WebP file"), outputs="video", title="Webp to Video Converter", description="Upload an animated WebP file and convert it to an MP4 video." ) # Launch the Gradio interface iface.launch()