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("""
AI Video Generator — Create stunning videos from text
🚀 Ready to Generate