Spaces:
Build error
Build error
Updated app.py to include global sesarch of MP4 file
Browse files5 unmodified lines67891011127 unmodified lines202122232425268 unmodified lines3536373839404142434445464748495051525354555 unmodified linesimport gradio as gr# Optional: set this if you want GPU on SpacesUSE_GPU = False # we're on CPU Basic nowdef generate_motion(prompt: str):7 unmodified linesrun_id = str(uuid.uuid4())[:8]# Build commandgpu_flag = "-1" # CPUcmd = ["python","gen_t2m.py",8 unmodified linesexcept subprocess.CalledProcessError as e:raise gr.Error(f"Generation failed. See logs. (Error: {e})")# Find the generated mp4anim_dir = os.path.join("generation", run_id, "animation")mp4_files = glob.glob(os.path.join(anim_dir, "*.mp4"))if not mp4_files:raise gr.Error("No MP4 file was generated. Please check server logs.")# Return the first video file (Gradio will display it)return mp4_files[0]# Build the Gradio interfacedemo = gr.Interface(fn=generate_motion,inputs=gr.Textbox(lines=2, label="Text prompt", placeholder="A person is walking forward."),outputs=gr.Video(label="Generated motion"),title="MoMask: Text-to-Motion Generation",description=(5 unmodified lines6789101112137 unmodified lines212223242526278 unmodified lines3637383940414243444546474849505152535455565758596061626364656667686970717273747576777879805 unmodified linesimport gradio as gr# Optional: set this if you want GPU on Spaces# (We are on CPU Basic, so keep this False.)USE_GPU = Falsedef generate_motion(prompt: str):7 unmodified linesrun_id = str(uuid.uuid4())[:8]# Build commandgpu_flag = "-1" # CPU only on Spacescmd = ["python","gen_t2m.py",8 unmodified linesexcept subprocess.CalledProcessError as e:raise gr.Error(f"Generation failed. See logs. (Error: {e})")# ------------------------------------------------------------------# Find the generated mp4 (be very flexible about where it is)# ------------------------------------------------------------------# Find all mp4 files anywhere in the repoall_mp4s = glob.glob("**/*.mp4", recursive=True)# Prefer files whose path contains this run_idmp4_candidates = [f for f in all_mp4s if run_id in f]# If nothing has run_id, prefer files under "generation/"if not mp4_candidates:mp4_in_generation = [f for f in all_mp4s if "generation" in f]if mp4_in_generation:mp4_candidates = mp4_in_generation# If still nothing, fall back to any mp4 at allif not mp4_candidates and all_mp4s:mp4_candidates = all_mp4s# If we still have no mp4s, something went wrong in gen_t2m.pyif not mp4_candidates:raise gr.Error("No MP4 file was generated. Please check server logs.")# Pick the most recently modified mp4 as the outputmp4_path = max(mp4_candidates, key=os.path.getmtime)# Return the video path (Gradio will display it)return mp4_path# Build the Gradio interfacedemo = gr.Interface(fn=generate_motion,inputs=gr.Textbox(lines=2,label="Text prompt",placeholder="A person is walking forward.",),outputs=gr.Video(label="Generated motion"),title="MoMask: Text-to-Motion Generation",description=(
app.py+34-9