Astridkraft commited on
Commit
ca76d8b
·
verified ·
1 Parent(s): 6db455d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -3
app.py CHANGED
@@ -1047,17 +1047,23 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
1047
  padding_info = None
1048
  scaled_image = None
1049
  scaled_mask = None
 
1050
 
1051
  if bbox_x1 is not None and bbox_y1 is not None and bbox_x2 is not None and bbox_y2 is not None:
1052
  print(f"🎯 BBox Koordinaten erhalten: [{bbox_x1}, {bbox_y1}, {bbox_x2}, {bbox_y2}]")
1053
 
1054
- # 1. MASKE in Abhängigkeit der BBox Koordinaten AUF ORIGINAL-BILD ERSTELLEN (speichern für späteres Compositing)
1055
- original_mask = create_face_mask(image, (bbox_x1, bbox_y1, bbox_x2, bbox_y2), mode)
 
 
 
 
 
1056
 
1057
  # 2. BILD UND MASKE GEMEINSAM SKALIEREN (mit Padding)
1058
  scaled_image, scaled_mask, padding_info = scale_image_and_mask_together(
1059
  image.convert("RGB"), # Originalbild
1060
- original_mask, # Originalmaske
1061
  target_size=IMG_SIZE
1062
  )
1063
 
@@ -1069,6 +1075,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
1069
  scaled_image = image.convert("RGB").resize((IMG_SIZE, IMG_SIZE), Image.Resampling.LANCZOS)
1070
  scaled_mask = Image.new("L", (IMG_SIZE, IMG_SIZE), 255) # Volle Maske
1071
 
 
1072
  progress(0.1, desc="ControlNet läuft...")
1073
 
1074
  # ===== CONTROLNET: MAPS ERSTELLEN =====
 
1047
  padding_info = None
1048
  scaled_image = None
1049
  scaled_mask = None
1050
+
1051
 
1052
  if bbox_x1 is not None and bbox_y1 is not None and bbox_x2 is not None and bbox_y2 is not None:
1053
  print(f"🎯 BBox Koordinaten erhalten: [{bbox_x1}, {bbox_y1}, {bbox_x2}, {bbox_y2}]")
1054
 
1055
+ # === WICHTIGE ÄNDERUNG: SAM 2 STATT create_face_mask ===
1056
+ # 1. MASKE mit SAM 2 erzeugen (transparent für Benutzer)
1057
+ original_mask = controlnet_processor.create_sam_mask(
1058
+ image=image,
1059
+ bbox_coords=(bbox_x1, bbox_y1, bbox_x2, bbox_y2),
1060
+ mode=mode
1061
+ )
1062
 
1063
  # 2. BILD UND MASKE GEMEINSAM SKALIEREN (mit Padding)
1064
  scaled_image, scaled_mask, padding_info = scale_image_and_mask_together(
1065
  image.convert("RGB"), # Originalbild
1066
+ original_mask, # SAM 2 Maske (oder Fallback)
1067
  target_size=IMG_SIZE
1068
  )
1069
 
 
1075
  scaled_image = image.convert("RGB").resize((IMG_SIZE, IMG_SIZE), Image.Resampling.LANCZOS)
1076
  scaled_mask = Image.new("L", (IMG_SIZE, IMG_SIZE), 255) # Volle Maske
1077
 
1078
+
1079
  progress(0.1, desc="ControlNet läuft...")
1080
 
1081
  # ===== CONTROLNET: MAPS ERSTELLEN =====