Spaces:
Sleeping
Sleeping
Update ltx_worker_upscaler.py
Browse files- ltx_worker_upscaler.py +2 -7
ltx_worker_upscaler.py
CHANGED
|
@@ -12,10 +12,11 @@ import numpy as np
|
|
| 12 |
import imageio
|
| 13 |
from pathlib import Path
|
| 14 |
import huggingface_hub
|
|
|
|
| 15 |
|
| 16 |
from inference import create_ltx_video_pipeline
|
| 17 |
from ltx_video.models.autoencoders.latent_upsampler import LatentUpsampler
|
| 18 |
-
from ltx_video.models.autoencoders.vae_encode import vae_decode
|
| 19 |
|
| 20 |
class LtxUpscaler:
|
| 21 |
def __init__(self, device_id='cuda:0'):
|
|
@@ -75,15 +76,10 @@ class LtxUpscaler:
|
|
| 75 |
def upscale_latents_to_video(self, latent_path: str, output_path: str, video_fps: int):
|
| 76 |
print(f"UPSCALER ({self.device}): Processando latentes de {os.path.basename(latent_path)}")
|
| 77 |
|
| 78 |
-
# Carrega os latentes do disco e os envia para a GPU
|
| 79 |
latents = torch.load(latent_path).to(self.device, dtype=self.model_dtype)
|
| 80 |
|
| 81 |
-
# PASSO 1: Upscale Espacial (não precisamos mais de vae_encode)
|
| 82 |
upsampled_latents = self.latent_upsampler(latents)
|
| 83 |
|
| 84 |
-
# (Opcional: PASSO 2 - Upscale Temporal seria inserido aqui no futuro)
|
| 85 |
-
|
| 86 |
-
# PASSO 3: Decodificação Final
|
| 87 |
decode_timestep = torch.tensor([0.0] * upsampled_latents.shape[0], device=self.device)
|
| 88 |
upsampled_video_tensor = vae_decode(
|
| 89 |
upsampled_latents, self.vae, is_video=True, timestep=decode_timestep
|
|
@@ -110,7 +106,6 @@ class LtxUpscaler:
|
|
| 110 |
)
|
| 111 |
|
| 112 |
decoded_tensor = (decoded_tensor.clamp(-1, 1) + 1) / 2.0
|
| 113 |
-
# Shape: (B, C, F, H, W) -> (H, W, C)
|
| 114 |
numpy_image = (decoded_tensor[0].permute(2, 3, 1, 0).squeeze().cpu().float().numpy() * 255).astype(np.uint8)
|
| 115 |
return Image.fromarray(numpy_image)
|
| 116 |
#--- END OF MODIFIED FILE app_fluxContext_Ltx/ltx_worker_upscaler.py ---
|
|
|
|
| 12 |
import imageio
|
| 13 |
from pathlib import Path
|
| 14 |
import huggingface_hub
|
| 15 |
+
from PIL import Image # <--- IMPORTAÇÃO ADICIONADA AQUI
|
| 16 |
|
| 17 |
from inference import create_ltx_video_pipeline
|
| 18 |
from ltx_video.models.autoencoders.latent_upsampler import LatentUpsampler
|
| 19 |
+
from ltx_video.models.autoencoders.vae_encode import vae_encode, vae_decode
|
| 20 |
|
| 21 |
class LtxUpscaler:
|
| 22 |
def __init__(self, device_id='cuda:0'):
|
|
|
|
| 76 |
def upscale_latents_to_video(self, latent_path: str, output_path: str, video_fps: int):
|
| 77 |
print(f"UPSCALER ({self.device}): Processando latentes de {os.path.basename(latent_path)}")
|
| 78 |
|
|
|
|
| 79 |
latents = torch.load(latent_path).to(self.device, dtype=self.model_dtype)
|
| 80 |
|
|
|
|
| 81 |
upsampled_latents = self.latent_upsampler(latents)
|
| 82 |
|
|
|
|
|
|
|
|
|
|
| 83 |
decode_timestep = torch.tensor([0.0] * upsampled_latents.shape[0], device=self.device)
|
| 84 |
upsampled_video_tensor = vae_decode(
|
| 85 |
upsampled_latents, self.vae, is_video=True, timestep=decode_timestep
|
|
|
|
| 106 |
)
|
| 107 |
|
| 108 |
decoded_tensor = (decoded_tensor.clamp(-1, 1) + 1) / 2.0
|
|
|
|
| 109 |
numpy_image = (decoded_tensor[0].permute(2, 3, 1, 0).squeeze().cpu().float().numpy() * 255).astype(np.uint8)
|
| 110 |
return Image.fromarray(numpy_image)
|
| 111 |
#--- END OF MODIFIED FILE app_fluxContext_Ltx/ltx_worker_upscaler.py ---
|