linoyts HF Staff commited on
Commit
0f99044
·
verified ·
1 Parent(s): a385137

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

Browse files
Files changed (1) hide show
  1. app.py +4 -39
app.py CHANGED
@@ -93,38 +93,9 @@ def _duration(*args, **kwargs):
93
  return int(120 + int(num_frames) * per_frame)
94
 
95
 
96
-
97
- class StreamRun:
98
- """Run pipe() in a thread; yield live status strings (generator yields DO forward on ZeroGPU)."""
99
- def __init__(self, call_pipe, num_steps):
100
- self.call_pipe, self.num_steps = call_pipe, num_steps
101
- self.state = {"step": 0}
102
- self.holder = {}
103
- def _cb(self, p, i, t, kw):
104
- self.state["step"] = i + 1
105
- return {}
106
- def _run(self):
107
- try:
108
- self.holder["out"] = self.call_pipe(self._cb)
109
- except Exception as e:
110
- self.holder["err"] = e
111
- def stream(self):
112
- th = threading.Thread(target=self._run); th.start()
113
- while th.is_alive():
114
- s = self.state["step"]
115
- yield (s / self.num_steps if s else 0.0, f"step {s}/{self.num_steps}" if s else "Loading model…")
116
- time.sleep(0.4)
117
- th.join()
118
- if "err" in self.holder:
119
- raise self.holder["err"]
120
- @property
121
- def result(self):
122
- return self.holder["out"]
123
-
124
-
125
  @spaces.GPU(duration=_duration)
126
  def shave(video, prompt, preset, num_frames, seed, randomize,
127
- progress=gr.Progress()):
128
  if video is None:
129
  raise gr.Error("Please upload a video of a bearded subject.")
130
  if randomize:
@@ -140,8 +111,7 @@ def shave(video, prompt, preset, num_frames, seed, randomize,
140
  full_prompt = _build_prompt(prompt)
141
 
142
 
143
- def _call_pipe(_cb):
144
- return pipe(
145
  prompt=full_prompt, negative_prompt=NEGATIVE,
146
  reference_conditions=[LTX2ReferenceCondition(frames=ref, strength=1.0)],
147
  reference_downscale_factor=1,
@@ -149,16 +119,11 @@ def shave(video, prompt, preset, num_frames, seed, randomize,
149
  num_inference_steps=NUM_STEPS, guidance_scale=GUIDANCE,
150
  spatio_temporal_guidance_blocks=STG_BLOCKS,
151
  generator=torch.Generator(device="cuda").manual_seed(seed),
152
- output_type="np", return_dict=False, callback_on_step_end=_cb,
153
  )
154
- runner = StreamRun(_call_pipe, NUM_STEPS)
155
- for _frac, _desc in runner.stream():
156
- progress(_frac, desc=_desc)
157
- yield gr.update(), gr.update()
158
- video_out, audio_out = runner.result
159
  out_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
160
  _export(video_out[0], audio_out, out_path)
161
- yield out_path, seed
162
 
163
 
164
  with gr.Blocks(title="LTX-2.3 Beard Removal") as demo:
 
93
  return int(120 + int(num_frames) * per_frame)
94
 
95
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
96
  @spaces.GPU(duration=_duration)
97
  def shave(video, prompt, preset, num_frames, seed, randomize,
98
+ progress=gr.Progress(track_tqdm=True)):
99
  if video is None:
100
  raise gr.Error("Please upload a video of a bearded subject.")
101
  if randomize:
 
111
  full_prompt = _build_prompt(prompt)
112
 
113
 
114
+ video_out, audio_out = pipe(
 
115
  prompt=full_prompt, negative_prompt=NEGATIVE,
116
  reference_conditions=[LTX2ReferenceCondition(frames=ref, strength=1.0)],
117
  reference_downscale_factor=1,
 
119
  num_inference_steps=NUM_STEPS, guidance_scale=GUIDANCE,
120
  spatio_temporal_guidance_blocks=STG_BLOCKS,
121
  generator=torch.Generator(device="cuda").manual_seed(seed),
122
+ output_type="np", return_dict=False,
123
  )
 
 
 
 
 
124
  out_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
125
  _export(video_out[0], audio_out, out_path)
126
+ return out_path, seed
127
 
128
 
129
  with gr.Blocks(title="LTX-2.3 Beard Removal") as demo: