Astridkraft commited on
Commit
9778b2f
·
verified ·
1 Parent(s): 538ea82

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -8
app.py CHANGED
@@ -197,7 +197,6 @@ def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
197
  traceback.print_exc()
198
  return None
199
 
200
-
201
  def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, face_preserve, bbox_x1, bbox_y1, bbox_x2, bbox_y2, progress=gr.Progress()):
202
  try:
203
  if image is None:
@@ -222,12 +221,17 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
222
 
223
  print(f"🎯 ControlNet Step-Kalkulation: UI={steps}, Adj-Strength={adj_strength:.3f}, Echte Steps={actual_steps_from_strength}, ControlNet-Steps={controlnet_steps}")
224
 
225
- # CONTROLNET-STRENGTH BERECHNEN: 50% der Inpaint-Strength
226
- controlnet_strength = adj_strength * 0.5
227
- print(f"🎯 ControlNet Strength: {controlnet_strength:.3f} (50% von Inpaint-Strength {adj_strength:.3f})")
 
 
 
 
 
 
228
 
229
  # ControlNet Modul aufrufen - MIT ZWEI RÜCKGABEWERTEN
230
- # ControlNet Modul aufrufen - MIT DREI RÜCKGABEWERTEN
231
  controlnet_output, inpaint_input = controlnet_processor.generate_with_controlnet(
232
  image=image,
233
  prompt=prompt,
@@ -248,7 +252,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
248
  # --- INPAINT PIPELINE ---
249
  pipe = load_img2img()
250
 
251
- # JETZT: inpaint_input verwenden (Conditioning Image für Inpaint)
252
  img_resized = inpaint_input.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
253
 
254
  # --- PARAMETER-TUNING ---
@@ -302,7 +306,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
302
  result = pipe(
303
  prompt=prompt,
304
  negative_prompt=neg_prompt,
305
- image=img_resized, # JETZT: inpaint_input (Conditioning Image)
306
  mask_image=mask,
307
  strength=adj_strength,
308
  num_inference_steps=int(steps),
@@ -339,7 +343,6 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, fac
339
  return None
340
 
341
 
342
-
343
  def update_bbox_from_image(image):
344
  """Aktualisiert die Bounding-Box-Koordinaten wenn ein Bild hochgeladen wird"""
345
  if image is None:
 
197
  traceback.print_exc()
198
  return None
199
 
 
200
  def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale, face_preserve, bbox_x1, bbox_y1, bbox_x2, bbox_y2, progress=gr.Progress()):
201
  try:
202
  if image is None:
 
221
 
222
  print(f"🎯 ControlNet Step-Kalkulation: UI={steps}, Adj-Strength={adj_strength:.3f}, Echte Steps={actual_steps_from_strength}, ControlNet-Steps={controlnet_steps}")
223
 
224
+ # --- KONTROLLNET-STRENGTH ANPASSEN ABHÄNGIG VOM MODUS ---
225
+ if face_preserve:
226
+ # UMGEBUNG BEIBEHALTEN, PERSON ÄNDERN HOHE STRENGTH FÜR CANNY
227
+ controlnet_strength = adj_strength * 0.8 # 80% für Canny
228
+ print(f"🎯 ControlNet Canny Modus: Strength = {controlnet_strength:.3f} (80% von {adj_strength:.3f})")
229
+ else:
230
+ # PERSON BEIBEHALTEN, UMGEBUNG ÄNDERN → NORMALE STRENGTH FÜR OPENPOSE
231
+ controlnet_strength = adj_strength * 0.5 # 50% für OpenPose
232
+ print(f"🎯 ControlNet OpenPose Modus: Strength = {controlnet_strength:.3f} (50% von {adj_strength:.3f})")
233
 
234
  # ControlNet Modul aufrufen - MIT ZWEI RÜCKGABEWERTEN
 
235
  controlnet_output, inpaint_input = controlnet_processor.generate_with_controlnet(
236
  image=image,
237
  prompt=prompt,
 
252
  # --- INPAINT PIPELINE ---
253
  pipe = load_img2img()
254
 
255
+ # inpaint_input verwenden (IMMER Originalbild)
256
  img_resized = inpaint_input.convert("RGB").resize((IMG_SIZE, IMG_SIZE))
257
 
258
  # --- PARAMETER-TUNING ---
 
306
  result = pipe(
307
  prompt=prompt,
308
  negative_prompt=neg_prompt,
309
+ image=img_resized, # inpaint_input (Originalbild)
310
  mask_image=mask,
311
  strength=adj_strength,
312
  num_inference_steps=int(steps),
 
343
  return None
344
 
345
 
 
346
  def update_bbox_from_image(image):
347
  """Aktualisiert die Bounding-Box-Koordinaten wenn ein Bild hochgeladen wird"""
348
  if image is None: