import gradio as gr import torch from diffusers import CogVideoXPipeline from diffusers.utils import export_to_video import os import tempfile import uuid # ============================================ # DoThatShi Video Generator - Hugging Face Space # ============================================ # Model configuration - Using CogVideoX (open source, free) MODEL_ID = "THUDM/CogVideoX-2b" # 2B parameter version, lighter for free tier # Custom CSS for DoThatShi branding custom_css = """ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;600;800&display=swap'); .gradio-container { font-family: 'Inter', sans-serif !important; background: linear-gradient(135deg, #0f0f23 0%, #1a1a2e 50%, #16213e 100%) !important; min-height: 100vh; } .header { text-align: center; padding: 2rem 0; margin-bottom: 1rem; } .brand-title { font-size: 3rem; font-weight: 800; background: linear-gradient(90deg, #ff6b6b, #feca57, #48dbfb, #ff9ff3); -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text; margin-bottom: 0.5rem; } .brand-subtitle { color: #a0a0a0; font-size: 1.1rem; font-weight: 400; } .generate-btn { background: linear-gradient(90deg, #ff6b6b, #feca57) !important; color: #0f0f23 !important; font-weight: 700 !important; border: none !important; border-radius: 12px !important; padding: 12px 32px !important; font-size: 1.1rem !important; transition: all 0.3s ease !important; } .generate-btn:hover { transform: translateY(-2px); box-shadow: 0 8px 25px rgba(255, 107, 107, 0.4) !important; } .input-box { border-radius: 12px !important; border: 2px solid #2d2d44 !important; background: #1a1a2e !important; color: #ffffff !important; } .input-box:focus { border-color: #ff6b6b !important; box-shadow: 0 0 15px rgba(255, 107, 107, 0.3) !important; } .video-output { border-radius: 16px !important; overflow: hidden !important; border: 2px solid #2d2d44 !important; } .settings-panel { background: rgba(26, 26, 46, 0.8) !important; border-radius: 16px !important; padding: 1.5rem !important; border: 1px solid #2d2d44 !important; } .footer { text-align: center; padding: 2rem; color: #666; font-size: 0.9rem; } .status-badge { display: inline-block; padding: 4px 12px; border-radius: 20px; font-size: 0.85rem; font-weight: 600; margin-top: 10px; } .status-ready { background: rgba(72, 219, 251, 0.2); color: #48dbfb; border: 1px solid #48dbfb; } .status-generating { background: rgba(254, 202, 87, 0.2); color: #feca57; border: 1px solid #feca57; } """ # Global pipeline (loaded once) pipe = None def load_pipeline(): """Load the video generation pipeline""" global pipe if pipe is None: print("🎬 Loading DoThatShi Video Generator...") pipe = CogVideoXPipeline.from_pretrained( MODEL_ID, torch_dtype=torch.float16 if torch.cuda.is_available() else torch.float32 ) if torch.cuda.is_available(): pipe.to("cuda") # Enable memory efficient attention pipe.enable_sequential_cpu_offload() else: pipe.to("cpu") print("⚠️ Running on CPU - generation will be slower") return pipe def generate_video( prompt, negative_prompt, num_frames, fps, guidance_scale, num_inference_steps, seed, width, height ): """Generate video from text prompt""" # Load pipeline pipeline = load_pipeline() # Set seed for reproducibility if seed == -1: seed = torch.randint(0, 2**32, (1,)).item() generator = torch.Generator(device="cuda" if torch.cuda.is_available() else "cpu").manual_seed(seed) # Generate video print(f"🎨 Generating: {prompt[:50]}...") video = pipeline( prompt=prompt, negative_prompt=negative_prompt, num_frames=num_frames, num_inference_steps=num_inference_steps, guidance_scale=guidance_scale, generator=generator, width=width, height=height, ).frames[0] # Export to file output_path = os.path.join(tempfile.gettempdir(), f"dothatshi_{uuid.uuid4().hex[:8]}.mp4") export_to_video(video, output_path, fps=fps) return output_path, f"✅ Generated with seed: {seed}" # ============================================ # Gradio Interface # ============================================ with gr.Blocks(css=custom_css, title="DoThatShi Video Generator") as demo: # Header gr.HTML("""

DoThatShi

AI Video Generator — Create stunning videos from text

🚀 Ready to Generate
""") with gr.Row(): # Left Panel - Controls with gr.Column(scale=1): gr.HTML('
') prompt = gr.Textbox( label="📝 Your Video Prompt", placeholder="A cinematic shot of a futuristic city at sunset, neon lights reflecting on wet streets...", lines=4, elem_classes=["input-box"] ) negative_prompt = gr.Textbox( label="🚫 Negative Prompt (what to avoid)", value="blurry, low quality, distorted, ugly, deformed", lines=2, elem_classes=["input-box"] ) with gr.Row(): width = gr.Slider(256, 1280, value=720, step=64, label="Width") height = gr.Slider(256, 1280, value=480, step=64, label="Height") with gr.Row(): num_frames = gr.Slider(8, 49, value=16, step=1, label="Frames") fps = gr.Slider(1, 30, value=8, step=1, label="FPS") with gr.Row(): guidance_scale = gr.Slider(1, 20, value=6, step=0.5, label="Guidance Scale") num_inference_steps = gr.Slider(10, 100, value=50, step=5, label="Steps") seed = gr.Number(value=-1, label="🎲 Seed (-1 for random)", precision=0) generate_btn = gr.Button( "✨ Generate Video", variant="primary", elem_classes=["generate-btn"] ) gr.HTML('
') # Right Panel - Output with gr.Column(scale=1): video_output = gr.Video( label="🎬 Generated Video", elem_classes=["video-output"], autoplay=True ) status_text = gr.Textbox( label="Status", interactive=False, value="Click 'Generate Video' to create your first DoThatShi video!" ) # Tips section gr.HTML("""

💡 Pro Tips for Better Videos

""") # Examples gr.Examples( examples=[ ["A serene Japanese garden with cherry blossoms falling in slow motion, soft pink petals dancing in the wind, golden sunlight filtering through", "blurry, low quality", 16, 8, 6, 50, -1, 720, 480], ["Cyberpunk street market at night, holographic signs, steam rising from food stalls, people in futuristic clothing walking by", "distorted, ugly", 24, 12, 7, 50, 42, 720, 480], ["Majestic eagle soaring over snow-capped mountains, dramatic clouds, cinematic wide shot, golden hour lighting", "blurry, dark", 16, 8, 6, 50, -1, 720, 480], ], inputs=[prompt, negative_prompt, num_frames, fps, guidance_scale, num_inference_steps, seed, width, height], label="🎯 Quick Start Examples" ) # Footer gr.HTML(""" """) # Event handler generate_btn.click( fn=generate_video, inputs=[prompt, negative_prompt, num_frames, fps, guidance_scale, num_inference_steps, seed, width, height], outputs=[video_output, status_text] ) # Launch if __name__ == "__main__": demo.launch()