linoyts HF Staff commited on
Commit
3f681ea
·
verified ·
1 Parent(s): 23c5113

revert to plain track_tqdm progress (Z-Image pattern), drop generator/callback

Browse files
Files changed (1) hide show
  1. app.py +3 -38
app.py CHANGED
@@ -97,35 +97,6 @@ def _duration(*args, **kwargs):
97
  return int(70 + int(num_frames) * 1.3)
98
 
99
 
100
-
101
- class StreamRun:
102
- """Run pipe() in a thread; drive native gr.Progress from a generator (forwards on ZeroGPU)."""
103
- def __init__(self, call_pipe, num_steps):
104
- self.call_pipe, self.num_steps = call_pipe, num_steps
105
- self.state = {"step": 0}
106
- self.holder = {}
107
- def _cb(self, p, i, t, kw):
108
- self.state["step"] = i + 1
109
- return {}
110
- def _run(self):
111
- try:
112
- self.holder["out"] = self.call_pipe(self._cb)
113
- except Exception as e:
114
- self.holder["err"] = e
115
- def stream(self):
116
- th = threading.Thread(target=self._run); th.start()
117
- while th.is_alive():
118
- s = self.state["step"]
119
- yield (s / self.num_steps if s else 0.0, f"step {s}/{self.num_steps}" if s else "Loading model…")
120
- time.sleep(0.4)
121
- th.join()
122
- if "err" in self.holder:
123
- raise self.holder["err"]
124
- @property
125
- def result(self):
126
- return self.holder["out"]
127
-
128
-
129
  @spaces.GPU(duration=_duration)
130
  def outpaint(video, canvas_key, prompt, num_frames, seed, randomize,
131
  progress=gr.Progress(track_tqdm=True)):
@@ -168,8 +139,7 @@ def outpaint(video, canvas_key, prompt, num_frames, seed, randomize,
168
  progress((i + 1) / NUM_STEPS, desc=f"Outpainting — step {i + 1}/{NUM_STEPS}")
169
  return {}
170
 
171
- def _call_pipe(_cb):
172
- return pipe(
173
  prompt=full_prompt, negative_prompt="",
174
  reference_conditions=[LTX2ReferenceCondition(frames=ref, strength=1.0)],
175
  conditioning_attention_mask=attn_mask, reference_downscale_factor=1,
@@ -177,13 +147,8 @@ def outpaint(video, canvas_key, prompt, num_frames, seed, randomize,
177
  num_inference_steps=NUM_STEPS, sigmas=DISTILLED_SIGMA_VALUES,
178
  guidance_scale=1.0, stg_scale=0.0, audio_guidance_scale=1.0, audio_stg_scale=0.0,
179
  generator=torch.Generator(device="cuda").manual_seed(seed),
180
- output_type="np", return_dict=False, callback_on_step_end=_cb,
181
  )
182
- runner = StreamRun(_call_pipe, NUM_STEPS)
183
- for _frac, _desc in runner.stream():
184
- progress(_frac, desc=_desc)
185
- yield gr.update(), gr.update()
186
- video_out, audio_out = runner.result
187
 
188
  # keep the original pixels exactly in the center; use generated pixels in the margins (feathered).
189
  gen = (np.clip(video_out[0], 0, 1) * 255).astype(np.uint8)
@@ -198,7 +163,7 @@ def outpaint(video, canvas_key, prompt, num_frames, seed, randomize,
198
 
199
  out_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
200
  _export(out, audio_out, out_path)
201
- yield out_path, seed
202
 
203
 
204
  with gr.Blocks(title="LTX-2.3 Video Outpaint") as demo:
 
97
  return int(70 + int(num_frames) * 1.3)
98
 
99
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
100
  @spaces.GPU(duration=_duration)
101
  def outpaint(video, canvas_key, prompt, num_frames, seed, randomize,
102
  progress=gr.Progress(track_tqdm=True)):
 
139
  progress((i + 1) / NUM_STEPS, desc=f"Outpainting — step {i + 1}/{NUM_STEPS}")
140
  return {}
141
 
142
+ video_out, audio_out = pipe(
 
143
  prompt=full_prompt, negative_prompt="",
144
  reference_conditions=[LTX2ReferenceCondition(frames=ref, strength=1.0)],
145
  conditioning_attention_mask=attn_mask, reference_downscale_factor=1,
 
147
  num_inference_steps=NUM_STEPS, sigmas=DISTILLED_SIGMA_VALUES,
148
  guidance_scale=1.0, stg_scale=0.0, audio_guidance_scale=1.0, audio_stg_scale=0.0,
149
  generator=torch.Generator(device="cuda").manual_seed(seed),
150
+ output_type="np", return_dict=False,
151
  )
 
 
 
 
 
152
 
153
  # keep the original pixels exactly in the center; use generated pixels in the margins (feathered).
154
  gen = (np.clip(video_out[0], 0, 1) * 255).astype(np.uint8)
 
163
 
164
  out_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
165
  _export(out, audio_out, out_path)
166
+ return out_path, seed
167
 
168
 
169
  with gr.Blocks(title="LTX-2.3 Video Outpaint") as demo: