File size: 2,192 Bytes
12deb01
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import os
import sys
import gradio as gr
try:
    os.system("pip install -r requirements.txt")
except Exception as e:
    print(e)

sys.path.insert(0, '.')


from utils.get_opt import get_opt
from os.path import join as pjoin
import numpy as np
from trainers import DDPMTrainer
from models import MotionTransformer

device = 'cpu'
opt = get_opt("checkpoints/t2m/t2m_motiondiffuse/opt.txt", device)
opt.do_denoise = True

assert opt.dataset_name == "t2m"
opt.data_root = './dataset/HumanML3D'
opt.motion_dir = pjoin(opt.data_root, 'new_joint_vecs')
opt.text_dir = pjoin(opt.data_root, 'texts')
opt.joints_num = 22
opt.dim_pose = 263

mean = np.load(pjoin(opt.meta_dir, 'mean.npy'))
std = np.load(pjoin(opt.meta_dir, 'std.npy'))


def build_models(opt):
    encoder = MotionTransformer(
        input_feats=opt.dim_pose,
        num_frames=opt.max_motion_length,
        num_layers=opt.num_layers,
        latent_dim=opt.latent_dim,
        no_clip=opt.no_clip,
        no_eff=opt.no_eff)
    return encoder


encoder = build_models(opt).to(device)
trainer = DDPMTrainer(opt, encoder)
trainer.load(pjoin(opt.model_dir, opt.which_epoch + '.tar'))

trainer.eval_mode()
trainer.to(opt.device)

def generate(prompt, length):
    from tools.visualization import process
    result_path = "outputs/" + str(hash(prompt)) + ".mp4"
    process(trainer, opt, device, mean, std, prompt, int(length), result_path)
    return result_path

demo = gr.Interface(
    fn=generate,
    inputs=["text", gr.Slider(20, 196, value=60)],
    examples=[
        ["the man throws a punch with each hand.", 58],
        ["a person jogs clockwise in a circle.", 178],
        ["a person spins quickly and takes off running.", 29],
        ["a person is walking slowly forward.", 142],
        ["a person quickly waves with their right hand", 46],
        ["a person performing a slight bow", 89],
    ],
    outputs="video",
    title="MotionDiffuse: Text-Driven Human Motion Generation with Diffusion Model",
    description="This is an interactive demo for MotionDiffuse. For more information, feel free to visit our project page(https://mingyuan-zhang.github.io/projects/MotionDiffuse.html).")

demo.launch(share=True)