-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmulti_model_animation_test.py
More file actions
353 lines (295 loc) · 12.4 KB
/
multi_model_animation_test.py
File metadata and controls
353 lines (295 loc) · 12.4 KB
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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
#!/usr/bin/env python3
"""
Multi-Model Animation Test
This script tests the enhanced animation system with multiple Runway models
to achieve maximum animation quality and motion effects.
"""
import json
import requests
import time
from typing import Dict, Any, List
def test_multi_model_animation():
"""Test the multi-model animation enhancement system."""
print("🎬 Multi-Model Animation Enhancement Test")
print("=" * 60)
print()
# Test scenarios for different models and motion intensities
animation_test_scenarios = [
{
"name": "Cinematic Ocean (Gen-4 Maximum Quality)",
"image_prompt": "A majestic ocean with large waves at golden hour",
"motion_intensity": "cinematic",
"model": "gen4",
"expected_quality": "Exceptional animation with maximum motion control",
"duration": 10
},
{
"name": "Dynamic Forest (Gen-4 Turbo Balanced)",
"image_prompt": "A magical forest with ancient trees swaying in wind",
"motion_intensity": "dynamic",
"model": "gen4_turbo",
"expected_quality": "Excellent motion with fast generation",
"duration": 6
},
{
"name": "Action Scene (Gen-3a Turbo Speed)",
"image_prompt": "A busy city street with fast-moving traffic",
"motion_intensity": "dynamic",
"model": "gen3a_turbo",
"expected_quality": "Good motion with fastest generation",
"duration": 5
},
{
"name": "Nature Scene (Auto-Select Optimal)",
"image_prompt": "A peaceful mountain lake with gentle ripples",
"motion_intensity": "moderate",
"model": None, # Auto-select
"expected_quality": "Automatically optimized model selection",
"duration": 8
},
{
"name": "Subtle Motion (Gen-3a Reliable)",
"image_prompt": "A serene garden with flowers gently swaying",
"motion_intensity": "subtle",
"model": "gen3a",
"expected_quality": "Stable and reliable motion generation",
"duration": 5
}
]
results = []
for i, scenario in enumerate(animation_test_scenarios, 1):
print(f"🎯 Test {i}: {scenario['name']}")
print(f" Scene: {scenario['image_prompt']}")
print(f" Motion: {scenario['motion_intensity']}")
print(f" Model: {scenario['model'] or 'Auto-Select'}")
print(f" Expected: {scenario['expected_quality']}")
print()
# Test with preview mode to see model selection
print(" 📋 Testing model selection and animation parameters...")
preview_result = test_animation_preview(scenario)
if preview_result:
print(" ✅ Animation parameters configured successfully")
print(f" 🎬 Model selected for optimal animation quality")
else:
print(" ❌ Animation configuration failed")
results.append({
"scenario": scenario,
"preview_result": preview_result
})
print()
print("-" * 60)
print()
# Save results
timestamp = int(time.time())
results_file = f"multi_model_animation_results_{timestamp}.json"
with open(results_file, 'w') as f:
json.dump(results, f, indent=2, ensure_ascii=False)
print(f"📄 Results saved to: {results_file}")
return results
def test_animation_preview(scenario: Dict[str, Any]) -> Dict[Any, Any]:
"""Test animation preview for a specific scenario."""
try:
payload = {
"image_prompt": scenario["image_prompt"],
"motion_intensity": scenario["motion_intensity"],
"duration": scenario["duration"],
"enhance_motion": True,
"preview_only": True
}
# Add model if specified (otherwise auto-select)
if scenario["model"]:
payload["model"] = scenario["model"]
response = requests.post("http://localhost:8000/generate-video-from-prompt", json=payload)
if response.status_code == 200:
result = response.json()
return result
else:
print(f" ❌ API request failed: {response.status_code}")
return None
except Exception as e:
print(f" ❌ Request failed: {e}")
return None
def demonstrate_model_capabilities():
"""Demonstrate the capabilities of different Runway models."""
print("\n🎬 Runway Model Capabilities")
print("=" * 60)
from src.config import Config
models = Config.RUNWAY_MODELS
for model_id, info in models.items():
print(f"\n🎯 {info['name']} ({model_id})")
print(f" Description: {info['description']}")
print(f" Motion Quality: {info['motion_quality']}")
print(f" Generation Speed: {info['generation_speed']}")
print(f" Best For: {info['recommended_for']}")
def show_model_selection_logic():
"""Show the intelligent model selection logic."""
print("\n🧠 Intelligent Model Selection")
print("=" * 60)
selection_matrix = {
"Motion Intensity": {
"cinematic": "gen4 (Maximum quality for cinematic content)",
"dynamic": "gen4_turbo (Balanced speed/quality for dynamic content)",
"moderate": "gen4_turbo (Good balance for moderate motion)",
"subtle": "gen3a_turbo (Fast generation for subtle motion)"
},
"Content Type": {
"cinematic": "gen4 (Epic/dramatic content)",
"action": "gen4_turbo (Dynamic/fast content)",
"nature": "gen4_turbo (Natural environments)",
"urban": "gen4_turbo (City/architectural)",
"general": "gen4_turbo (Default balanced choice)"
},
"Quality Priority": {
"maximum_quality": "gen4 (Highest quality, slower)",
"balanced": "gen4_turbo (Best balance)",
"speed": "gen3a_turbo (Fastest generation)",
"reliable": "gen3a (Most stable/consistent)"
}
}
for category, options in selection_matrix.items():
print(f"\n🎯 {category}:")
for key, value in options.items():
print(f" • {key}: {value}")
def test_enhanced_animation_parameters():
"""Test the enhanced animation parameters for different models."""
print("\n🔧 Enhanced Animation Parameters")
print("=" * 60)
try:
from src.file_processors.runway_processor import RunwayProcessor
processor = RunwayProcessor()
# Test parameter generation for different models
test_combinations = [
("gen4", "cinematic"),
("gen4_turbo", "dynamic"),
("gen3a_turbo", "moderate"),
("gen3a", "subtle")
]
for model, intensity in test_combinations:
print(f"\n🎬 Model: {model} | Intensity: {intensity}")
try:
params = processor._get_enhanced_animation_parameters(model, intensity)
print(f" Parameters: {params}")
# Test content type analysis
test_prompts = [
"A cinematic ocean scene with dramatic waves",
"A fast-paced city street with traffic",
"A peaceful forest with gentle movement"
]
for prompt in test_prompts:
content_type = processor._analyze_content_type(prompt)
optimal_model = processor._select_optimal_model_for_animation(intensity, content_type)
print(f" Prompt: {prompt[:40]}...")
print(f" Content Type: {content_type}")
print(f" Optimal Model: {optimal_model}")
except Exception as e:
print(f" ❌ Error: {e}")
except ImportError as e:
print(f"❌ Cannot test parameters: {e}")
def create_animation_api_examples():
"""Create examples of using the enhanced animation API."""
print("\n📝 Enhanced Animation API Examples")
print("=" * 60)
print("\n🎬 Maximum Quality Cinematic Video:")
print("```bash")
print('curl -X POST "http://localhost:8000/generate-video-from-prompt" \\')
print(' -H "Content-Type: application/json" \\')
print(' -d \'{')
print(' "image_prompt": "An epic mountain landscape during golden hour",')
print(' "motion_intensity": "cinematic",')
print(' "model": "gen4",')
print(' "enhance_motion": true,')
print(' "duration": 10')
print(' }\'')
print("```")
print("\n⚡ Fast Dynamic Animation:")
print("```bash")
print('curl -X POST "http://localhost:8000/generate-video-from-prompt" \\')
print(' -H "Content-Type: application/json" \\')
print(' -d \'{')
print(' "image_prompt": "A bustling city street with fast traffic",')
print(' "motion_intensity": "dynamic",')
print(' "model": "gen3a_turbo",')
print(' "enhance_motion": true,')
print(' "duration": 5')
print(' }\'')
print("```")
print("\n🤖 Auto-Select Optimal Model:")
print("```bash")
print('curl -X POST "http://localhost:8000/generate-video-from-prompt" \\')
print(' -H "Content-Type: application/json" \\')
print(' -d \'{')
print(' "image_prompt": "A magical forest with swaying trees",')
print(' "motion_intensity": "dynamic",')
print(' "auto_select_model": true,')
print(' "enhance_motion": true,')
print(' "duration": 6')
print(' }\'')
print("```")
print("\n🐍 Python Example:")
print("```python")
print("import requests")
print()
print("# Maximum animation quality")
print("response = requests.post('http://localhost:8000/generate-video-from-prompt', json={")
print(" 'image_prompt': 'A dramatic ocean with powerful waves',")
print(" 'motion_intensity': 'cinematic',")
print(" 'model': 'gen4', # Maximum quality model")
print(" 'effects': ['cinematic', 'hdr', 'dramatic'],")
print(" 'enhance_motion': True,")
print(" 'duration': 10")
print("})")
print()
print("result = response.json()")
print("print(f'Video: {result[\"video_url\"]}')")
print("print(f'Model Used: {result.get(\"model\", \"unknown\")}')")
print("```")
def test_api_health():
"""Check if the API server is running."""
try:
response = requests.get("http://localhost:8000/health")
if response.status_code == 200:
print("✅ API server is healthy")
return True
else:
print(f"⚠️ API server returned status: {response.status_code}")
return False
except requests.exceptions.ConnectionError:
print("❌ Cannot connect to API server at http://localhost:8000")
print(" Please start the server with: python run_api.py")
return False
except Exception as e:
print(f"❌ API health check failed: {e}")
return False
if __name__ == "__main__":
print("🚀 Starting Multi-Model Animation Enhancement Tests")
print("=" * 60)
# Check API health
if not test_api_health():
exit(1)
print()
# Demonstrate model capabilities
demonstrate_model_capabilities()
# Show model selection logic
show_model_selection_logic()
# Test enhanced parameters
test_enhanced_animation_parameters()
# Show API usage examples
create_animation_api_examples()
# Run multi-model tests
print()
results = test_multi_model_animation()
print("\n🎉 Multi-Model Animation Enhancement Complete!")
print("\n✨ Enhanced Animation Features:")
print("• 4 Runway models with different animation capabilities")
print("• Intelligent model selection based on content and motion intensity")
print("• Enhanced animation parameters for each model")
print("• Motion bucket ID optimization for Gen-4 models")
print("• Content-aware model recommendations")
print("• Automatic fallback and error handling")
print("\n🎯 Model Recommendations:")
print("• Maximum Quality: gen4 (cinematic content)")
print("• Balanced Performance: gen4_turbo (most content)")
print("• Fast Generation: gen3a_turbo (quick iterations)")
print("• Reliable Results: gen3a (stable/consistent)")
print("\n🚀 Your videos now have access to the best animation models!")
print("The system automatically selects the optimal model for maximum motion quality.")