megalado commited on
Commit
f745733
·
1 Parent(s): 31644a6

Update app.py to use subprocess with better debugging

Browse files
Files changed (2) hide show
  1. app.py +42 -31
  2. requirements.txt +6 -2
app.py CHANGED
@@ -4,55 +4,66 @@ import os
4
  import sys
5
  import numpy as np
6
  from pathlib import Path
 
 
7
 
8
  def text_to_motion(text_prompt, motion_length=3.0, seed=0):
9
  """Generate motion from text prompt using MDM"""
10
  try:
11
  # First, check if we need to clone the repository
12
  if not Path("motion-diffusion-model").exists():
13
- import subprocess
14
  print("Cloning Motion Diffusion Model repository...")
15
  subprocess.run(["git", "clone", "https://github.com/GuyTevet/motion-diffusion-model.git"])
16
- # Add the repository to the Python path after cloning
17
- sys.path.append('./motion-diffusion-model')
18
  print("Installing Spacy language model...")
19
  subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
20
- else:
21
- # Add the repository to the Python path if it already exists
22
- sys.path.append('./motion-diffusion-model')
23
 
24
- # Now import the necessary functions
25
- # Use the correct import paths based on the repository structure
26
- from sample.generate import generate
27
- from visualization.visualize import visualize
28
 
29
- # Set the seed for reproducibility
30
- if seed is not None:
31
- torch.manual_seed(seed)
32
 
33
- # Use the local checkpoint path
34
- model_path = "checkpoints/mld_humanml.pt"
 
 
 
 
 
 
 
35
 
36
- # Generate the motion
37
- print("Running MDM generation...")
38
- motion_data = generate(
39
- model_path=model_path,
40
- text_prompt=text_prompt,
41
- motion_length=motion_length,
42
- seeds=[seed] # Generate just one sample
43
- )
44
 
45
- # Render the animation
46
- print("Rendering animation...")
47
- output_path = "output.mp4"
48
- visualize(motion_data, output_path)
49
 
50
- print("Animation generated successfully!")
51
- return output_path
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
52
  except Exception as e:
53
- import traceback
54
  print(f"Error generating motion: {str(e)}")
55
- print(traceback.format_exc()) # Print the full traceback for debugging
56
  return None
57
 
58
  # Create the Gradio interface
 
4
  import sys
5
  import numpy as np
6
  from pathlib import Path
7
+ import traceback
8
+ import subprocess
9
 
10
  def text_to_motion(text_prompt, motion_length=3.0, seed=0):
11
  """Generate motion from text prompt using MDM"""
12
  try:
13
  # First, check if we need to clone the repository
14
  if not Path("motion-diffusion-model").exists():
 
15
  print("Cloning Motion Diffusion Model repository...")
16
  subprocess.run(["git", "clone", "https://github.com/GuyTevet/motion-diffusion-model.git"])
 
 
17
  print("Installing Spacy language model...")
18
  subprocess.run(["python", "-m", "spacy", "download", "en_core_web_sm"])
 
 
 
19
 
20
+ # Get absolute path to the checkpoint
21
+ checkpoint_path = os.path.abspath("checkpoints/mld_humanml.pt")
 
 
22
 
23
+ # Set the working directory to the repository for imports to work correctly
24
+ original_dir = os.getcwd()
25
+ os.chdir("motion-diffusion-model")
26
 
27
+ # Create a sampling command
28
+ cmd = [
29
+ "python",
30
+ "sample/generate.py",
31
+ "--model_path", checkpoint_path,
32
+ "--text_prompt", text_prompt,
33
+ "--motion_length", str(motion_length),
34
+ "--seed", str(int(seed))
35
+ ]
36
 
37
+ print(f"Running command: {' '.join(cmd)}")
38
+ result = subprocess.run(cmd, capture_output=True, text=True)
 
 
 
 
 
 
39
 
40
+ # Print the output for debugging
41
+ print("Command output:", result.stdout)
42
+ if result.stderr:
43
+ print("Command error:", result.stderr)
44
 
45
+ # Change back to the original directory
46
+ os.chdir(original_dir)
47
+
48
+ # The script might save the output in a specific location
49
+ # Check the common output paths
50
+ output_paths = [
51
+ "samples/sample.mp4",
52
+ "motion-diffusion-model/samples/sample.mp4",
53
+ "output.mp4",
54
+ "motion-diffusion-model/output.mp4"
55
+ ]
56
+
57
+ for path in output_paths:
58
+ if Path(path).exists():
59
+ print(f"Found output at {path}")
60
+ return path
61
+
62
+ print("Output file not found in expected locations.")
63
+ return None
64
  except Exception as e:
 
65
  print(f"Error generating motion: {str(e)}")
66
+ print(traceback.format_exc()) # Print the full traceback
67
  return None
68
 
69
  # Create the Gradio interface
requirements.txt CHANGED
@@ -1,5 +1,6 @@
1
  gradio>=3.50.2
2
  torch>=2.0.1
 
3
  numpy>=1.24.3
4
  spacy>=3.5.3
5
  transformers>=4.30.2
@@ -9,5 +10,8 @@ imageio>=2.31.1
9
  tqdm>=4.65.0
10
  einops>=0.6.1
11
  git+https://github.com/openai/CLIP.git
12
- torchvision>=0.15.0
13
- tensorboard>=2.13.0
 
 
 
 
1
  gradio>=3.50.2
2
  torch>=2.0.1
3
+ torchvision>=0.15.0
4
  numpy>=1.24.3
5
  spacy>=3.5.3
6
  transformers>=4.30.2
 
10
  tqdm>=4.65.0
11
  einops>=0.6.1
12
  git+https://github.com/openai/CLIP.git
13
+ clearml>=1.10.3
14
+ tensorboard>=2.13.0
15
+ smplx>=0.1.28
16
+ opencv-python>=4.7.0
17
+ ipython>=8.12.0