Hemanth0004 commited on
Commit
117b1da
·
verified ·
1 Parent(s): 093f1a4

Updated app.py to include global sesarch of MP4 file

Browse files
Files changed (1) hide show
  1. app.py +34 -9
app.py CHANGED
@@ -6,7 +6,8 @@ import subprocess
6
  import gradio as gr
7
 
8
  # Optional: set this if you want GPU on Spaces
9
- USE_GPU = False # we're on CPU Basic now
 
10
 
11
 
12
  def generate_motion(prompt: str):
@@ -20,7 +21,7 @@ def generate_motion(prompt: str):
20
  run_id = str(uuid.uuid4())[:8]
21
 
22
  # Build command
23
- gpu_flag = "-1" # CPU
24
  cmd = [
25
  "python",
26
  "gen_t2m.py",
@@ -35,21 +36,45 @@ def generate_motion(prompt: str):
35
  except subprocess.CalledProcessError as e:
36
  raise gr.Error(f"Generation failed. See logs. (Error: {e})")
37
 
38
- # Find the generated mp4
39
- anim_dir = os.path.join("generation", run_id, "animation")
40
- mp4_files = glob.glob(os.path.join(anim_dir, "*.mp4"))
41
 
42
- if not mp4_files:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
43
  raise gr.Error("No MP4 file was generated. Please check server logs.")
44
 
45
- # Return the first video file (Gradio will display it)
46
- return mp4_files[0]
 
 
 
47
 
48
 
49
  # Build the Gradio interface
50
  demo = gr.Interface(
51
  fn=generate_motion,
52
- inputs=gr.Textbox(lines=2, label="Text prompt", placeholder="A person is walking forward."),
 
 
 
 
53
  outputs=gr.Video(label="Generated motion"),
54
  title="MoMask: Text-to-Motion Generation",
55
  description=(
 
6
  import gradio as gr
7
 
8
  # Optional: set this if you want GPU on Spaces
9
+ # (We are on CPU Basic, so keep this False.)
10
+ USE_GPU = False
11
 
12
 
13
  def generate_motion(prompt: str):
 
21
  run_id = str(uuid.uuid4())[:8]
22
 
23
  # Build command
24
+ gpu_flag = "-1" # CPU only on Spaces
25
  cmd = [
26
  "python",
27
  "gen_t2m.py",
 
36
  except subprocess.CalledProcessError as e:
37
  raise gr.Error(f"Generation failed. See logs. (Error: {e})")
38
 
39
+ # ------------------------------------------------------------------
40
+ # Find the generated mp4 (be very flexible about where it is)
41
+ # ------------------------------------------------------------------
42
 
43
+ # Find all mp4 files anywhere in the repo
44
+ all_mp4s = glob.glob("**/*.mp4", recursive=True)
45
+
46
+ # Prefer files whose path contains this run_id
47
+ mp4_candidates = [f for f in all_mp4s if run_id in f]
48
+
49
+ # If nothing has run_id, prefer files under "generation/"
50
+ if not mp4_candidates:
51
+ mp4_in_generation = [f for f in all_mp4s if "generation" in f]
52
+ if mp4_in_generation:
53
+ mp4_candidates = mp4_in_generation
54
+
55
+ # If still nothing, fall back to any mp4 at all
56
+ if not mp4_candidates and all_mp4s:
57
+ mp4_candidates = all_mp4s
58
+
59
+ # If we still have no mp4s, something went wrong in gen_t2m.py
60
+ if not mp4_candidates:
61
  raise gr.Error("No MP4 file was generated. Please check server logs.")
62
 
63
+ # Pick the most recently modified mp4 as the output
64
+ mp4_path = max(mp4_candidates, key=os.path.getmtime)
65
+
66
+ # Return the video path (Gradio will display it)
67
+ return mp4_path
68
 
69
 
70
  # Build the Gradio interface
71
  demo = gr.Interface(
72
  fn=generate_motion,
73
+ inputs=gr.Textbox(
74
+ lines=2,
75
+ label="Text prompt",
76
+ placeholder="A person is walking forward.",
77
+ ),
78
  outputs=gr.Video(label="Generated motion"),
79
  title="MoMask: Text-to-Motion Generation",
80
  description=(