File size: 1,322 Bytes
4496399
 
 
 
667d24f
 
4496399
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
667d24f
 
 
 
4496399
 
 
667d24f
 
4496399
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
import os
import uuid
import subprocess
import shlex
import gradio as gr

MODEL_DIR = "motion-diffusion-model"   # where you copied the repo
OUTPUT_DIR = "outputs"
os.makedirs(OUTPUT_DIR, exist_ok=True)

def generate_motion(prompt: str):
    # Unique filename
    run_id = uuid.uuid4().hex[:8]
    out_file = f"{run_id}.mp4"
    out_path = os.path.join(OUTPUT_DIR, out_file)

    # Command-line call to the sample script
    # Adjust flags if needed; this is the typical pattern
    cmd = f"python {MODEL_DIR}/sample/predict.py " \
          f"--prompt \"{prompt}\" " \
          f"--results_dir {OUTPUT_DIR} " \
          f"--num_samples 1"

    # Run the model
    subprocess.run(shlex.split(cmd), check=True)

    # The script will dump something like outputs/sample_0.mp4
    # Rename it to our unique filename
    default_out = os.path.join(OUTPUT_DIR, "sample_0.mp4")
    if os.path.exists(default_out):
        os.replace(default_out, out_path)
    else:
        raise FileNotFoundError(default_out)

    return out_path

demo = gr.Interface(
    fn=generate_motion,
    inputs=gr.Textbox(label="Enter a text prompt"),
    outputs=gr.Video(label="Generated Motion"),
    title="Motion Diffusion Model",
    description="Type some text and watch the 3D human motion!"
)

if __name__ == "__main__":
    demo.launch()