Astridkraft commited on
Commit
002f8e8
·
verified ·
1 Parent(s): 4e95608

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -11
app.py CHANGED
@@ -1235,8 +1235,9 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
1235
  adj_strength = 0.75 # Leicht runter auf Realismus
1236
 
1237
  # CONTROLNET-STÄRKE
1238
- controlnet_strength = 0.55 #Inpaint kann bei Neugenerierung nicht so viel Kontrolle vertragen
1239
-
 
1240
  depth_ratio = 0.50 # 35%
1241
  canny_ratio = 0.12 # 10%
1242
 
@@ -1245,14 +1246,21 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
1245
  # Heuristik für Naturszenen vs. Innenräume
1246
  nature_keywords = ["beach", "forest", "mountain", "ocean", "sky", "field", "landscape", "nature", "outdoor", "desert", "snow", "arctic"]
1247
  interior_keywords = ["office", "room", "interior", "kitchen", "bedroom", "living room", "indoor", "wall", "furniture"]
 
1248
 
1249
  # Anpassung für Innenräume (mehr Kantenerhalt)
1250
  if any(keyword in prompt_lower for keyword in interior_keywords):
1251
- # Vorherige Formel für exakten Objektschutz
1252
  adj_strength = 0.2 + (ui_strength * 0.5)
1253
  controlnet_strength = 0.7 + (ui_strength * 0.2)
1254
  canny_ratio = 0.8 + (ui_strength * 0.1)
1255
  depth_ratio = 1.0 - canny_ratio
 
 
 
 
 
 
1256
 
1257
  conditioning_scale = [
1258
  controlnet_strength * depth_ratio,
@@ -1268,19 +1276,18 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
1268
  # Anpassung für Naturszenen (maximale Flexibilität) - die optimalen UI-Werte: strength:0,72 , steps: 35 , guidance: 9-9,5
1269
  elif any(keyword in prompt_lower for keyword in nature_keywords):
1270
 
1271
- # 1. DENOISING: Radikaler bei Naturszenen (Wald→Wüste)
1272
  adj_strength = 0.3 + (ui_strength * 0.5) # wie stark das bestehende Bild überschrieben wird im kompletten Denoising-Prozess-also Strukturveränderung
1273
 
1274
- # 2. CONTROLNET: WENIGER bei Naturszenen (mehr Freiheit)
1275
  controlnet_strength = 0.3 + (ui_strength * 0.3) # 0.3-0.6
1276
 
1277
- # 3. RATIOS: WENIG Canny (Kanten stören bei Naturveränderung)
1278
  # MEHR Depth (Maßstab/Tiefe erhalten)
1279
  depth_ratio = 0.8 - (ui_strength * 0.3) # Depth-Wert hält Maßstab und Boden (Emi groß, Liege klein - Emi im Meer)
1280
  canny_ratio = 1.0 - depth_ratio # erzwingt Kanten - hält dadurch an alter Umgebung fest - schlecht bei Umgebungswechsel
1281
 
1282
  # Clipping verhindert extreme Werte, Controlnet hat immer etwas Einfluß sonst ist Pipline instabil
1283
- # Für Naturszenen (Wald→Wüste, Meer→Tundra)
1284
  adj_strength = max(0.3, min(adj_strength, 0.85))
1285
  controlnet_strength = max(0.25, min(controlnet_strength, 0.65))
1286
  depth_ratio = max(0.3, min(depth_ratio, 0.9)) # Depth nicht unter 30%
@@ -1296,10 +1303,15 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
1296
  print(f" Depth: {depth_ratio*100:.0f}% (Maßstab), Canny: {canny_ratio*100:.0f}%")
1297
  print(f" Conditioning Scale: [{conditioning_scale[0]:.3f}, {conditioning_scale[1]:.3f}]")
1298
 
1299
- else:
1300
- print("🎯 Standard-Ratio 90:10 (Depth:Canny)")
1301
-
1302
- # 4. CONDITIONING SCALE BERECHNEN
 
 
 
 
 
1303
  conditioning_scale = [
1304
  controlnet_strength * depth_ratio, # Depth-Gewichtung
1305
  controlnet_strength * canny_ratio # Canny-Gewichtung
 
1235
  adj_strength = 0.75 # Leicht runter auf Realismus
1236
 
1237
  # CONTROLNET-STÄRKE
1238
+ controlnet_strength = 0.55 #Inpaint kann bei Neugenerierung nicht so viel Kontrolle vertragen
1239
+
1240
+ #Ratios:
1241
  depth_ratio = 0.50 # 35%
1242
  canny_ratio = 0.12 # 10%
1243
 
 
1246
  # Heuristik für Naturszenen vs. Innenräume
1247
  nature_keywords = ["beach", "forest", "mountain", "ocean", "sky", "field", "landscape", "nature", "outdoor", "desert", "snow", "arctic"]
1248
  interior_keywords = ["office", "room", "interior", "kitchen", "bedroom", "living room", "indoor", "wall", "furniture"]
1249
+
1250
 
1251
  # Anpassung für Innenräume (mehr Kantenerhalt)
1252
  if any(keyword in prompt_lower for keyword in interior_keywords):
1253
+ # Ob Formel korrekt? kein Test!
1254
  adj_strength = 0.2 + (ui_strength * 0.5)
1255
  controlnet_strength = 0.7 + (ui_strength * 0.2)
1256
  canny_ratio = 0.8 + (ui_strength * 0.1)
1257
  depth_ratio = 1.0 - canny_ratio
1258
+
1259
+ # Clipping: extreme Werte, Instabilität, Für exakten Objektschutz (Büro→Küche, Zimmer→Garten)
1260
+ adj_strength = max(0.15, min(adj_strength, 0.7)) # Max 70% Denoising
1261
+ controlnet_strength = max(0.6, min(controlnet_strength, 0.95)) # Min 60% ControlNet
1262
+ canny_ratio = max(0.7, min(canny_ratio, 0.95)) # Canny mind. 70% für Kanten
1263
+ depth_ratio = max(0.05, min(depth_ratio, 0.3)) # Depth max 30%
1264
 
1265
  conditioning_scale = [
1266
  controlnet_strength * depth_ratio,
 
1276
  # Anpassung für Naturszenen (maximale Flexibilität) - die optimalen UI-Werte: strength:0,72 , steps: 35 , guidance: 9-9,5
1277
  elif any(keyword in prompt_lower for keyword in nature_keywords):
1278
 
1279
+ # DENOISING: Radikaler bei Naturszenen (Wald→Wüste)
1280
  adj_strength = 0.3 + (ui_strength * 0.5) # wie stark das bestehende Bild überschrieben wird im kompletten Denoising-Prozess-also Strukturveränderung
1281
 
1282
+ # CONTROLNET: WENIGER bei Naturszenen (mehr Freiheit)
1283
  controlnet_strength = 0.3 + (ui_strength * 0.3) # 0.3-0.6
1284
 
1285
+ # RATIOS: WENIG Canny (Kanten stören bei Naturveränderung)
1286
  # MEHR Depth (Maßstab/Tiefe erhalten)
1287
  depth_ratio = 0.8 - (ui_strength * 0.3) # Depth-Wert hält Maßstab und Boden (Emi groß, Liege klein - Emi im Meer)
1288
  canny_ratio = 1.0 - depth_ratio # erzwingt Kanten - hält dadurch an alter Umgebung fest - schlecht bei Umgebungswechsel
1289
 
1290
  # Clipping verhindert extreme Werte, Controlnet hat immer etwas Einfluß sonst ist Pipline instabil
 
1291
  adj_strength = max(0.3, min(adj_strength, 0.85))
1292
  controlnet_strength = max(0.25, min(controlnet_strength, 0.65))
1293
  depth_ratio = max(0.3, min(depth_ratio, 0.9)) # Depth nicht unter 30%
 
1303
  print(f" Depth: {depth_ratio*100:.0f}% (Maßstab), Canny: {canny_ratio*100:.0f}%")
1304
  print(f" Conditioning Scale: [{conditioning_scale[0]:.3f}, {conditioning_scale[1]:.3f}]")
1305
 
1306
+ else: #Standard
1307
+
1308
+ # Clipping:
1309
+ adj_strength = max(0.15, min(adj_strength, 0.7)) # Max 70% Denoising
1310
+ controlnet_strength = max(0.6, min(controlnet_strength, 0.95)) # Min 60% ControlNet
1311
+ canny_ratio = max(0.7, min(canny_ratio, 0.95)) # Canny mind. 70% für Kanten
1312
+ depth_ratio = max(0.05, min(depth_ratio, 0.3)) # Depth max 30%
1313
+
1314
+
1315
  conditioning_scale = [
1316
  controlnet_strength * depth_ratio, # Depth-Gewichtung
1317
  controlnet_strength * canny_ratio # Canny-Gewichtung