Astridkraft commited on
Commit
3744e15
·
verified ·
1 Parent(s): 421d3c4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +17 -3
app.py CHANGED
@@ -218,7 +218,17 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
218
  # PARAMETER-TUNING
219
  # -------------------------------
220
  adj_strength = min(0.85, strength * 1.25)
221
- controlnet_strength = adj_strength * (0.8 if face_preserve else 0.5)
 
 
 
 
 
 
 
 
 
 
222
  controlnet_steps = min(25, int(steps * 0.8))
223
 
224
  print(f"🎯 Steps={steps}, ControlNet-Steps={controlnet_steps}, Strength={controlnet_strength:.3f}")
@@ -235,10 +245,12 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
235
  steps=controlnet_steps,
236
  guidance_scale=guidance_scale,
237
  controlnet_strength=controlnet_strength,
238
- progress=progress
 
239
  )
240
 
241
  print(f"✅ ControlNet Output erhalten: {type(controlnet_output)}")
 
242
 
243
  # -------------------------------
244
  # INPAINT (STABLE DIFFUSION IMG2IMG)
@@ -246,6 +258,8 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
246
  progress(0.3, desc="ControlNet abgeschlossen – starte Inpaint...")
247
 
248
  pipe = load_img2img() # ← deine bestehende Funktion
 
 
249
  img_resized = inpaint_input.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
250
 
251
  adj_guidance = min(guidance_scale, 12.0)
@@ -306,7 +320,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
306
  import traceback
307
  traceback.print_exc()
308
  return None
309
-
310
 
311
  def update_bbox_from_image(image):
312
  """Aktualisiert die Bounding-Box-Koordinaten wenn ein Bild hochgeladen wird"""
 
218
  # PARAMETER-TUNING
219
  # -------------------------------
220
  adj_strength = min(0.85, strength * 1.25)
221
+
222
+ # CONTROLNET-STRENGTH ANPASSEN ABHÄNGIG VOM MODUS
223
+ if face_preserve:
224
+ # UMGEBUNG BEIBEHALTEN, PERSON ÄNDERN → HOHE STRENGTH FÜR KOMBINIERTE STRATEGIE
225
+ controlnet_strength = adj_strength * 0.8 # 80% für kombinierte OpenPose + Canny
226
+ print(f"🎯 ControlNet Modus: Umgebung beibehalten (Strength = {controlnet_strength:.3f})")
227
+ else:
228
+ # PERSON BEIBEHALTEN, UMGEBUNG ÄNDERN → NORMALE STRENGTH FÜR OPENPOSE
229
+ controlnet_strength = adj_strength * 0.5 # 50% für OpenPose
230
+ print(f"🎯 ControlNet Modus: Person beibehalten (Strength = {controlnet_strength:.3f})")
231
+
232
  controlnet_steps = min(25, int(steps * 0.8))
233
 
234
  print(f"🎯 Steps={steps}, ControlNet-Steps={controlnet_steps}, Strength={controlnet_strength:.3f}")
 
245
  steps=controlnet_steps,
246
  guidance_scale=guidance_scale,
247
  controlnet_strength=controlnet_strength,
248
+ progress=progress,
249
+ keep_environment=face_preserve # WICHTIG: Parameter hinzugefügt!
250
  )
251
 
252
  print(f"✅ ControlNet Output erhalten: {type(controlnet_output)}")
253
+ print(f"✅ Inpaint Input erhalten: {type(inpaint_input)}")
254
 
255
  # -------------------------------
256
  # INPAINT (STABLE DIFFUSION IMG2IMG)
 
258
  progress(0.3, desc="ControlNet abgeschlossen – starte Inpaint...")
259
 
260
  pipe = load_img2img() # ← deine bestehende Funktion
261
+
262
+ # inpaint_input ist IMMER das Originalbild (laut neuer ControlNet-Logik)
263
  img_resized = inpaint_input.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
264
 
265
  adj_guidance = min(guidance_scale, 12.0)
 
320
  import traceback
321
  traceback.print_exc()
322
  return None
323
+
324
 
325
  def update_bbox_from_image(image):
326
  """Aktualisiert die Bounding-Box-Koordinaten wenn ein Bild hochgeladen wird"""