Spaces:
Runtime error
Runtime error
File size: 10,344 Bytes
73547eb | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 | 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"}]
) |