MMM-Demo / app.py
pbichpur's picture
Update app.py
04dea95 verified
import subprocess
import glob
import os
import gradio as gr
def find_latest_file(base_path, extension):
files = glob.glob(f"{base_path}/*.{extension}")
return max(files, key=os.path.getctime) if files else None
def generate_html_only(prompt: str, length: int):
# 1) Run your generation script
cmd = [
"python", "generate.py",
"--resume-pth", "output/vq/2023-07-19-04-17-17_12_VQVAE_20batchResetNRandom_8192_32/net_last.pth",
"--resume-trans", "output/t2m/2023-10-10-03-17-01_HML3D_44_crsAtt2lyr_mask0.5-1/net_last.pth",
"--text", prompt,
"--length", str(length),
]
subprocess.run(cmd, check=True)
# 2) Pick up the latest HTML output
html_file = find_latest_file("output", "html")
if html_file is None:
return "<p style='color:red;'>Error: no HTML file found.</p>"
# 3) Read & wrap it in an iframe so it renders fully in your client
with open(html_file, "r") as f:
raw_html = f.read()
iframe = (
"<iframe srcdoc=\""
+ raw_html.replace('"', "&quot;")
+ "\" width=\"100%\" height=\"800px\" style=\"border:none;\"></iframe>"
)
return iframe
# Build a minimal Gradio interface
demo = gr.Interface(
fn=generate_html_only,
inputs=[
gr.Textbox(label="Motion Prompt", lines=3, placeholder="e.g. A person walks forward and spins."),
gr.Number(label="Length", value=156)
],
outputs=gr.HTML(label="3D Animation (HTML)"),
title="MMM Motion Generator",
description="Enter a text prompt and length to generate the 3D skeleton animation."
)
if __name__ == "__main__":
demo.launch()