import gradio as gr from moviepy.editor import VideoFileClip import random import os funny_messages = [ "Converting your video with pure magic... ✨", "Baking digital cookies for the conversion elves... 🍪", "Teaching pixels to do the cha-cha slide... 💃", "Convincing bits to switch teams... ⚽", "Defragmenting your video's existential crisis... 🤔", "Polishing every pixel for maximum shine... 💎", "Making your video do a quick wardrobe change... 👗", "Negotiating with the codec goblins... 🧙", "Telling your video to hold still... 📸", "Whispering sweet nothings to the file system... 💌" ] def convert_video(input_video, output_format, progress=gr.Progress(track_tqdm=True)): if input_video is None: raise gr.Error("Please upload a video first!") progress(0, random.choice(funny_messages)) clip = VideoFileClip(input_video) output_file = f"converted_output.{output_format}" # Simulate progress with funny messages for i in range(1, 5): progress(i/5, random.choice(funny_messages)) # Set codec based on format codec = None if output_format == "mp4": codec = "libx264" elif output_format == "webm": codec = "libvpx" elif output_format == "avi": codec = "png" elif output_format == "mov": codec = "libx264" elif output_format == "wmv": codec = "libx264" # WMV support is limited; fallback to mp4 codec for demo try: clip.write_videofile(output_file, codec=codec, audio_codec="aac" if output_format in ["mp4", "mov"] else None, verbose=False, logger=None) except Exception as e: raise gr.Error(f"Conversion failed: {e}") progress(1, "Done! Enjoy your freshly converted video 🎉") return output_file css = """ body { background: linear-gradient(120deg, #23a6d5 0%, #e73c7e 100%); background-size: 200% 200%; animation: gradientBG 10s ease-in-out infinite; } @keyframes gradientBG { 0% {background-position: 0% 50%;} 50% {background-position: 100% 50%;} 100% {background-position: 0% 50%;} } .gradio-container { border-radius: 18px !important; box-shadow: 0 8px 32px 0 rgba(31, 38, 135, 0.37) !important; background: rgba(255,255,255,0.15) !important; backdrop-filter: blur(8px) !important; border: 1px solid rgba(255,255,255,0.18) !important; } h1, .gr-markdown { color: #fff !important; text-shadow: 2px 2px 8px rgba(0,0,0,0.3); font-family: 'Segoe UI', 'Arial Rounded MT Bold', Arial, sans-serif; } .gr-button { background: linear-gradient(90deg, #ff6b6b 0%, #4ecdc4 100%) !important; color: #fff !important; border: none !important; border-radius: 8px !important; font-size: 1.1em !important; transition: transform 0.2s; } .gr-button:hover { transform: scale(1.05) rotate(-2deg); box-shadow: 0 4px 12px rgba(78,205,196,0.25); } .gr-video { border-radius: 12px !important; box-shadow: 0 2px 12px rgba(35,166,213,0.12); background: rgba(255,255,255,0.1) !important; } .gr-dropdown { border-radius: 8px !important; background: rgba(255,255,255,0.2) !important; color: #333 !important; } """ with gr.Blocks(css=css, theme=gr.themes.Glass()) as demo: gr.Markdown( """