-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathenhanced_motion_examples.py
More file actions
251 lines (209 loc) Β· 9.4 KB
/
enhanced_motion_examples.py
File metadata and controls
251 lines (209 loc) Β· 9.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
#!/usr/bin/env python3
"""
Enhanced Motion Video Generation Examples
This script demonstrates the enhanced motion capabilities of the Runway processor
with different motion intensity levels: subtle, moderate, dynamic, and cinematic.
"""
import json
import requests
import time
from typing import Dict, Any
def test_motion_intensity_levels():
"""Test video generation with different motion intensity levels."""
# Base URL for the API
base_url = "http://localhost:8000"
# Test scenarios with different motion intensities
test_scenarios = [
{
"name": "Ocean Scene - Subtle Motion",
"image_prompt": "A peaceful ocean view with gentle waves at sunset",
"motion_intensity": "subtle",
"expected_motion": "Gentle ripples, soft movement, slow pan"
},
{
"name": "Ocean Scene - Moderate Motion",
"image_prompt": "A peaceful ocean view with gentle waves at sunset",
"motion_intensity": "moderate",
"expected_motion": "Flowing water, natural movement, smooth tracking"
},
{
"name": "Ocean Scene - Dynamic Motion",
"image_prompt": "A peaceful ocean view with gentle waves at sunset",
"motion_intensity": "dynamic",
"expected_motion": "Energetic waves, rhythmic motion, dynamic sweep"
},
{
"name": "Ocean Scene - Cinematic Motion",
"image_prompt": "A peaceful ocean view with gentle waves at sunset",
"motion_intensity": "cinematic",
"expected_motion": "Dramatic waves, sweeping motion, cinematic movement"
},
{
"name": "Forest Scene - Cinematic Motion",
"image_prompt": "A magical forest with tall trees and dappled sunlight",
"motion_intensity": "cinematic",
"expected_motion": "Majestic trees swaying, leaves cascading like rain, cinematic movement through forest canopy"
},
{
"name": "City Scene - Dynamic Motion",
"image_prompt": "A modern city skyline with glass buildings reflecting sunlight",
"motion_intensity": "dynamic",
"expected_motion": "Dynamic camera sweeping through scene, shadows moving, glass reflections shifting"
}
]
print("π¬ Enhanced Motion Video Generation Test")
print("=" * 60)
print()
results = []
for i, scenario in enumerate(test_scenarios, 1):
print(f"π Test {i}: {scenario['name']}")
print(f" Image Prompt: {scenario['image_prompt']}")
print(f" Motion Intensity: {scenario['motion_intensity']}")
print(f" Expected Motion: {scenario['expected_motion']}")
print()
# Test with preview mode first to see the generated prompts
print(" π Preview Mode - Checking generated prompts...")
preview_result = test_prompt_to_video_preview(
image_prompt=scenario["image_prompt"],
motion_intensity=scenario["motion_intensity"]
)
if preview_result:
print(" β
Preview generated successfully")
# Extract the video prompt from preview
prompts = preview_result.get("prompts", {})
video_gen = prompts.get("2_video_generation", {})
final_prompt = video_gen.get("sanitized_prompt", "")
print(f" π Generated Video Prompt: {final_prompt}")
# Add preview result to our results
results.append({
"scenario": scenario["name"],
"motion_intensity": scenario["motion_intensity"],
"preview_result": preview_result,
"generated_prompt": final_prompt
})
else:
print(" β Preview failed")
print()
print("-" * 60)
print()
# Save results to file
timestamp = int(time.time())
results_file = f"enhanced_motion_test_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}")
# Print summary
print("\nπ Test Summary:")
print("=" * 60)
for result in results:
print(f"β’ {result['scenario']} ({result['motion_intensity']})")
prompt = result.get('generated_prompt', '')
if prompt:
# Extract motion keywords from the prompt
motion_keywords = extract_motion_keywords(prompt)
print(f" Motion Keywords: {', '.join(motion_keywords)}")
print()
return results
def test_prompt_to_video_preview(image_prompt: str, motion_intensity: str = "dynamic") -> Dict[Any, Any]:
"""Test the preview mode for prompt-to-video generation."""
try:
payload = {
"image_prompt": image_prompt,
"motion_intensity": motion_intensity,
"duration": 5,
"ratio": "1280:720",
"preview_only": True
}
response = requests.post("http://localhost:8000/generate-video-from-prompt", json=payload)
if response.status_code == 200:
result_data = response.json()
# Extract the preview data from the result
if hasattr(result_data, 'get'):
# This is likely the VideoGenerationResult structure
# We need to parse the actual preview from the response
print(" β οΈ Note: Getting result in API response format, may need to extract preview data")
return result_data
else:
# Direct preview data
return result_data
else:
print(f" β API request failed: {response.status_code}")
print(f" Error: {response.text}")
return None
except Exception as e:
print(f" β Request failed: {e}")
return None
def extract_motion_keywords(prompt: str) -> list:
"""Extract motion-related keywords from a video prompt."""
motion_keywords = [
"swaying", "dancing", "flowing", "moving", "shifting", "drifting",
"cascading", "sweeping", "racing", "rippling", "billowing", "streaming",
"camera", "cinematic", "dynamic", "gentle", "dramatic", "epic",
"waves", "wind", "breeze", "motion", "movement", "animation"
]
found_keywords = []
prompt_lower = prompt.lower()
for keyword in motion_keywords:
if keyword in prompt_lower:
found_keywords.append(keyword)
return found_keywords
def test_api_health():
"""Check if the API server is running and healthy."""
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
def demonstrate_motion_comparison():
"""Demonstrate the differences between motion intensity levels."""
print("\nπ Motion Intensity Comparison")
print("=" * 60)
base_prompt = "A serene mountain landscape with clouds and trees"
intensities = ["subtle", "moderate", "dynamic", "cinematic"]
print(f"Base Scene: {base_prompt}")
print()
for intensity in intensities:
print(f"π¬ {intensity.upper()} Motion:")
# This would call our enhanced motion generation function directly
# For demonstration, we'll show what the motion would look like
motion_descriptions = {
"subtle": "Clouds drifting across sky, grass swaying gently, atmospheric mist moving softly, slow pan",
"moderate": "Clouds flowing across sky, grass swaying gently, atmospheric mist moving softly, smooth tracking",
"dynamic": "Clouds racing across sky, grass rippling like waves, mist flowing through valleys, light intensity shifting, dynamic sweep",
"cinematic": "Dramatic clouds racing across vast sky, grass rippling like ocean waves, mist cascading through valleys, cinematic movement revealing landscape grandeur"
}
print(f" Expected Motion: {motion_descriptions[intensity]}")
print()
if __name__ == "__main__":
print("π Starting Enhanced Motion Video Generation Tests")
print("=" * 60)
# Check API health
if not test_api_health():
exit(1)
print()
# Demonstrate motion comparison
demonstrate_motion_comparison()
# Run the main test
print()
results = test_motion_intensity_levels()
print("\nπ Enhanced Motion Testing Complete!")
print("\nπ‘ Key Features Added:")
print("β’ Motion intensity levels: subtle, moderate, dynamic, cinematic")
print("β’ Enhanced scene detection for better motion generation")
print("β’ Intensity-specific motion enhancers and camera movements")
print("β’ API support for motion_intensity parameter")
print("β’ Comprehensive motion keyword system")
print("\nπ οΈ Usage Examples:")
print("β’ API: Include 'motion_intensity': 'cinematic' in your request")
print("β’ CLI: Add --motion-intensity cinematic to your command")
print("β’ Direct: motion_intensity='subtle' in function calls")