megalado
commited on
Commit
·
c02fe08
1
Parent(s):
4595318
Create different animations based on input parameters
Browse files
app.py
CHANGED
|
@@ -18,9 +18,12 @@ def create_motion_animation(text_prompt, motion_length=3.0, seed=0):
|
|
| 18 |
# Create a unique filename based on parameters
|
| 19 |
output_filename = f"output_{abs(hash(text_prompt) % 10000)}_{int(motion_length)}_{seed}.mp4"
|
| 20 |
|
|
|
|
|
|
|
|
|
|
| 21 |
# Create a simple visualization script
|
| 22 |
with open("motion_animation.py", "w") as f:
|
| 23 |
-
f.write(
|
| 24 |
import numpy as np
|
| 25 |
import matplotlib.pyplot as plt
|
| 26 |
from matplotlib.animation import FuncAnimation
|
|
@@ -29,11 +32,11 @@ from mpl_toolkits.mplot3d import Axes3D
|
|
| 29 |
import random
|
| 30 |
|
| 31 |
# Set random seeds for reproducibility
|
| 32 |
-
np.random.seed({
|
| 33 |
-
random.seed({
|
| 34 |
|
| 35 |
# Animation parameters
|
| 36 |
-
text_prompt = "{
|
| 37 |
walking = "walk" in text_prompt.lower()
|
| 38 |
running = "run" in text_prompt.lower()
|
| 39 |
jumping = "jump" in text_prompt.lower()
|
|
@@ -42,7 +45,7 @@ turning = "turn" in text_prompt.lower() or "spin" in text_prompt.lower()
|
|
| 42 |
waving = "wave" in text_prompt.lower()
|
| 43 |
|
| 44 |
# Create a motion based on text prompt
|
| 45 |
-
def generate_motion(frames={
|
| 46 |
joints = 16 # Number of joints in a simplified skeleton
|
| 47 |
dims = 3 # x, y, z
|
| 48 |
|
|
@@ -226,8 +229,14 @@ def visualize_motion(output_path):
|
|
| 226 |
return output_path
|
| 227 |
|
| 228 |
# Create and visualize a motion
|
| 229 |
-
visualize_motion("{
|
| 230 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 231 |
|
| 232 |
# Run the script
|
| 233 |
subprocess.run(["python", "motion_animation.py"])
|
|
|
|
| 18 |
# Create a unique filename based on parameters
|
| 19 |
output_filename = f"output_{abs(hash(text_prompt) % 10000)}_{int(motion_length)}_{seed}.mp4"
|
| 20 |
|
| 21 |
+
# Sanitize the text prompt for Python string
|
| 22 |
+
safe_prompt = text_prompt.replace('"', '')
|
| 23 |
+
|
| 24 |
# Create a simple visualization script
|
| 25 |
with open("motion_animation.py", "w") as f:
|
| 26 |
+
f.write("""
|
| 27 |
import numpy as np
|
| 28 |
import matplotlib.pyplot as plt
|
| 29 |
from matplotlib.animation import FuncAnimation
|
|
|
|
| 32 |
import random
|
| 33 |
|
| 34 |
# Set random seeds for reproducibility
|
| 35 |
+
np.random.seed({})
|
| 36 |
+
random.seed({})
|
| 37 |
|
| 38 |
# Animation parameters
|
| 39 |
+
text_prompt = "{}"
|
| 40 |
walking = "walk" in text_prompt.lower()
|
| 41 |
running = "run" in text_prompt.lower()
|
| 42 |
jumping = "jump" in text_prompt.lower()
|
|
|
|
| 45 |
waving = "wave" in text_prompt.lower()
|
| 46 |
|
| 47 |
# Create a motion based on text prompt
|
| 48 |
+
def generate_motion(frames={}):
|
| 49 |
joints = 16 # Number of joints in a simplified skeleton
|
| 50 |
dims = 3 # x, y, z
|
| 51 |
|
|
|
|
| 229 |
return output_path
|
| 230 |
|
| 231 |
# Create and visualize a motion
|
| 232 |
+
visualize_motion("{}")
|
| 233 |
+
""".format(
|
| 234 |
+
int(seed), # First {}
|
| 235 |
+
int(seed), # Second {}
|
| 236 |
+
safe_prompt, # Third {}
|
| 237 |
+
int(motion_length * 30), # Fourth {}
|
| 238 |
+
output_filename # Fifth {}
|
| 239 |
+
))
|
| 240 |
|
| 241 |
# Run the script
|
| 242 |
subprocess.run(["python", "motion_animation.py"])
|