Spaces:
Paused
Paused
Update api/ltx_server_refactored_complete.py
Browse files
api/ltx_server_refactored_complete.py
CHANGED
|
@@ -283,6 +283,14 @@ class VideoService:
|
|
| 283 |
downscaled_height = self._align(int(height_padded * downscale_factor), vae_scale_factor)
|
| 284 |
downscaled_width = self._align(int(width_padded * downscale_factor), vae_scale_factor)
|
| 285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 286 |
# 1. Começa com a configuração padrão
|
| 287 |
first_pass_config = self.config.get("first_pass", {}).copy()
|
| 288 |
|
|
@@ -351,6 +359,39 @@ class VideoService:
|
|
| 351 |
video_path = self._save_and_log_video(pixel_tensor, f"{base_filename}_{seed}")
|
| 352 |
return str(video_path), str(final_latents_path), seed
|
| 353 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 354 |
@log_function_io
|
| 355 |
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int) -> List[ConditioningItem]:
|
| 356 |
"""[UNIFIED] Prepares ConditioningItems from a mixed list of file paths and tensors."""
|
|
|
|
| 283 |
downscaled_height = self._align(int(height_padded * downscale_factor), vae_scale_factor)
|
| 284 |
downscaled_width = self._align(int(width_padded * downscale_factor), vae_scale_factor)
|
| 285 |
|
| 286 |
+
for item in original_conditioning_items:
|
| 287 |
+
moved_tensor = item.media_item.to(self.main_device, dtype=self.runtime_autocast_dtype)
|
| 288 |
+
processed_conditioning_items.append(ConditioningItem(
|
| 289 |
+
media_item=moved_tensor,
|
| 290 |
+
media_frame_number=item.media_frame_number,
|
| 291 |
+
conditioning_strength=item.conditioning_strength
|
| 292 |
+
))
|
| 293 |
+
|
| 294 |
# 1. Começa com a configuração padrão
|
| 295 |
first_pass_config = self.config.get("first_pass", {}).copy()
|
| 296 |
|
|
|
|
| 359 |
video_path = self._save_and_log_video(pixel_tensor, f"{base_filename}_{seed}")
|
| 360 |
return str(video_path), str(final_latents_path), seed
|
| 361 |
|
| 362 |
+
|
| 363 |
+
|
| 364 |
+
@log_function_io
|
| 365 |
+
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int) -> List[Condition-ingItem]:
|
| 366 |
+
"""
|
| 367 |
+
[CORRIGIDO] Prepara ConditioningItems, mas mantém os tensores na CPU.
|
| 368 |
+
O movimento para a GPU será tratado posteriormente.
|
| 369 |
+
"""
|
| 370 |
+
if not items_list: return []
|
| 371 |
+
height_padded, width_padded = self._align(height), self._align(width)
|
| 372 |
+
padding_values = calculate_padding(height, width, height_padded, width_padded)
|
| 373 |
+
|
| 374 |
+
conditioning_items = []
|
| 375 |
+
for media_item, frame, weight in items_list:
|
| 376 |
+
if isinstance(media_item, str):
|
| 377 |
+
# Carrega a imagem e aplica padding, mas mantém na CPU.
|
| 378 |
+
tensor = load_image_to_tensor_with_resize_and_crop(media_item, height, width)
|
| 379 |
+
tensor = torch.nn.functional.pad(tensor, padding_values)
|
| 380 |
+
# O tensor permanece na CPU aqui.
|
| 381 |
+
elif isinstance(media_item, torch.Tensor):
|
| 382 |
+
# Se for um tensor (como o de overlap), apenas garante que está na CPU.
|
| 383 |
+
tensor = media_item.cpu()
|
| 384 |
+
else:
|
| 385 |
+
logging.warning(f"Unknown conditioning media type: {type(media_item)}. Skipping.")
|
| 386 |
+
continue
|
| 387 |
+
|
| 388 |
+
safe_frame = max(0, min(int(frame), num_frames - 1))
|
| 389 |
+
conditioning_items.append(ConditioningItem(tensor, safe_frame, float(weight)))
|
| 390 |
+
|
| 391 |
+
self._log_conditioning_items(conditioning_items)
|
| 392 |
+
return conditioning_items
|
| 393 |
+
|
| 394 |
+
|
| 395 |
@log_function_io
|
| 396 |
def prepare_condition_items(self, items_list: List, height: int, width: int, num_frames: int) -> List[ConditioningItem]:
|
| 397 |
"""[UNIFIED] Prepares ConditioningItems from a mixed list of file paths and tensors."""
|