megalado commited on
Commit
e14c352
·
1 Parent(s): 7ca808e

Add app, requirements, and model checkpoint

Browse files
Files changed (3) hide show
  1. app.py +47 -0
  2. checkpoints/t2m_50step.pt +3 -0
  3. requirements.txt +6 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess, uuid, os
2
+ from pathlib import Path
3
+ import gradio as gr
4
+
5
+ # --- CONFIG ---------------------------------------------------------------
6
+ CKPT_PATH = "checkpoints/t2m_50step.pt" # you already uploaded this
7
+ DEVICE = "cpu" # free HF Spaces have no GPU
8
+ # --------------------------------------------------------------------------
9
+
10
+
11
+ def generate_motion(prompt: str) -> str:
12
+ """
13
+ Calls the repo’s built-in inference script and returns the path to
14
+ the generated BVH file so Gradio can hand it to the user.
15
+ """
16
+ out_file = Path("/tmp") / f"{uuid.uuid4().hex}.bvh"
17
+
18
+ cmd = [
19
+ "python",
20
+ "-m",
21
+ "motion_diffusion_model.sample.generate", # script in the repo
22
+ "--model_path", CKPT_PATH,
23
+ "--prompt", prompt,
24
+ "--output", str(out_file),
25
+ "--device", DEVICE,
26
+ "--num_steps", "50" # matches the checkpoint
27
+ ]
28
+
29
+ # Run the subprocess and surface errors cleanly in the UI
30
+ completed = subprocess.run(cmd, capture_output=True, text=True)
31
+ if completed.returncode != 0:
32
+ raise RuntimeError(f"Inference failed:\n{completed.stderr}")
33
+
34
+ return str(out_file)
35
+
36
+
37
+ # ----------------- GRADIO UI ------------------------------------------------
38
+ iface = gr.Interface(
39
+ fn=generate_motion,
40
+ inputs=gr.Textbox(lines=2, placeholder="e.g. a person walks and waves"),
41
+ outputs=gr.File(label="Download BVH"),
42
+ title="Text-to-Motion (MDM – 50-step)",
43
+ description="Enter a natural-language description to generate a 3-D human-motion BVH file.",
44
+ )
45
+
46
+ if __name__ == "__main__":
47
+ iface.launch()
checkpoints/t2m_50step.pt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0fbdc8547c8f262b8838645586790b55f983d90db3bb7ed58e4b5d49429587ca
3
+ size 81818987
requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Core runtime
2
+ torch>=2.0 # PyTorch
3
+ gradio # Web UI + simple REST endpoint
4
+
5
+ # Pull the Motion-Diffusion-Model repo at build time
6
+ git+https://github.com/GuyTevet/motion-diffusion-model.git