megalado commited on
Commit
20a9eae
·
1 Parent(s): db73149

use prompt-only sampler (sample_text2motion.py)

Browse files
Files changed (1) hide show
  1. app.py +7 -17
app.py CHANGED
@@ -13,25 +13,19 @@ DEVICE = "cpu" # free HF Spaces have no GPU
13
 
14
 
15
  def generate_motion(prompt: str) -> str:
16
- """
17
- Calls the MDM sampling script and returns the generated BVH path.
18
- """
19
- # create a unique temp directory for this run
20
- out_dir = Path("/tmp") / f"mdm_{uuid.uuid4().hex}"
21
- out_dir.mkdir(parents=True, exist_ok=True)
22
 
23
  cmd = [
24
  "python",
25
  "-m",
26
- "motion_diffusion_model.sample.generate",
27
  "--model_path", str(CKPT_PATH),
28
- "--text_prompt", prompt,
29
- "--cuda", "-1", # -1 = cpu
30
- "--num_samples", "1",
31
- "--output_dir", str(out_dir),
32
  ]
33
 
34
- # add both repo roots to PYTHONPATH
35
  env = os.environ.copy()
36
  root = Path(__file__).parent
37
  repo_inner = root / "motion_diffusion_model"
@@ -41,11 +35,7 @@ def generate_motion(prompt: str) -> str:
41
  if completed.returncode != 0:
42
  raise RuntimeError(f"Inference failed:\n{completed.stderr}")
43
 
44
- # find the .bvh the script just wrote
45
- bvh_files = list(out_dir.rglob("*.bvh"))
46
- if not bvh_files:
47
- raise RuntimeError("No BVH file produced.")
48
- return str(bvh_files[0])
49
 
50
 
51
 
 
13
 
14
 
15
  def generate_motion(prompt: str) -> str:
16
+ out_file = Path("/tmp") / f"{uuid.uuid4().hex}.bvh"
 
 
 
 
 
17
 
18
  cmd = [
19
  "python",
20
  "-m",
21
+ "motion_diffusion_model.sample.sample_text2motion",
22
  "--model_path", str(CKPT_PATH),
23
+ "--prompt", prompt,
24
+ "--output", str(out_file),
25
+ "--device", "cpu",
 
26
  ]
27
 
28
+ # make repo visible to the subprocess
29
  env = os.environ.copy()
30
  root = Path(__file__).parent
31
  repo_inner = root / "motion_diffusion_model"
 
35
  if completed.returncode != 0:
36
  raise RuntimeError(f"Inference failed:\n{completed.stderr}")
37
 
38
+ return str(out_file)
 
 
 
 
39
 
40
 
41