Spaces:
Running
Running
Commit
·
afec801
1
Parent(s):
fcc3e8d
Download bvh
Browse files
app.py
CHANGED
|
@@ -104,7 +104,7 @@ CSS = """
|
|
| 104 |
border-color: #000000;
|
| 105 |
border-radius: var(--block-radius);
|
| 106 |
background: var(--block-background-fill);
|
| 107 |
-
width:
|
| 108 |
line-height: var(--line-sm);
|
| 109 |
}
|
| 110 |
}
|
|
@@ -172,7 +172,9 @@ def inv_transform(data):
|
|
| 172 |
kinematic_chain = t2m_kinematic_chain
|
| 173 |
converter = Joint2BVHConvertor()
|
| 174 |
cached_dir = './cached'
|
| 175 |
-
|
|
|
|
|
|
|
| 176 |
|
| 177 |
@torch.no_grad()
|
| 178 |
def generate(
|
|
@@ -213,20 +215,20 @@ def generate(
|
|
| 213 |
pred_motions = pred_motions.detach().cpu().numpy()
|
| 214 |
data = inv_transform(pred_motions)
|
| 215 |
for k, (caption, joint_data) in enumerate(zip(captions, data)):
|
| 216 |
-
animation_path = pjoin(cached_dir, f'{uid}'
|
| 217 |
os.makedirs(animation_path, exist_ok=True)
|
| 218 |
joint_data = joint_data[:m_length[k]]
|
| 219 |
joint = recover_from_ric(torch.from_numpy(joint_data).float(), 22).numpy()
|
| 220 |
-
bvh_path = pjoin(animation_path, "
|
| 221 |
-
save_path = pjoin(animation_path, "
|
| 222 |
if use_ik:
|
| 223 |
_, joint = converter.convert(joint, filename=bvh_path, iterations=100)
|
| 224 |
else:
|
| 225 |
_, joint = converter.convert(joint, filename=bvh_path, iterations=100, foot_ik=False)
|
| 226 |
plot_3d_motion(save_path, kinematic_chain, joint, title=caption, fps=20)
|
| 227 |
-
np.save(pjoin(animation_path, "
|
| 228 |
data_unit = {
|
| 229 |
-
"url": pjoin(animation_path, "
|
| 230 |
}
|
| 231 |
datas.append(data_unit)
|
| 232 |
|
|
@@ -248,11 +250,10 @@ autoplay loop disablepictureinpicture id="{video_id}">
|
|
| 248 |
"""
|
| 249 |
return video_html
|
| 250 |
|
| 251 |
-
|
| 252 |
def generate_component(generate_function, text, motion_len='0', postprocess='IK'):
|
| 253 |
if text == DEFAULT_TEXT or text == "" or text is None:
|
| 254 |
return [None for _ in range(1)]
|
| 255 |
-
uid = random.randrange(99999)
|
| 256 |
try:
|
| 257 |
motion_len = max(0, min(int(float(motion_len) * 20), 196))
|
| 258 |
except:
|
|
@@ -294,6 +295,12 @@ with gr.Blocks(css=CSS, theme=theme) as demo:
|
|
| 294 |
value="IK",
|
| 295 |
info="Use basic inverse kinematic (IK) for foot contact locking",
|
| 296 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 297 |
gen_btn = gr.Button("Generate", variant="primary")
|
| 298 |
clear = gr.Button("Clear", variant="secondary")
|
| 299 |
|
|
|
|
| 104 |
border-color: #000000;
|
| 105 |
border-radius: var(--block-radius);
|
| 106 |
background: var(--block-background-fill);
|
| 107 |
+
width: 25%;
|
| 108 |
line-height: var(--line-sm);
|
| 109 |
}
|
| 110 |
}
|
|
|
|
| 172 |
kinematic_chain = t2m_kinematic_chain
|
| 173 |
converter = Joint2BVHConvertor()
|
| 174 |
cached_dir = './cached'
|
| 175 |
+
uid = 12138
|
| 176 |
+
animation_path = pjoin(cached_dir, f'{uid}')
|
| 177 |
+
os.makedirs(animation_path, exist_ok=True)
|
| 178 |
|
| 179 |
@torch.no_grad()
|
| 180 |
def generate(
|
|
|
|
| 215 |
pred_motions = pred_motions.detach().cpu().numpy()
|
| 216 |
data = inv_transform(pred_motions)
|
| 217 |
for k, (caption, joint_data) in enumerate(zip(captions, data)):
|
| 218 |
+
animation_path = pjoin(cached_dir, f'{uid}')
|
| 219 |
os.makedirs(animation_path, exist_ok=True)
|
| 220 |
joint_data = joint_data[:m_length[k]]
|
| 221 |
joint = recover_from_ric(torch.from_numpy(joint_data).float(), 22).numpy()
|
| 222 |
+
bvh_path = pjoin(animation_path, "sample_repeat%d.bvh" % (r))
|
| 223 |
+
save_path = pjoin(animation_path, "sample_repeat%d.mp4"%(r))
|
| 224 |
if use_ik:
|
| 225 |
_, joint = converter.convert(joint, filename=bvh_path, iterations=100)
|
| 226 |
else:
|
| 227 |
_, joint = converter.convert(joint, filename=bvh_path, iterations=100, foot_ik=False)
|
| 228 |
plot_3d_motion(save_path, kinematic_chain, joint, title=caption, fps=20)
|
| 229 |
+
np.save(pjoin(animation_path, "sample_repeat%d.npy"%(r)), joint)
|
| 230 |
data_unit = {
|
| 231 |
+
"url": pjoin(animation_path, "sample_repeat%d.mp4"%(r))
|
| 232 |
}
|
| 233 |
datas.append(data_unit)
|
| 234 |
|
|
|
|
| 250 |
"""
|
| 251 |
return video_html
|
| 252 |
|
|
|
|
| 253 |
def generate_component(generate_function, text, motion_len='0', postprocess='IK'):
|
| 254 |
if text == DEFAULT_TEXT or text == "" or text is None:
|
| 255 |
return [None for _ in range(1)]
|
| 256 |
+
# uid = random.randrange(99999)
|
| 257 |
try:
|
| 258 |
motion_len = max(0, min(int(float(motion_len) * 20), 196))
|
| 259 |
except:
|
|
|
|
| 295 |
value="IK",
|
| 296 |
info="Use basic inverse kinematic (IK) for foot contact locking",
|
| 297 |
)
|
| 298 |
+
with gr.Column(scale=1):
|
| 299 |
+
gr.Markdown(
|
| 300 |
+
f"""
|
| 301 |
+
<a href="{pjoin(animation_path, "sample_repeat0.bvh")}" download="sample.bvh"><b>click to download</b></a>
|
| 302 |
+
"""
|
| 303 |
+
)
|
| 304 |
gen_btn = gr.Button("Generate", variant="primary")
|
| 305 |
clear = gr.Button("Clear", variant="secondary")
|
| 306 |
|