Spaces:
Paused
Paused
Update app.py
Browse files
app.py
CHANGED
|
@@ -43,26 +43,30 @@ def generate(image: Image.Image, edit_prompt: str):
|
|
| 43 |
|
| 44 |
global sampler
|
| 45 |
if sampler is None:
|
| 46 |
-
# A inicialização do sampler agora lê os novos parâmetros do .yaml
|
| 47 |
print("Inicializando o XFluxSampler com a configuração completa...")
|
| 48 |
sampler = XFluxSampler(
|
| 49 |
device=device,
|
| 50 |
-
ip_loaded=args.use_ip,
|
| 51 |
-
spatial_condition=args.use_spatial_condition,
|
| 52 |
-
share_position_embedding=args.share_position_embedding,
|
| 53 |
-
use_share_weight_referencenet=args.use_share_weight_referencenet,
|
| 54 |
-
double_block_refnet=args.double_block_refnet,
|
| 55 |
-
single_block_refnet=args.single_block_refnet
|
| 56 |
)
|
| 57 |
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
img = torch.from_numpy((np.array(img) / 127.5) - 1)
|
| 62 |
img = img.permute(2, 0, 1).unsqueeze(0).to(device, dtype=dtype)
|
| 63 |
|
| 64 |
use_image_conditioning = args.use_spatial_condition or args.use_share_weight_referencenet
|
| 65 |
|
|
|
|
|
|
|
|
|
|
| 66 |
result = sampler(
|
| 67 |
prompt=edit_prompt,
|
| 68 |
width=args.sample_width,
|
|
@@ -70,7 +74,7 @@ def generate(image: Image.Image, edit_prompt: str):
|
|
| 70 |
num_steps=args.sample_steps,
|
| 71 |
image_prompt=None,
|
| 72 |
true_gs=args.cfg_scale,
|
| 73 |
-
seed=
|
| 74 |
ip_scale=args.ip_scale if args.use_ip else 1.0,
|
| 75 |
source_image=img if use_image_conditioning else None,
|
| 76 |
)
|
|
|
|
| 43 |
|
| 44 |
global sampler
|
| 45 |
if sampler is None:
|
|
|
|
| 46 |
print("Inicializando o XFluxSampler com a configuração completa...")
|
| 47 |
sampler = XFluxSampler(
|
| 48 |
device=device,
|
| 49 |
+
ip_loaded=args.get('use_ip', False),
|
| 50 |
+
spatial_condition=args.get('use_spatial_condition', False),
|
| 51 |
+
share_position_embedding=args.get('share_position_embedding', False),
|
| 52 |
+
use_share_weight_referencenet=args.get('use_share_weight_referencenet', False),
|
| 53 |
+
double_block_refnet=args.get('double_block_refnet', False),
|
| 54 |
+
single_block_refnet=args.get('single_block_refnet', False)
|
| 55 |
)
|
| 56 |
|
| 57 |
+
# --- CORREÇÃO: Redimensiona a imagem de entrada para corresponder às dimensões de saída ---
|
| 58 |
+
target_width = (args.sample_width // 32) * 32
|
| 59 |
+
target_height = (args.sample_height // 32) * 32
|
| 60 |
+
img = image.resize((target_width, target_height), Image.Resampling.LANCZOS)
|
| 61 |
+
|
| 62 |
img = torch.from_numpy((np.array(img) / 127.5) - 1)
|
| 63 |
img = img.permute(2, 0, 1).unsqueeze(0).to(device, dtype=dtype)
|
| 64 |
|
| 65 |
use_image_conditioning = args.use_spatial_condition or args.use_share_weight_referencenet
|
| 66 |
|
| 67 |
+
# Gera um seed aleatório se for -1
|
| 68 |
+
seed = args.seed if args.seed != -1 else np.random.randint(0, 2**32 - 1)
|
| 69 |
+
|
| 70 |
result = sampler(
|
| 71 |
prompt=edit_prompt,
|
| 72 |
width=args.sample_width,
|
|
|
|
| 74 |
num_steps=args.sample_steps,
|
| 75 |
image_prompt=None,
|
| 76 |
true_gs=args.cfg_scale,
|
| 77 |
+
seed=seed,
|
| 78 |
ip_scale=args.ip_scale if args.use_ip else 1.0,
|
| 79 |
source_image=img if use_image_conditioning else None,
|
| 80 |
)
|