linoyts HF Staff commited on
Commit
739f22d
·
verified ·
1 Parent(s): 2621fa2

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
@@ -98,35 +98,6 @@ def _duration(*args, **kwargs):
98
  return int(60 + int(num_frames) * per_frame)
99
 
100
 
101
-
102
- class StreamRun:
103
- """Run pipe() in a thread; drive native gr.Progress from a generator (forwards on ZeroGPU)."""
104
- def __init__(self, call_pipe, num_steps):
105
- self.call_pipe, self.num_steps = call_pipe, num_steps
106
- self.state = {"step": 0}
107
- self.holder = {}
108
- def _cb(self, p, i, t, kw):
109
- self.state["step"] = i + 1
110
- return {}
111
- def _run(self):
112
- try:
113
- self.holder["out"] = self.call_pipe(self._cb)
114
- except Exception as e:
115
- self.holder["err"] = e
116
- def stream(self):
117
- th = threading.Thread(target=self._run); th.start()
118
- while th.is_alive():
119
- s = self.state["step"]
120
- yield (s / self.num_steps if s else 0.0, f"step {s}/{self.num_steps}" if s else "Loading model…")
121
- time.sleep(0.4)
122
- th.join()
123
- if "err" in self.holder:
124
- raise self.holder["err"]
125
- @property
126
- def result(self):
127
- return self.holder["out"]
128
-
129
-
130
  @spaces.GPU(duration=_duration)
131
  def decompress(video, prompt, preset, num_frames, seed, randomize,
132
  progress=gr.Progress(track_tqdm=True)):
@@ -148,8 +119,7 @@ def decompress(video, prompt, preset, num_frames, seed, randomize,
148
  progress((i + 1) / NUM_STEPS, desc=f"Restoring — step {i + 1}/{NUM_STEPS}")
149
  return {}
150
 
151
- def _call_pipe(_cb):
152
- return pipe(
153
  prompt=prompt, negative_prompt="",
154
  reference_conditions=[LTX2ReferenceCondition(frames=ref, strength=1.0)],
155
  reference_downscale_factor=1,
@@ -157,16 +127,11 @@ def decompress(video, prompt, preset, num_frames, seed, randomize,
157
  num_inference_steps=NUM_STEPS, sigmas=DISTILLED_SIGMA_VALUES,
158
  guidance_scale=1.0, stg_scale=0.0, audio_guidance_scale=1.0, audio_stg_scale=0.0,
159
  generator=torch.Generator(device="cuda").manual_seed(seed),
160
- output_type="np", return_dict=False, callback_on_step_end=_cb,
161
  )
162
- runner = StreamRun(_call_pipe, NUM_STEPS)
163
- for _frac, _desc in runner.stream():
164
- progress(_frac, desc=_desc)
165
- yield gr.update(), gr.update()
166
- video_out, audio_out = runner.result
167
  out_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
168
  _export(video_out[0], audio_out, out_path)
169
- yield out_path, seed
170
 
171
 
172
  with gr.Blocks(title="LTX-2.3 Decompress") as demo:
 
98
  return int(60 + int(num_frames) * per_frame)
99
 
100
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
101
  @spaces.GPU(duration=_duration)
102
  def decompress(video, prompt, preset, num_frames, seed, randomize,
103
  progress=gr.Progress(track_tqdm=True)):
 
119
  progress((i + 1) / NUM_STEPS, desc=f"Restoring — step {i + 1}/{NUM_STEPS}")
120
  return {}
121
 
122
+ video_out, audio_out = pipe(
 
123
  prompt=prompt, negative_prompt="",
124
  reference_conditions=[LTX2ReferenceCondition(frames=ref, strength=1.0)],
125
  reference_downscale_factor=1,
 
127
  num_inference_steps=NUM_STEPS, sigmas=DISTILLED_SIGMA_VALUES,
128
  guidance_scale=1.0, stg_scale=0.0, audio_guidance_scale=1.0, audio_stg_scale=0.0,
129
  generator=torch.Generator(device="cuda").manual_seed(seed),
130
+ output_type="np", return_dict=False,
131
  )
 
 
 
 
 
132
  out_path = tempfile.NamedTemporaryFile(suffix=".mp4", delete=False).name
133
  _export(video_out[0], audio_out, out_path)
134
+ return out_path, seed
135
 
136
 
137
  with gr.Blocks(title="LTX-2.3 Decompress") as demo: