Astridkraft commited on
Commit
a20d236
·
verified ·
1 Parent(s): 8cad168

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +115 -17
app.py CHANGED
@@ -1380,33 +1380,131 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
1380
  print(f" Conditioning Scale: [{conditioning_scale[0]:.3f}, {conditioning_scale[1]:.3f}]")
1381
 
1382
 
1383
- else: # face_only_change
1384
  # Optimale UI-Werte (entscheidend)
1385
  # Strength: 0.60 – 0.65 → ideal: 0.62
1386
  # Guidance (CFG): 7.0 – 8.0 → ideal: 7.5
1387
  # Steps: 30 – 34 → ideal: 32
1388
- keep_environment = True
1389
 
1390
- adj_strength = 0.6 #Struktur
 
 
 
 
 
 
 
1391
 
1392
- # Controlnet-zurückhaltend
1393
- controlnet_strength = 0.4
 
 
 
1394
 
1395
- # HIER FEHLEN DIE RATIOS - Controlnet gesteuertes Inpainting:
1396
- depth_ratio = 0.55 # Für Gesicht: Depth stärker
1397
- canny_ratio = 0.10 # Canny leichter hält an Kanten fest
1398
 
1399
- # KRITISCH: conditioning_scale HIER definieren (wie bei environment_change)!
1400
- conditioning_scale = [
1401
- controlnet_strength * depth_ratio,
1402
- controlnet_strength * canny_ratio
1403
- ]
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1404
 
1405
- print(f"👤 Gesichtsmodus: Depth {depth_ratio*100}%, Canny {canny_ratio*100}%")
1406
- print(f" Strength: {adj_strength:.2f}")
1407
- print(f" ControlNet: {controlnet_strength:.3f}")
1408
- print(f" Depth: {depth_ratio*100}%, Canny: {canny_ratio*100}%")
 
 
1409
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1410
  #################################################################################################
1411
 
1412
 
 
1380
  print(f" Conditioning Scale: [{conditioning_scale[0]:.3f}, {conditioning_scale[1]:.3f}]")
1381
 
1382
 
1383
+ else: # face_only_change
1384
  # Optimale UI-Werte (entscheidend)
1385
  # Strength: 0.60 – 0.65 → ideal: 0.62
1386
  # Guidance (CFG): 7.0 – 8.0 → ideal: 7.5
1387
  # Steps: 30 – 34 → ideal: 32
 
1388
 
1389
+ #alte Werte mit UI-strength 0,85
1390
+ #adj_strength = 0.6 #Struktur
1391
+ #controlnet_strength = 0.4
1392
+ # HIER FEHLEN DIE RATIOS - Controlnet gesteuertes Inpainting:
1393
+ #depth_ratio = 0.55 # Für Gesicht: Depth stärker
1394
+ #canny_ratio = 0.10 # Canny leichter hält an Kanten fest
1395
+
1396
+ keep_environment = True
1397
 
1398
+ ui_strength = strength # 0.1-0.9 vom User
1399
+ prompt_lower = prompt.lower()
1400
+
1401
+ #Standard für alle Gesichter
1402
+ adj_strength = 0.15 + (ui_strength * 0.75) # 0.15-0.9 Bereich
1403
 
1404
+ # ControlNet-Stärke (nimmt mit UI-Strength ab)
1405
+ controlnet_strength = 0.8 - (ui_strength * 0.6) # 0.8 0.2 linear
 
1406
 
1407
+ # Depth vs. Canny Basis-Ratio
1408
+ depth_ratio = 0.8 - (ui_strength * 0.4) # 0.8 → 0.4
1409
+ canny_ratio = 0.2 + (ui_strength * 0.3) # 0.2 → 0.5
1410
+
1411
+
1412
+ # Anime-Stile
1413
+ anime_keywords = ["anime", "manga", "cartoon", "character", "chibi", "cel-shading", "lineart"]
1414
+
1415
+ # Realistic/Photo-Stile
1416
+ #realistic_keywords = ["photorealistic", "photography", "photo", "realistic", "portrait", "studio", "cinematic"]
1417
+
1418
+ # Zeichnungen/Illustrationen (kein Anime)
1419
+ drawing_keywords = ["drawing", "illustration", "sketch", "painting", "artwork", "watercolor"]
1420
+
1421
+
1422
+ if any(keyword in prompt_lower for keyword in anime_keywords):
1423
+ # Anime: Mehr Denoising für Stiländerungen
1424
+ adj_strength = 0.2 + (ui_strength * 0.8) # 0.2-1.0
1425
+
1426
+ # Anime: Weniger ControlNet insgesamt
1427
+ controlnet_strength = 0.7 - (ui_strength * 0.5) # 0.7 → 0.2
1428
+
1429
+ # Anime: Weniger Depth, mehr Canny
1430
+ depth_ratio = 0.6 - (ui_strength * 0.3) # 0.6 → 0.3
1431
+ canny_ratio = 0.4 + (ui_strength * 0.4) # 0.4 → 0.8
1432
+
1433
+
1434
+
1435
+ #Clipping
1436
+ adj_strength = max(0.15, min(adj_strength, 0.95))
1437
+ controlnet_strength = max(0.1, min(controlnet_strength, 0.9))
1438
+ depth_ratio = max(0.1, min(base_depth, 0.9))
1439
+ canny_ratio = max(0.1, min(base_canny, 0.9))
1440
+
1441
+
1442
+ # KRITISCH: conditioning_scale HIER definieren (wie bei environment_change)!
1443
+ conditioning_scale = [
1444
+ controlnet_strength * depth_ratio,
1445
+ controlnet_strength * canny_ratio
1446
+ ]
1447
+
1448
+ print(" 🎨 Anime-Modus: Mehr Freiheit für Stiländerungen")
1449
+ print(f"🎯 STANDARD MODUS: Umgebung ändern")
1450
+ print(f" Strength: {adj_strength}, ControlNet: {controlnet_strength}")
1451
+ print(f" Depth: {depth_ratio*100}%, Canny: {canny_ratio*100}%")
1452
+ print(f" Conditioning Scale: [{conditioning_scale[0]:.3f}, {conditioning_scale[1]:.3f}]")
1453
+
1454
+
1455
+
1456
+
1457
+ elif any(keyword in prompt_lower for keyword in drawing_keywords):
1458
+ # Weniger Denoising für anatomische Korrektheit
1459
+ adj_strength = max(0.3, adj_strength * 0.9) # Konservativer
1460
+
1461
+ # Mehr ControlNet für Strukturerhalt
1462
+ controlnet_strength = min(0.9, controlnet_strength * 1.2) # Mehr Kontrolle
1463
+
1464
+ # Mehr Depth, weniger Canny
1465
+ depth_ratio = min(0.9, base_depth_ratio * 1.2) # Mehr Depth
1466
+ canny_ratio = max(0.1, base_canny_ratio * 0.8) # Weniger Canny
1467
+
1468
+ #Clipping
1469
+ adj_strength = max(0.15, min(adj_strength, 0.95))
1470
+ controlnet_strength = max(0.1, min(controlnet_strength, 0.9))
1471
+ base_depth = max(0.1, min(base_depth, 0.9))
1472
+ base_canny = max(0.1, min(base_canny, 0.9))
1473
+
1474
+
1475
+ conditioning_scale = [
1476
+ controlnet_strength * depth_ratio,
1477
+ controlnet_strength * canny_ratio
1478
+ ]
1479
+
1480
+ print(" 📸 Drawing-Modus: Mehr Strukturerhalt")
1481
+ print(f"🎯 STANDARD MODUS: Umgebung ändern")
1482
+ print(f" Strength: {adj_strength}, ControlNet: {controlnet_strength}")
1483
+ print(f" Depth: {depth_ratio*100}%, Canny: {canny_ratio*100}%")
1484
+ print(f" Conditioning Scale: [{conditioning_scale[0]:.3f}, {conditioning_scale[1]:.3f}]")
1485
 
1486
+ else: #Standard
1487
+ #Clipping
1488
+ adj_strength = max(0.15, min(adj_strength, 0.95))
1489
+ controlnet_strength = max(0.1, min(controlnet_strength, 0.9))
1490
+ depth_ratio = max(0.1, min(base_depth, 0.9))
1491
+ canny_ratio = max(0.1, min(base_canny, 0.9))
1492
 
1493
+
1494
+ # KRITISCH: conditioning_scale HIER definieren (wie bei environment_change)!
1495
+ conditioning_scale = [
1496
+ controlnet_strength * depth_ratio,
1497
+ controlnet_strength * canny_ratio
1498
+ ]
1499
+
1500
+ print(" 📸 Standard-Modus: Mehr Strukturerhalt")
1501
+ print(f" Strength: {adj_strength}, ControlNet: {controlnet_strength}")
1502
+ print(f" Depth: {depth_ratio*100}%, Canny: {canny_ratio*100}%")
1503
+ print(f" Conditioning Scale: [{conditioning_scale[0]:.3f}, {conditioning_scale[1]:.3f}]")
1504
+
1505
+
1506
+ #################################################################################################
1507
+ # Controlnet-Einstellungen ENDE
1508
  #################################################################################################
1509
 
1510