Update app.py
Browse files
app.py
CHANGED
|
@@ -1496,6 +1496,74 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
|
|
| 1496 |
canny_ratio = 1.0 - depth_ratio
|
| 1497 |
print(" 💇 Anime-Hinterkopf: Mehr Canny für Haarkontur")
|
| 1498 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1499 |
|
| 1500 |
|
| 1501 |
|
|
|
|
| 1496 |
canny_ratio = 1.0 - depth_ratio
|
| 1497 |
print(" 💇 Anime-Hinterkopf: Mehr Canny für Haarkontur")
|
| 1498 |
|
| 1499 |
+
if any(keyword in prompt_lower for keyword in anime_keywords):
|
| 1500 |
+
print("🎨 ANIME-TRANSFORM-MODUS")
|
| 1501 |
+
|
| 1502 |
+
def smoothstep(min_val, max_val, x):
|
| 1503 |
+
x = max(0, min(1, (x - min_val) / (max_val - min_val)))
|
| 1504 |
+
return x * x * (3 - 2 * x)
|
| 1505 |
+
|
| 1506 |
+
# Basiseinstellungen für Anime
|
| 1507 |
+
adj_strength = 0.30 + 0.55 * smoothstep(0.35, 0.9, ui_strength)
|
| 1508 |
+
adj_strength = max(0.3, min(adj_strength, 0.85))
|
| 1509 |
+
|
| 1510 |
+
controlnet_strength = 0.30 + 0.52 * smoothstep(0.65, 0.9, ui_strength)
|
| 1511 |
+
controlnet_strength = max(0.25, min(controlnet_strength, 0.85))
|
| 1512 |
+
|
| 1513 |
+
# ANPASSUNG BASIEREND AUF GESICHT/HINTERKOPF
|
| 1514 |
+
if is_front_face:
|
| 1515 |
+
# Anime-GESICHT vorne
|
| 1516 |
+
depth_ratio = 0.65 + 0.15 * smoothstep(0.5, 0.9, ui_strength) # Höher für Gesichtsstruktur
|
| 1517 |
+
canny_ratio = 1.0 - depth_ratio
|
| 1518 |
+
print(" 👤 Anime-Gesicht (vorne): Mehr Depth für 3D-Struktur")
|
| 1519 |
+
|
| 1520 |
+
elif is_back_head:
|
| 1521 |
+
# Anime-HINTERKOPF
|
| 1522 |
+
depth_ratio = 0.65 + 0.20 * smoothstep(0.5, 0.9, ui_strength) # Niedriger
|
| 1523 |
+
canny_ratio = 1.0 - depth_ratio
|
| 1524 |
+
|
| 1525 |
+
# 2. CONTROLNET-BOOST AB 0.7 (neue Logik)
|
| 1526 |
+
if ui_strength <= 0.7:
|
| 1527 |
+
# Bis 0.7: normale Steigerung (wie getestet und gut)
|
| 1528 |
+
controlnet_strength = 0.30 + 0.52 * smoothstep(0.65, 0.9, ui_strength)
|
| 1529 |
+
else:
|
| 1530 |
+
# Ab 0.7: DEUTLICH MEHR ControlNet für Stabilität
|
| 1531 |
+
# Von 0.7 (≈0.5) auf 0.9 (≈0.85) linear steigern
|
| 1532 |
+
boost_factor = (ui_strength - 0.7) / 0.2 # 0.0 → 1.0
|
| 1533 |
+
controlnet_strength = 0.5 + (0.35 * boost_factor) # 0.5 → 0.85
|
| 1534 |
+
|
| 1535 |
+
# 3. CLIPPING (sicherheitshalber)
|
| 1536 |
+
controlnet_strength = max(0.3, min(controlnet_strength, 0.9))
|
| 1537 |
+
|
| 1538 |
+
print(f" 💇 Anime-Hinterkopf: Depth={depth_ratio:.2f}, ControlNet={controlnet_strength:.2f}")
|
| 1539 |
+
if ui_strength > 0.7:
|
| 1540 |
+
print(" ⚡ BOOST: ControlNet erhöht für bessere Strukturerhaltung")
|
| 1541 |
+
|
| 1542 |
+
else:
|
| 1543 |
+
# Standard-Anime (Fallback)
|
| 1544 |
+
depth_ratio = 0.55 + 0.15 * smoothstep(0.5, 0.9, ui_strength)
|
| 1545 |
+
canny_ratio = 1.0 - depth_ratio
|
| 1546 |
+
|
| 1547 |
+
conditioning_scale = [
|
| 1548 |
+
controlnet_strength * depth_ratio,
|
| 1549 |
+
controlnet_strength * canny_ratio
|
| 1550 |
+
]
|
| 1551 |
+
|
| 1552 |
+
print(f"UI Strength: {ui_strength}")
|
| 1553 |
+
print(f"adj_strength: {adj_strength:.3f}")
|
| 1554 |
+
print(f"controlnet_strength: {controlnet_strength:.3f}")
|
| 1555 |
+
print(f"Depth: {depth_ratio*100:.1f}%, Canny: {canny_ratio*100:.1f}%")
|
| 1556 |
+
print(f"conditioning_scale: {conditioning_scale}")
|
| 1557 |
+
|
| 1558 |
+
|
| 1559 |
+
|
| 1560 |
+
|
| 1561 |
+
|
| 1562 |
+
|
| 1563 |
+
|
| 1564 |
+
|
| 1565 |
+
|
| 1566 |
+
|
| 1567 |
|
| 1568 |
|
| 1569 |
|