Update controlnet_module.py
Browse files- controlnet_module.py +16 -17
controlnet_module.py
CHANGED
|
@@ -1,4 +1,3 @@
|
|
| 1 |
-
# controlnet_processor.py
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
|
| 4 |
from controlnet_aux import OpenposeDetector
|
|
@@ -143,24 +142,24 @@ class ControlNetProcessor:
|
|
| 143 |
raise
|
| 144 |
return self.pipe_canny
|
| 145 |
|
| 146 |
-
|
| 147 |
-
|
| 148 |
steps, guidance_scale, controlnet_strength,
|
| 149 |
progress=None, keep_environment=False
|
| 150 |
):
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
|
| 165 |
pipe = self.load_controlnet_pipeline(controlnet_type)
|
| 166 |
|
|
@@ -201,7 +200,7 @@ class ControlNetProcessor:
|
|
| 201 |
|
| 202 |
print("✅ ControlNet abgeschlossen!")
|
| 203 |
|
| 204 |
-
#
|
| 205 |
return result.images[0], conditioning_image
|
| 206 |
|
| 207 |
except Exception as e:
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers import StableDiffusionControlNetPipeline, ControlNetModel
|
| 3 |
from controlnet_aux import OpenposeDetector
|
|
|
|
| 142 |
raise
|
| 143 |
return self.pipe_canny
|
| 144 |
|
| 145 |
+
def generate_with_controlnet(
|
| 146 |
+
self, image, prompt, negative_prompt,
|
| 147 |
steps, guidance_scale, controlnet_strength,
|
| 148 |
progress=None, keep_environment=False
|
| 149 |
):
|
| 150 |
+
"""Generiert Bild mit ControlNet und Fortschrittsanzeige"""
|
| 151 |
+
try:
|
| 152 |
+
# --- KORREKTE LOGIK ---
|
| 153 |
+
if keep_environment:
|
| 154 |
+
# UMGEBUNG BEIBEHALTEN, PERSON ÄNDERN
|
| 155 |
+
controlnet_type = "canny" # ✅ Canny behält Umgebung
|
| 156 |
+
print("🎯 ControlNet Modus: Umgebung beibehalten (Canny Edge)")
|
| 157 |
+
conditioning_image = self.extract_canny_edges(image)
|
| 158 |
+
else:
|
| 159 |
+
# PERSON BEIBEHALTEN, UMGEBUNG ÄNDERN
|
| 160 |
+
controlnet_type = "openpose" # ✅ OpenPose behält Person
|
| 161 |
+
print("🎯 ControlNet Modus: Person beibehalten (OpenPose)")
|
| 162 |
+
conditioning_image = self.extract_pose(image)
|
| 163 |
|
| 164 |
pipe = self.load_controlnet_pipeline(controlnet_type)
|
| 165 |
|
|
|
|
| 200 |
|
| 201 |
print("✅ ControlNet abgeschlossen!")
|
| 202 |
|
| 203 |
+
# ZWEI Werte zurückgeben
|
| 204 |
return result.images[0], conditioning_image
|
| 205 |
|
| 206 |
except Exception as e:
|