Update controlnet_module.py
Browse files- controlnet_module.py +15 -13
controlnet_module.py
CHANGED
|
@@ -77,9 +77,9 @@ class ControlNetProcessor:
|
|
| 77 |
try:
|
| 78 |
img_array = np.array(image.convert("RGB"))
|
| 79 |
|
| 80 |
-
# Canny Edge Detection
|
| 81 |
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 82 |
-
edges = cv2.Canny(gray,
|
| 83 |
|
| 84 |
# Zu 3-Kanal Bild konvertieren
|
| 85 |
edges_rgb = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
|
|
@@ -148,14 +148,16 @@ class ControlNetProcessor:
|
|
| 148 |
print("Loading Multi-ControlNet pipeline...")
|
| 149 |
try:
|
| 150 |
# Beide ControlNet-Modelle laden
|
| 151 |
-
self.controlnet_openpose
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
|
|
|
| 159 |
|
| 160 |
# Multi-ControlNet Pipeline
|
| 161 |
self.pipe_multi = StableDiffusionControlNetPipeline.from_pretrained(
|
|
@@ -182,7 +184,7 @@ class ControlNetProcessor:
|
|
| 182 |
):
|
| 183 |
"""Generiert Bild mit ControlNet und Fortschrittsanzeige"""
|
| 184 |
try:
|
| 185 |
-
# ---
|
| 186 |
if keep_environment:
|
| 187 |
# UMGEBUNG BEIBEHALTEN, PERSON ÄNDERN → MULTI-CONTROLNET
|
| 188 |
print("🎯 ControlNet Modus: Umgebung beibehalten (Multi-ControlNet: OpenPose + Canny)")
|
|
@@ -197,8 +199,8 @@ class ControlNetProcessor:
|
|
| 197 |
controlnet_type = "multi"
|
| 198 |
|
| 199 |
# Unterschiedliche Strengths für Pose und Canny
|
| 200 |
-
controlnet_conditioning_scale = [controlnet_strength * 0.
|
| 201 |
-
controlnet_strength * 0.
|
| 202 |
|
| 203 |
else:
|
| 204 |
# PERSON BEIBEHALTEN, UMGEBUNG ÄNDERN → NUR OPENPOSE
|
|
|
|
| 77 |
try:
|
| 78 |
img_array = np.array(image.convert("RGB"))
|
| 79 |
|
| 80 |
+
# Canny Edge Detection
|
| 81 |
gray = cv2.cvtColor(img_array, cv2.COLOR_RGB2GRAY)
|
| 82 |
+
edges = cv2.Canny(gray, 100, 200)
|
| 83 |
|
| 84 |
# Zu 3-Kanal Bild konvertieren
|
| 85 |
edges_rgb = cv2.cvtColor(edges, cv2.COLOR_GRAY2RGB)
|
|
|
|
| 148 |
print("Loading Multi-ControlNet pipeline...")
|
| 149 |
try:
|
| 150 |
# Beide ControlNet-Modelle laden
|
| 151 |
+
if self.controlnet_openpose is None:
|
| 152 |
+
self.controlnet_openpose = ControlNetModel.from_pretrained(
|
| 153 |
+
"lllyasviel/sd-controlnet-openpose",
|
| 154 |
+
torch_dtype=self.torch_dtype
|
| 155 |
+
)
|
| 156 |
+
if self.controlnet_canny is None:
|
| 157 |
+
self.controlnet_canny = ControlNetModel.from_pretrained(
|
| 158 |
+
"lllyasviel/sd-controlnet-canny",
|
| 159 |
+
torch_dtype=self.torch_dtype
|
| 160 |
+
)
|
| 161 |
|
| 162 |
# Multi-ControlNet Pipeline
|
| 163 |
self.pipe_multi = StableDiffusionControlNetPipeline.from_pretrained(
|
|
|
|
| 184 |
):
|
| 185 |
"""Generiert Bild mit ControlNet und Fortschrittsanzeige"""
|
| 186 |
try:
|
| 187 |
+
# --- KORRIGIERTE LOGIK ---
|
| 188 |
if keep_environment:
|
| 189 |
# UMGEBUNG BEIBEHALTEN, PERSON ÄNDERN → MULTI-CONTROLNET
|
| 190 |
print("🎯 ControlNet Modus: Umgebung beibehalten (Multi-ControlNet: OpenPose + Canny)")
|
|
|
|
| 199 |
controlnet_type = "multi"
|
| 200 |
|
| 201 |
# Unterschiedliche Strengths für Pose und Canny
|
| 202 |
+
controlnet_conditioning_scale = [controlnet_strength * 0.6, # OpenPose: 60% für Person
|
| 203 |
+
controlnet_strength * 0.4] # Canny: 40% für Umgebung
|
| 204 |
|
| 205 |
else:
|
| 206 |
# PERSON BEIBEHALTEN, UMGEBUNG ÄNDERN → NUR OPENPOSE
|