aducsdr commited on
Commit
b426e9f
·
verified ·
1 Parent(s): 0344c73

Update aduc_framework/engineers/deformes3D.py

Browse files
aduc_framework/engineers/deformes3D.py CHANGED
@@ -85,11 +85,27 @@ class Deformes3DEngine:
85
 
86
  logger.info(f"IMAGE SPECIALIST: Ordem para gerar {num_keyframes_to_generate} keyframes (versões LTX).")
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  for i in range(num_keyframes_to_generate):
89
  scene_index = i + 1
90
  current_scene = storyboard[i]
91
  future_scene = storyboard[i + 1] if (i + 1) < len(storyboard) else "A cena final."
92
-
93
  logger.info(f"--> Gerando Keyframe {scene_index}/{num_keyframes_to_generate}...")
94
 
95
  img_prompt = deformes2d_thinker_singleton.get_anticipatory_keyframe_prompt(
@@ -97,47 +113,48 @@ class Deformes3DEngine:
97
  scene_history=previous_prompt,
98
  current_scene_desc=current_scene,
99
  future_scene_desc=future_scene,
100
- last_image_path=current_base_image_path,
101
- fixed_ref_paths=general_ref_paths
102
  )
 
 
 
103
 
104
- context_paths = [current_base_image_path] + [p for p in general_ref_paths if p != current_base_image_path][:3]
105
- ltx_context_paths = list(reversed(context_paths))
106
-
107
- ltx_conditioning_items = []
108
- weight = 0.6
109
- for idx, path in enumerate(ltx_context_paths):
110
- img_pil = Image.open(path).convert("RGB")
111
- img_processed = self._preprocess_image_for_latent_conversion(img_pil, target_resolution_tuple)
112
- pixel_tensor = self._pil_to_pixel_tensor(img_processed)
113
- latent_tensor = vae_manager_singleton.encode(pixel_tensor)
114
- ltx_conditioning_items.append(LatentConditioningItem(latent_tensor, 0, weight))
115
- if idx >= 0: weight -= 0.1
116
 
117
  ltx_base_params = {"guidance_scale": 1.0, "stg_scale": 0.001, "num_inference_steps": 25}
118
  generated_latents, _ = ltx_manager_singleton.generate_latent_fragment(
119
  height=height, width=width,
120
  conditioning_items_data=ltx_conditioning_items,
121
  motion_prompt=img_prompt,
122
- video_total_frames=48, video_fps=24,
123
  **ltx_base_params
124
  )
125
-
126
  final_latent = generated_latents[:, :, -1:, :, :]
127
- upscaled_latent = latent_enhancer_specialist_singleton.upscale(final_latent)
128
- enriched_pixel_tensor = vae_manager_singleton.decode(upscaled_latent)
129
 
130
  pixel_path = os.path.join(self.workspace_dir, f"keyframe_{scene_index:04d}_pixel.png")
131
  latent_path = os.path.join(self.workspace_dir, f"keyframe_{scene_index:04d}_latent.pt")
132
  self.save_image_from_tensor(enriched_pixel_tensor, pixel_path)
133
  torch.save(final_latent.cpu(), latent_path)
134
 
 
 
 
135
  keyframe_data = {
136
  "id": scene_index,
137
  "caminho_pixel": pixel_path,
138
  "caminho_latent": latent_path,
139
  "prompt_keyframe": img_prompt
140
  }
 
141
  all_keyframes_data.append(keyframe_data)
142
 
143
  if progress_callback:
 
85
 
86
  logger.info(f"IMAGE SPECIALIST: Ordem para gerar {num_keyframes_to_generate} keyframes (versões LTX).")
87
 
88
+ ltx_conditioning_items0 = []
89
+
90
+
91
+ img_pil0 = Image.open(initial_ref_path).convert("RGB")
92
+ img_processed0 = self._preprocess_image_for_latent_conversion(img_pil0, target_resolution_tuple)
93
+ pixel_tensor0 = self._pil_to_pixel_tensor(img_processed0)
94
+
95
+ ltx_conditioning_items0.append(LatentConditioningItem(pixel_tensor0, 0, 0.05))
96
+ ltx_conditioning_items0.append(LatentConditioningItem(pixel_tensor0, 24, 0.05))
97
+
98
+ latent_tensorY = pixel_tensor0
99
+ latent_tensorX = latent_tensorY
100
+
101
+ current_base_image_path = initial_ref_path
102
+ past_base_image_path = initial_ref_path
103
+
104
+
105
  for i in range(num_keyframes_to_generate):
106
  scene_index = i + 1
107
  current_scene = storyboard[i]
108
  future_scene = storyboard[i + 1] if (i + 1) < len(storyboard) else "A cena final."
 
109
  logger.info(f"--> Gerando Keyframe {scene_index}/{num_keyframes_to_generate}...")
110
 
111
  img_prompt = deformes2d_thinker_singleton.get_anticipatory_keyframe_prompt(
 
113
  scene_history=previous_prompt,
114
  current_scene_desc=current_scene,
115
  future_scene_desc=future_scene,
116
+ last_image_path=past_base_image_path,
117
+ fixed_ref_paths=current_base_image_path
118
  )
119
+
120
+ past_base_image_path = current_base_image_path
121
+
122
 
123
+
124
+ ltx_conditioning_items = ltx_conditioning_items0
125
+ ltx_conditioning_items.append(LatentConditioningItem(latent_tensorX, 0, 0.4))
126
+ ltx_conditioning_items.append(LatentConditioningItem(latent_tensorY, 8, 0.6))
127
+
128
+ latent_tensorX = latent_tensorY
 
 
 
 
 
 
129
 
130
  ltx_base_params = {"guidance_scale": 1.0, "stg_scale": 0.001, "num_inference_steps": 25}
131
  generated_latents, _ = ltx_manager_singleton.generate_latent_fragment(
132
  height=height, width=width,
133
  conditioning_items_data=ltx_conditioning_items,
134
  motion_prompt=img_prompt,
135
+ video_total_frames=24, video_fps=24,
136
  **ltx_base_params
137
  )
138
+
139
  final_latent = generated_latents[:, :, -1:, :, :]
140
+ #upscaled_latent = latent_enhancer_specialist_singleton.upscale(final_latent)
141
+ enriched_pixel_tensor = vae_manager_singleton.decode(final_latent)
142
 
143
  pixel_path = os.path.join(self.workspace_dir, f"keyframe_{scene_index:04d}_pixel.png")
144
  latent_path = os.path.join(self.workspace_dir, f"keyframe_{scene_index:04d}_latent.pt")
145
  self.save_image_from_tensor(enriched_pixel_tensor, pixel_path)
146
  torch.save(final_latent.cpu(), latent_path)
147
 
148
+ latent_tensorY = latent_path
149
+
150
+
151
  keyframe_data = {
152
  "id": scene_index,
153
  "caminho_pixel": pixel_path,
154
  "caminho_latent": latent_path,
155
  "prompt_keyframe": img_prompt
156
  }
157
+
158
  all_keyframes_data.append(keyframe_data)
159
 
160
  if progress_callback: