Superwolff commited on
Commit
73547eb
·
verified ·
1 Parent(s): 8b19a86

Upload folder using huggingface_hub

Browse files
Files changed (2) hide show
  1. app.py +272 -0
  2. requirements.txt +1 -0
app.py ADDED
@@ -0,0 +1,272 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import time
3
+ import random
4
+ import os
5
+
6
+ def generate_video_from_image(
7
+ image,
8
+ prompt,
9
+ negative_prompt,
10
+ num_frames,
11
+ guidance_scale,
12
+ inference_steps,
13
+ seed,
14
+ use_spicy_mode,
15
+ spicy_intensity,
16
+ progress=gr.Progress()
17
+ ):
18
+ """Simulate video generation from image using Wan 2.2 model with spicy settings"""
19
+
20
+ # Validate inputs
21
+ if image is None:
22
+ raise gr.Error("Please upload an image to generate a video.")
23
+
24
+ if not prompt.strip():
25
+ raise gr.Error("Please enter a prompt for your video generation.")
26
+
27
+ # Set seed for reproducibility
28
+ if seed == -1:
29
+ seed = random.randint(0, 2147483647)
30
+
31
+ # Simulate processing steps
32
+ progress(0, desc="Initializing Wan 2.2 Spicy mode...")
33
+ time.sleep(0.5)
34
+
35
+ progress(0.1, desc="Loading model components...")
36
+ time.sleep(0.8)
37
+
38
+ progress(0.2, desc="Preparing image embeddings...")
39
+ time.sleep(0.6)
40
+
41
+ # Simulate video generation progress
42
+ progress(0.3, desc=f"Running {inference_steps} inference steps...")
43
+ for i in range(1, inference_steps + 1):
44
+ time.sleep(0.15)
45
+ progress_rate = 0.3 + (i / inference_steps) * 0.6
46
+ progress(progress_rate, desc=f"Step {i}/{inference_steps} completed...")
47
+
48
+ # Apply spicy mode effects
49
+ if use_spicy_mode:
50
+ progress(0.9, desc=f"Applying spicy mode with intensity {spicy_intensity}...")
51
+ time.sleep(1.2)
52
+
53
+ progress(1.0, desc="Finalizing video output...")
54
+ time.sleep(0.3)
55
+
56
+ # Create a fake video file path (in a real app, this would be the generated video)
57
+ # For demo purposes, we'll use a placeholder video
58
+ video_path = "https://gradio-builds.s3.amazonaws.com/assets/cheetah-003.jpg"
59
+
60
+ return {
61
+ "video": video_path,
62
+ "stats": f"✅ Video generated successfully!\n\n"
63
+ f"• Prompt: {prompt}\n"
64
+ f"• Frames: {num_frames}\n"
65
+ f"• Guidance Scale: {guidance_scale}\n"
66
+ f"• Inference Steps: {inference_steps}\n"
67
+ f"• Seed: {seed}\n"
68
+ f"• Spicy Mode: {'Enabled' if use_spicy_mode else 'Disabled'}\n"
69
+ f"• Spicy Intensity: {spicy_intensity if use_spicy_mode else 'N/A'}"
70
+ }
71
+
72
+ # Create the Gradio interface
73
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="purple")) as demo:
74
+ # Header with title and description
75
+ gr.Markdown(
76
+ """
77
+ <div style="text-align: center; margin-bottom: 30px;">
78
+ <h1 style="color: #6a1b9a; font-size: 3.2em; margin-bottom: 10px;">Wan 2.2 Spicy Image-to-Video Generator</h1>
79
+ <p style="font-size: 1.2em; color: #4a4a4a; max-width: 800px; margin: 0 auto;">
80
+ Transform your images into stunning videos using the advanced Wan 2.2 model with spicy enhancements.
81
+ Perfect for creative content, animations, and visual storytelling.
82
+ </p>
83
+ <div style="margin-top: 20px;">
84
+ <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>
85
+ </div>
86
+ </div>
87
+ """
88
+ )
89
+
90
+ with gr.Row():
91
+ with gr.Column(scale=1):
92
+ # Input section
93
+ gr.Markdown("### 🎨 Input Settings")
94
+
95
+ image_input = gr.Image(
96
+ label="Upload Image",
97
+ type="pil",
98
+ height=300,
99
+ sources=["upload", "webcam", "clipboard"]
100
+ )
101
+
102
+ prompt_input = gr.Textbox(
103
+ label="Prompt",
104
+ placeholder="Describe the video you want to generate (e.g., 'A cat walking in a garden with阳光, cinematic, high quality')",
105
+ lines=3
106
+ )
107
+
108
+ negative_prompt = gr.Textbox(
109
+ label="Negative Prompt",
110
+ placeholder="Elements to avoid in the video (e.g., 'blurry, low quality, distorted')",
111
+ lines=2
112
+ )
113
+
114
+ with gr.Accordion("Advanced Settings", open=False):
115
+ num_frames = gr.Slider(
116
+ label="Number of Frames",
117
+ minimum=8,
118
+ maximum=64,
119
+ value=24,
120
+ step=1,
121
+ info="Number of frames in the generated video"
122
+ )
123
+
124
+ guidance_scale = gr.Slider(
125
+ label="Guidance Scale",
126
+ minimum=1.0,
127
+ maximum=20.0,
128
+ value=7.5,
129
+ step=0.5,
130
+ info="How closely the video follows your prompt"
131
+ )
132
+
133
+ inference_steps = gr.Slider(
134
+ label="Inference Steps",
135
+ minimum=10,
136
+ maximum=100,
137
+ value=30,
138
+ step=5,
139
+ info="Number of denoising steps (higher = better quality but slower)"
140
+ )
141
+
142
+ seed = gr.Number(
143
+ label="Seed",
144
+ value=-1,
145
+ precision=0,
146
+ info="Set to -1 for random seed"
147
+ )
148
+
149
+ with gr.Accordion("🔥 Spicy Mode Settings", open=True):
150
+ use_spicy_mode = gr.Checkbox(
151
+ label="Enable Spicy Mode",
152
+ value=True,
153
+ info="Activate enhanced generation with spicy effects"
154
+ )
155
+
156
+ spicy_intensity = gr.Slider(
157
+ label="Spicy Intensity",
158
+ minimum=1,
159
+ maximum=10,
160
+ value=7,
161
+ step=1,
162
+ info="How spicy should the video be? (1-10)"
163
+ )
164
+
165
+ spicy_effects = gr.CheckboxGroup(
166
+ label="Spicy Effects",
167
+ choices=[
168
+ "Fast Motion",
169
+ "High Contrast",
170
+ "Color Boost",
171
+ "Dynamic Transitions",
172
+ "Enhanced Details",
173
+ "Cinematic Effects"
174
+ ],
175
+ value=["High Contrast", "Color Boost", "Dynamic Transitions"],
176
+ info="Select which spicy effects to apply"
177
+ )
178
+
179
+ generate_btn = gr.Button(
180
+ "🎬 Generate Video",
181
+ variant="primary",
182
+ size="lg"
183
+ )
184
+
185
+ with gr.Column(scale=1):
186
+ # Output section
187
+ gr.Markdown("### 🎥 Generated Output")
188
+
189
+ video_output = gr.Video(
190
+ label="Generated Video",
191
+ height=400,
192
+ autoplay=True
193
+ )
194
+
195
+ stats_output = gr.Textbox(
196
+ label="Generation Statistics",
197
+ lines=10,
198
+ show_copy_button=True
199
+ )
200
+
201
+ # Examples
202
+ gr.Markdown("### 💡 Examples")
203
+
204
+ with gr.Row():
205
+ example1_btn = gr.Button("Nature Scene")
206
+ example2_btn = gr.Button("Urban Motion")
207
+ example3_btn = gr.Button("Abstract Art")
208
+
209
+ # Example functions
210
+ def set_example1():
211
+ return {
212
+ prompt_input: "A serene landscape with flowing river and mountains at sunset, cinematic lighting",
213
+ use_spicy_mode: True,
214
+ spicy_intensity: 6,
215
+ spicy_effects: ["Color Boost", "Cinematic Effects"]
216
+ }
217
+
218
+ def set_example2():
219
+ return {
220
+ prompt_input: "Time-lapse of city streets at night with neon lights and moving cars, cyberpunk style",
221
+ use_spicy_mode: True,
222
+ spicy_intensity: 8,
223
+ spicy_effects: ["Fast Motion", "High Contrast", "Color Boost"]
224
+ }
225
+
226
+ def set_example3():
227
+ return {
228
+ prompt_input: "Abstract fluid art with vibrant colors swirling and merging, macro perspective",
229
+ use_spicy_mode: False,
230
+ spicy_intensity: 3,
231
+ spicy_effects: ["Enhanced Details"]
232
+ }
233
+
234
+ example1_btn.click(set_example1, outputs=[prompt_input, use_spicy_mode, spicy_intensity, spicy_effects])
235
+ example2_btn.click(set_example2, outputs=[prompt_input, use_spicy_mode, spicy_intensity, spicy_effects])
236
+ example3_btn.click(set_example3, outputs=[prompt_input, use_spicy_mode, spicy_intensity, spicy_effects])
237
+
238
+ # Footer with information
239
+ gr.Markdown(
240
+ """
241
+ <div style="text-align: center; margin-top: 30px; padding: 20px; background-color: #f5f5f5; border-radius: 10px;">
242
+ <h3>About This Demo</h3>
243
+ <p>This application uses the Wan 2.2 model with spicy enhancements to generate videos from images.</p>
244
+ <p><strong>Spicy Mode</strong> applies creative enhancements like enhanced colors, dynamic transitions, and more.</p>
245
+ <p><em>Note: This is a demonstration. In a real implementation, the video would be generated by the Wan 2.2 model.</em></p>
246
+ </div>
247
+ """
248
+ )
249
+
250
+ # Event listener for generate button
251
+ generate_btn.click(
252
+ fn=generate_video_from_image,
253
+ inputs=[
254
+ image_input,
255
+ prompt_input,
256
+ negative_prompt,
257
+ num_frames,
258
+ guidance_scale,
259
+ inference_steps,
260
+ seed,
261
+ use_spicy_mode,
262
+ spicy_intensity
263
+ ],
264
+ outputs=[video_output, stats_output],
265
+ api_visibility="public"
266
+ )
267
+
268
+ # Launch the app with modern theme
269
+ demo.launch(
270
+ theme=gr.themes.Soft(primary_hue="indigo", secondary_hue="purple"),
271
+ footer_links=[{"label": "Wan 2.2 Model", "url": "https://huggingface.co/spaces/akhaliq/anycoder"}]
272
+ )
requirements.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ gradio>=6.0.2