Daankular commited on
Commit
24a1162
·
1 Parent(s): 4fe229d

Stream subprocess output line-by-line; increase GPU duration to 360s

Browse files
Files changed (1) hide show
  1. app.py +23 -31
app.py CHANGED
@@ -105,9 +105,13 @@ setup()
105
  RESOLUTIONS = ["832x480", "480x832", "640x640", "1024x576", "576x1024"]
106
 
107
 
108
- @spaces.GPU(duration=180)
109
- def _generate(image: str, prompt: str, model: str, steps: int,
110
- guidance_scale: float, resolution: str, frames: int, seed: int):
 
 
 
 
111
  out_file = Path(tempfile.mkdtemp()) / "output.mp4"
112
  env = {**os.environ, "WAN2GP_ROOT": str(WAN2GP_ROOT)}
113
 
@@ -116,46 +120,34 @@ def _generate(image: str, prompt: str, model: str, steps: int,
116
  "--image", image,
117
  "--prompt", prompt,
118
  "--output", str(out_file),
119
- "--model", model,
120
- "--seed", str(seed),
121
  "--resolution", resolution,
122
- "--steps", str(steps),
123
- "--guidance_scale", str(guidance_scale),
124
- "--frames", str(frames),
125
  ]
126
 
127
  log_lines = []
128
- proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
129
  text=True, bufsize=1, env=env)
 
130
  for line in proc.stdout:
131
- log_lines.append(line.rstrip())
132
- print(line, end="")
133
- stderr_out = proc.stderr.read()
134
- proc.wait()
135
- if stderr_out:
136
- log_lines.append("--- stderr ---")
137
- log_lines.extend(stderr_out.splitlines())
138
- print(stderr_out)
139
 
 
140
  log = "\n".join(log_lines)
 
141
  if proc.returncode != 0 or not out_file.exists():
142
- return None, log + "\n[ERROR]"
 
143
 
144
  final = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
145
  shutil.copy2(out_file, final.name)
146
- return final.name, log + "\n[DONE]"
147
-
148
-
149
- def generate_video(image, prompt, resolution, steps, guidance_scale, frames, seed):
150
- if image is None:
151
- raise gr.Error("Please upload an image.")
152
- if not prompt.strip():
153
- raise gr.Error("Please enter a prompt.")
154
- yield None, f"Generating {resolution}, {steps} steps…"
155
- video, log = _generate(image, prompt, "sulphur-2",
156
- int(steps), float(guidance_scale),
157
- resolution, int(frames), int(seed))
158
- yield video, log
159
 
160
 
161
  with gr.Blocks(title="Sulphur — Image to Video") as demo:
 
105
  RESOLUTIONS = ["832x480", "480x832", "640x640", "1024x576", "576x1024"]
106
 
107
 
108
+ @spaces.GPU(duration=360)
109
+ def generate_video(image, prompt, resolution, steps, guidance_scale, frames, seed):
110
+ if image is None:
111
+ raise gr.Error("Please upload an image.")
112
+ if not prompt.strip():
113
+ raise gr.Error("Please enter a prompt.")
114
+
115
  out_file = Path(tempfile.mkdtemp()) / "output.mp4"
116
  env = {**os.environ, "WAN2GP_ROOT": str(WAN2GP_ROOT)}
117
 
 
120
  "--image", image,
121
  "--prompt", prompt,
122
  "--output", str(out_file),
123
+ "--model", "sulphur-2",
124
+ "--seed", str(int(seed)),
125
  "--resolution", resolution,
126
+ "--steps", str(int(steps)),
127
+ "--guidance_scale", str(float(guidance_scale)),
128
+ "--frames", str(int(frames)),
129
  ]
130
 
131
  log_lines = []
132
+ proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
133
  text=True, bufsize=1, env=env)
134
+
135
  for line in proc.stdout:
136
+ stripped = line.rstrip()
137
+ log_lines.append(stripped)
138
+ print(stripped)
139
+ yield None, "\n".join(log_lines[-30:])
 
 
 
 
140
 
141
+ proc.wait()
142
  log = "\n".join(log_lines)
143
+
144
  if proc.returncode != 0 or not out_file.exists():
145
+ yield None, log + "\n\n[ERROR] Generation failed."
146
+ return
147
 
148
  final = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False)
149
  shutil.copy2(out_file, final.name)
150
+ yield final.name, log + "\n\n[DONE]"
 
 
 
 
 
 
 
 
 
 
 
 
151
 
152
 
153
  with gr.Blocks(title="Sulphur — Image to Video") as demo: