Spaces:
Runtime error
Runtime error
| import gradio as gr | |
| import time | |
| import random | |
| import os | |
| def generate_video_from_image( | |
| image, | |
| prompt, | |
| negative_prompt, | |
| num_frames, | |
| guidance_scale, | |
| inference_steps, | |
| seed, | |
| use_spicy_mode, | |
| spicy_intensity, | |
| progress=gr.Progress() | |
| ): | |
| """Simulate video generation from image using Wan 2.2 model with spicy settings""" | |
| # Validate inputs | |
| if image is None: | |
| raise gr.Error("Please upload an image to generate a video.") | |
| if not prompt.strip(): | |
| raise gr.Error("Please enter a prompt for your video generation.") | |
| # Set seed for reproducibility | |
| if seed == -1: | |
| seed = random.randint(0, 2147483647) | |
| # Simulate processing steps | |
| progress(0, desc="Initializing Wan 2.2 Spicy mode...") | |
| time.sleep(0.5) | |
| progress(0.1, desc="Loading model components...") | |
| time.sleep(0.8) | |
| progress(0.2, desc="Preparing image embeddings...") | |
| time.sleep(0.6) | |
| # Simulate video generation progress | |
| progress(0.3, desc=f"Running {inference_steps} inference steps...") | |
| for i in range(1, inference_steps + 1): | |
| time.sleep(0.15) | |
| progress_rate = 0.3 + (i / inference_steps) * 0.6 | |
| progress(progress_rate, desc=f"Step {i}/{inference_steps} completed...") | |
| # Apply spicy mode effects | |
| if use_spicy_mode: | |
| progress(0.9, desc=f"Applying spicy mode with intensity {spicy_intensity}...") | |
| time.sleep(1.2) | |
| progress(1.0, desc="Finalizing video output...") | |
| time.sleep(0.3) | |
| # Create a fake video file path (in a real app, this would be the generated video) | |
| # For demo purposes, we'll use a placeholder video | |
| video_path = "https://gradio-builds.s3.amazonaws.com/assets/cheetah-003.jpg" | |
| return { | |
| "video": video_path, | |
| "stats": f"✅ Video generated successfully!\n\n" | |
| f"• Prompt: {prompt}\n" | |
| f"• Frames: {num_frames}\n" | |
| f"• Guidance Scale: {guidance_scale}\n" | |
| f"• Inference Steps: {inference_steps}\n" | |
| f"• Seed: {seed}\n" | |
| f"• Spicy Mode: {'Enabled' if use_spicy_mode else 'Disabled'}\n" | |
| f"• Spicy Intensity: {spicy_intensity if use_spicy_mode else 'N/A'}" | |
| } | |
| # Create the Gradio interface | |
| with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="purple")) as demo: | |
| # Header with title and description | |
| gr.Markdown( | |
| """ | |
| <div style="text-align: center; margin-bottom: 30px;"> | |
| <h1 style="color: #6a1b9a; font-size: 3.2em; margin-bottom: 10px;">Wan 2.2 Spicy Image-to-Video Generator</h1> | |
| <p style="font-size: 1.2em; color: #4a4a4a; max-width: 800px; margin: 0 auto;"> | |
| Transform your images into stunning videos using the advanced Wan 2.2 model with spicy enhancements. | |
| Perfect for creative content, animations, and visual storytelling. | |
| </p> | |
| <div style="margin-top: 20px;"> | |
| <a href="https://huggingface.co/spaces/akhaliq/anycoder" target="_blank" style="text-decoration: none; background-color: #6a1b9a; color: white; padding: 10px 20px; border-radius: 20px; font-weight: bold; font-size: 0.9em;">Built with anycoder</a> | |
| </div> | |
| </div> | |
| """ | |
| ) | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| # Input section | |
| gr.Markdown("### 🎨 Input Settings") | |
| image_input = gr.Image( | |
| label="Upload Image", | |
| type="pil", | |
| height=300, | |
| sources=["upload", "webcam", "clipboard"] | |
| ) | |
| prompt_input = gr.Textbox( | |
| label="Prompt", | |
| placeholder="Describe the video you want to generate (e.g., 'A cat walking in a garden with阳光, cinematic, high quality')", | |
| lines=3 | |
| ) | |
| negative_prompt = gr.Textbox( | |
| label="Negative Prompt", | |
| placeholder="Elements to avoid in the video (e.g., 'blurry, low quality, distorted')", | |
| lines=2 | |
| ) | |
| with gr.Accordion("Advanced Settings", open=False): | |
| num_frames = gr.Slider( | |
| label="Number of Frames", | |
| minimum=8, | |
| maximum=64, | |
| value=24, | |
| step=1, | |
| info="Number of frames in the generated video" | |
| ) | |
| guidance_scale = gr.Slider( | |
| label="Guidance Scale", | |
| minimum=1.0, | |
| maximum=20.0, | |
| value=7.5, | |
| step=0.5, | |
| info="How closely the video follows your prompt" | |
| ) | |
| inference_steps = gr.Slider( | |
| label="Inference Steps", | |
| minimum=10, | |
| maximum=100, | |
| value=30, | |
| step=5, | |
| info="Number of denoising steps (higher = better quality but slower)" | |
| ) | |
| seed = gr.Number( | |
| label="Seed", | |
| value=-1, | |
| precision=0, | |
| info="Set to -1 for random seed" | |
| ) | |
| with gr.Accordion("🔥 Spicy Mode Settings", open=True): | |
| use_spicy_mode = gr.Checkbox( | |
| label="Enable Spicy Mode", | |
| value=True, | |
| info="Activate enhanced generation with spicy effects" | |
| ) | |
| spicy_intensity = gr.Slider( | |
| label="Spicy Intensity", | |
| minimum=1, | |
| maximum=10, | |
| value=7, | |
| step=1, | |
| info="How spicy should the video be? (1-10)" | |
| ) | |
| spicy_effects = gr.CheckboxGroup( | |
| label="Spicy Effects", | |
| choices=[ | |
| "Fast Motion", | |
| "High Contrast", | |
| "Color Boost", | |
| "Dynamic Transitions", | |
| "Enhanced Details", | |
| "Cinematic Effects" | |
| ], | |
| value=["High Contrast", "Color Boost", "Dynamic Transitions"], | |
| info="Select which spicy effects to apply" | |
| ) | |
| generate_btn = gr.Button( | |
| "🎬 Generate Video", | |
| variant="primary", | |
| size="lg" | |
| ) | |
| with gr.Column(scale=1): | |
| # Output section | |
| gr.Markdown("### 🎥 Generated Output") | |
| video_output = gr.Video( | |
| label="Generated Video", | |
| height=400, | |
| autoplay=True | |
| ) | |
| stats_output = gr.Textbox( | |
| label="Generation Statistics", | |
| lines=10, | |
| show_copy_button=True | |
| ) | |
| # Examples | |
| gr.Markdown("### 💡 Examples") | |
| with gr.Row(): | |
| example1_btn = gr.Button("Nature Scene") | |
| example2_btn = gr.Button("Urban Motion") | |
| example3_btn = gr.Button("Abstract Art") | |
| # Example functions | |
| def set_example1(): | |
| return { | |
| prompt_input: "A serene landscape with flowing river and mountains at sunset, cinematic lighting", | |
| use_spicy_mode: True, | |
| spicy_intensity: 6, | |
| spicy_effects: ["Color Boost", "Cinematic Effects"] | |
| } | |
| def set_example2(): | |
| return { | |
| prompt_input: "Time-lapse of city streets at night with neon lights and moving cars, cyberpunk style", | |
| use_spicy_mode: True, | |
| spicy_intensity: 8, | |
| spicy_effects: ["Fast Motion", "High Contrast", "Color Boost"] | |
| } | |
| def set_example3(): | |
| return { | |
| prompt_input: "Abstract fluid art with vibrant colors swirling and merging, macro perspective", | |
| use_spicy_mode: False, | |
| spicy_intensity: 3, | |
| spicy_effects: ["Enhanced Details"] | |
| } | |
| example1_btn.click(set_example1, outputs=[prompt_input, use_spicy_mode, spicy_intensity, spicy_effects]) | |
| example2_btn.click(set_example2, outputs=[prompt_input, use_spicy_mode, spicy_intensity, spicy_effects]) | |
| example3_btn.click(set_example3, outputs=[prompt_input, use_spicy_mode, spicy_intensity, spicy_effects]) | |
| # Footer with information | |
| gr.Markdown( | |
| """ | |
| <div style="text-align: center; margin-top: 30px; padding: 20px; background-color: #f5f5f5; border-radius: 10px;"> | |
| <h3>About This Demo</h3> | |
| <p>This application uses the Wan 2.2 model with spicy enhancements to generate videos from images.</p> | |
| <p><strong>Spicy Mode</strong> applies creative enhancements like enhanced colors, dynamic transitions, and more.</p> | |
| <p><em>Note: This is a demonstration. In a real implementation, the video would be generated by the Wan 2.2 model.</em></p> | |
| </div> | |
| """ | |
| ) | |
| # Event listener for generate button | |
| generate_btn.click( | |
| fn=generate_video_from_image, | |
| inputs=[ | |
| image_input, | |
| prompt_input, | |
| negative_prompt, | |
| num_frames, | |
| guidance_scale, | |
| inference_steps, | |
| seed, | |
| use_spicy_mode, | |
| spicy_intensity | |
| ], | |
| outputs=[video_output, stats_output], | |
| api_visibility="public" | |
| ) | |
| # Launch the app with modern theme | |
| demo.launch( | |
| theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="purple"), | |
| footer_links=[{"label": "Wan 2.2 Model", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}] | |
| ) |