Spaces:
Paused
Paused
Update api/ltx_server_refactored_complete.py
Browse files
api/ltx_server_refactored_complete.py
CHANGED
|
@@ -210,7 +210,8 @@ class VideoService:
|
|
| 210 |
current_frames = self._align(current_frames, alignment_rule='n*8+1')
|
| 211 |
|
| 212 |
current_conditions = kwargs.get("initial_conditions", []) if i == 0 else []
|
| 213 |
-
if overlap_condition_item:
|
|
|
|
| 214 |
|
| 215 |
chunk_latents = self._generate_single_chunk_low(
|
| 216 |
prompt=chunk_prompt, num_frames=current_frames, seed=used_seed + i,
|
|
@@ -219,9 +220,28 @@ class VideoService:
|
|
| 219 |
if chunk_latents is None: raise RuntimeError(f"Failed to generate latents for scene {i+1}.")
|
| 220 |
|
| 221 |
if is_narrative and i < num_chunks - 1:
|
|
|
|
| 222 |
overlap_latents = chunk_latents[:, :, -overlap_frames:, :, :].clone()
|
| 223 |
-
|
| 224 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
if i > 0:
|
| 226 |
chunk_latents = chunk_latents[:, :, overlap_frames:, :, :]
|
| 227 |
|
|
|
|
| 210 |
current_frames = self._align(current_frames, alignment_rule='n*8+1')
|
| 211 |
|
| 212 |
current_conditions = kwargs.get("initial_conditions", []) if i == 0 else []
|
| 213 |
+
if overlap_condition_item:
|
| 214 |
+
current_conditions.append(overlap_condition_item)
|
| 215 |
|
| 216 |
chunk_latents = self._generate_single_chunk_low(
|
| 217 |
prompt=chunk_prompt, num_frames=current_frames, seed=used_seed + i,
|
|
|
|
| 220 |
if chunk_latents is None: raise RuntimeError(f"Failed to generate latents for scene {i+1}.")
|
| 221 |
|
| 222 |
if is_narrative and i < num_chunks - 1:
|
| 223 |
+
# 1. Criar tensor overlap latente
|
| 224 |
overlap_latents = chunk_latents[:, :, -overlap_frames:, :, :].clone()
|
| 225 |
+
logging.info(f"Criado overlap latente com shape: {list(overlap_latents.shape)}")
|
| 226 |
+
|
| 227 |
+
# 2. DECODIFICA o latente de volta para um tensor de PIXEL
|
| 228 |
+
logging.info("Decodificando latente de overlap para tensor de pixel...")
|
| 229 |
+
overlap_pixel_tensor = vae_manager_singleton.decode(
|
| 230 |
+
overlap_latents,
|
| 231 |
+
decode_timestep=float(self.config.get("decode_timestep", 0.05))
|
| 232 |
+
)
|
| 233 |
+
# O resultado de decode() está na CPU, no formato (B, C, F, H, W) e [0, 1]
|
| 234 |
+
# Precisamos normalizá-lo para [-1, 1] que é o que o pipeline espera.
|
| 235 |
+
overlap_pixel_tensor_normalized = (overlap_pixel_tensor * 2.0) - 1.0
|
| 236 |
+
logging.info(f"Tensor de pixel de overlap criado com shape: {list(overlap_pixel_tensor_normalized.shape)}")
|
| 237 |
+
|
| 238 |
+
# 3. Cria o ConditioningItem com o TENSOR DE PIXEL, não com o latente.
|
| 239 |
+
overlap_condition_item = ConditioningItem(
|
| 240 |
+
media_item=overlap_pixel_tensor_normalized,
|
| 241 |
+
media_frame_number=0,conditioning_strength=1.0
|
| 242 |
+
)
|
| 243 |
+
|
| 244 |
+
|
| 245 |
if i > 0:
|
| 246 |
chunk_latents = chunk_latents[:, :, overlap_frames:, :, :]
|
| 247 |
|