megalado commited on
Commit
4595318
·
1 Parent(s): 891dfcb

Fix animation script formatting issues

Browse files
Files changed (1) hide show
  1. app.py +29 -45
app.py CHANGED
@@ -11,43 +11,12 @@ import requests
11
  import time
12
  import random
13
 
14
- def inspect_mdm_repo():
15
- """Check the structure of the MDM repository"""
16
- if not Path("motion-diffusion-model").exists():
17
- print("MDM repository not found.")
18
- return
19
-
20
- print("Inspecting MDM repository structure:")
21
- # List top-level directories and files
22
- for item in sorted(os.listdir("motion-diffusion-model"))[:5]: # Limit to first 5 for brevity
23
- path = os.path.join("motion-diffusion-model", item)
24
- if os.path.isdir(path):
25
- print(f"Directory: {item}")
26
- # List files in the directory (up to 3)
27
- for subitem in sorted(os.listdir(path))[:3]:
28
- print(f" - {subitem}")
29
- else:
30
- print(f"File: {item}")
31
- print("...") # Indicate truncated output
32
-
33
  def create_motion_animation(text_prompt, motion_length=3.0, seed=0):
34
  """Create a motion animation based on input parameters"""
35
  print(f"Creating animation for: '{text_prompt}', length: {motion_length}s, seed: {seed}")
36
 
37
- # Use the seed for reproducibility
38
- np.random.seed(int(seed))
39
- random.seed(int(seed))
40
-
41
- # Parse the text prompt to influence the animation
42
- walking = "walk" in text_prompt.lower()
43
- running = "run" in text_prompt.lower()
44
- jumping = "jump" in text_prompt.lower()
45
- dancing = "danc" in text_prompt.lower()
46
- turning = "turn" in text_prompt.lower() or "spin" in text_prompt.lower()
47
- waving = "wave" in text_prompt.lower()
48
-
49
  # Create a unique filename based on parameters
50
- output_filename = f"output_{hash(text_prompt)}_{motion_length}_{seed}.mp4"
51
 
52
  # Create a simple visualization script
53
  with open("motion_animation.py", "w") as f:
@@ -63,6 +32,15 @@ import random
63
  np.random.seed({int(seed)})
64
  random.seed({int(seed)})
65
 
 
 
 
 
 
 
 
 
 
66
  # Create a motion based on text prompt
67
  def generate_motion(frames={int(motion_length * 30)}):
68
  joints = 16 # Number of joints in a simplified skeleton
@@ -70,14 +48,6 @@ def generate_motion(frames={int(motion_length * 30)}):
70
 
71
  motion = np.zeros((frames, joints, dims))
72
 
73
- # Parse animation parameters from text
74
- walking = {walking}
75
- running = {running}
76
- jumping = {jumping}
77
- dancing = {dancing}
78
- turning = {turning}
79
- waving = {waving}
80
-
81
  # Set speed based on motion type
82
  if running:
83
  speed = 4.0
@@ -224,7 +194,24 @@ def visualize_motion(output_path):
224
  [motion_data[frame, start, 1], motion_data[frame, end, 1]],
225
  [motion_data[frame, start, 2], motion_data[frame, end, 2]], 'r-')
226
 
227
- ax.set_title(f"{repr('{text_prompt}')} - Frame {{frame}}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
228
  return ax
229
 
230
  # Create animation
@@ -253,9 +240,6 @@ visualize_motion("{output_filename}")
253
  def text_to_motion(text_prompt, motion_length=3.0, seed=0):
254
  """Generate motion from text prompt using MDM"""
255
  try:
256
- # Inspect the MDM repository structure (limited output)
257
- inspect_mdm_repo()
258
-
259
  # Create a motion animation based on the input parameters
260
  return create_motion_animation(text_prompt, motion_length, seed)
261
 
@@ -268,7 +252,7 @@ def text_to_motion(text_prompt, motion_length=3.0, seed=0):
268
  demo = gr.Interface(
269
  fn=text_to_motion,
270
  inputs=[
271
- gr.Textbox(label="Text Prompt", placeholder="A person walks forward, then turns left", lines=3),
272
  gr.Slider(minimum=1.0, maximum=9.8, value=3.0, label="Motion Length (seconds)"),
273
  gr.Number(label="Random Seed", value=0)
274
  ],
 
11
  import time
12
  import random
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  def create_motion_animation(text_prompt, motion_length=3.0, seed=0):
15
  """Create a motion animation based on input parameters"""
16
  print(f"Creating animation for: '{text_prompt}', length: {motion_length}s, seed: {seed}")
17
 
 
 
 
 
 
 
 
 
 
 
 
 
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:
 
32
  np.random.seed({int(seed)})
33
  random.seed({int(seed)})
34
 
35
+ # Animation parameters
36
+ text_prompt = "{text_prompt.replace('"', '\\"')}"
37
+ walking = "walk" in text_prompt.lower()
38
+ running = "run" in text_prompt.lower()
39
+ jumping = "jump" in text_prompt.lower()
40
+ dancing = "danc" in text_prompt.lower()
41
+ 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={int(motion_length * 30)}):
46
  joints = 16 # Number of joints in a simplified skeleton
 
48
 
49
  motion = np.zeros((frames, joints, dims))
50
 
 
 
 
 
 
 
 
 
51
  # Set speed based on motion type
52
  if running:
53
  speed = 4.0
 
194
  [motion_data[frame, start, 1], motion_data[frame, end, 1]],
195
  [motion_data[frame, start, 2], motion_data[frame, end, 2]], 'r-')
196
 
197
+ # Set title
198
+ action_type = ""
199
+ if running:
200
+ action_type = "Running"
201
+ elif walking:
202
+ action_type = "Walking"
203
+ elif jumping:
204
+ action_type = "Jumping"
205
+ elif dancing:
206
+ action_type = "Dancing"
207
+ elif turning:
208
+ action_type = "Turning"
209
+ elif waving:
210
+ action_type = "Waving"
211
+ else:
212
+ action_type = "Moving"
213
+
214
+ ax.set_title(f"{action_type} Motion - Frame {{frame}}")
215
  return ax
216
 
217
  # Create animation
 
240
  def text_to_motion(text_prompt, motion_length=3.0, seed=0):
241
  """Generate motion from text prompt using MDM"""
242
  try:
 
 
 
243
  # Create a motion animation based on the input parameters
244
  return create_motion_animation(text_prompt, motion_length, seed)
245
 
 
252
  demo = gr.Interface(
253
  fn=text_to_motion,
254
  inputs=[
255
+ gr.Textbox(label="Text Prompt", placeholder="A person walks forward, then turns left", lines=3, value="A person walking"),
256
  gr.Slider(minimum=1.0, maximum=9.8, value=3.0, label="Motion Length (seconds)"),
257
  gr.Number(label="Random Seed", value=0)
258
  ],