Update app.py
Browse files
app.py
CHANGED
|
@@ -463,32 +463,49 @@ def load_txt2img(model_id):
|
|
| 463 |
print(f"❌ Auch Fallback fehlgeschlagen: {fallback_error}")
|
| 464 |
raise
|
| 465 |
|
| 466 |
-
|
| 467 |
def load_img2img():
|
|
|
|
| 468 |
global pipe_img2img
|
| 469 |
if pipe_img2img is None:
|
| 470 |
print("🔄 Lade ControlNet-Inpainting-Modell...")
|
| 471 |
-
|
| 472 |
-
|
| 473 |
-
|
| 474 |
-
|
| 475 |
-
|
| 476 |
-
|
| 477 |
-
|
| 478 |
-
|
| 479 |
-
|
| 480 |
-
|
| 481 |
-
|
| 482 |
-
|
| 483 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 484 |
|
|
|
|
| 485 |
pipe_img2img.enable_attention_slicing()
|
| 486 |
pipe_img2img.enable_vae_tiling()
|
| 487 |
if hasattr(pipe_img2img, 'vae_slicing'):
|
| 488 |
pipe_img2img.vae_slicing = True
|
| 489 |
-
print("✅ Inpainting-Modell geladen und optimiert")
|
| 490 |
|
| 491 |
return pipe_img2img
|
|
|
|
| 492 |
|
| 493 |
#Die Callback-Funktion wird von der Pipeline nach jedem Verarbeitungsschritt aufgerufen und erhält Informationen
|
| 494 |
#wie den aktuellen step und timestep. Diese nutzt der Progressbalken-Callback, um den Fortschritt zu berechnen und anzuzeigen.
|
|
|
|
| 463 |
print(f"❌ Auch Fallback fehlgeschlagen: {fallback_error}")
|
| 464 |
raise
|
| 465 |
|
|
|
|
| 466 |
def load_img2img():
|
| 467 |
+
"""Lädt ControlNet-Inpainting-Pipeline"""
|
| 468 |
global pipe_img2img
|
| 469 |
if pipe_img2img is None:
|
| 470 |
print("🔄 Lade ControlNet-Inpainting-Modell...")
|
| 471 |
+
try:
|
| 472 |
+
# WICHTIG: Nur EIN ControlNet laden (Canny) für die neue Pipeline
|
| 473 |
+
controlnet = ControlNetModel.from_pretrained(
|
| 474 |
+
"lllyasviel/sd-controlnet-canny",
|
| 475 |
+
torch_dtype=torch_dtype
|
| 476 |
+
)
|
| 477 |
+
|
| 478 |
+
pipe_img2img = StableDiffusionControlNetInpaintPipeline.from_pretrained(
|
| 479 |
+
"runwayml/stable-diffusion-v1-5",
|
| 480 |
+
controlnet=controlnet,
|
| 481 |
+
torch_dtype=torch_dtype,
|
| 482 |
+
safety_checker=None,
|
| 483 |
+
requires_safety_checker=False
|
| 484 |
+
).to(device)
|
| 485 |
+
|
| 486 |
+
# Scheduler konfigurieren (Ihre bestehende Logik)
|
| 487 |
+
pipe_img2img.scheduler = DPMSolverMultistepScheduler.from_config(
|
| 488 |
+
pipe_img2img.scheduler.config,
|
| 489 |
+
algorithm_type="sde-dpmsolver++",
|
| 490 |
+
use_karras_sigmas=True,
|
| 491 |
+
timestep_spacing="trailing"
|
| 492 |
+
)
|
| 493 |
+
|
| 494 |
+
print("✅ DPMSolver++ Multistep Scheduler für ControlNet-Inpainting konfiguriert")
|
| 495 |
+
|
| 496 |
+
except Exception as e:
|
| 497 |
+
print(f"❌ Fehler beim Laden des ControlNet-Inpainting-Modells: {e}")
|
| 498 |
+
raise
|
| 499 |
|
| 500 |
+
# Optimierungen
|
| 501 |
pipe_img2img.enable_attention_slicing()
|
| 502 |
pipe_img2img.enable_vae_tiling()
|
| 503 |
if hasattr(pipe_img2img, 'vae_slicing'):
|
| 504 |
pipe_img2img.vae_slicing = True
|
| 505 |
+
print("✅ ControlNet-Inpainting-Modell geladen und optimiert")
|
| 506 |
|
| 507 |
return pipe_img2img
|
| 508 |
+
|
| 509 |
|
| 510 |
#Die Callback-Funktion wird von der Pipeline nach jedem Verarbeitungsschritt aufgerufen und erhält Informationen
|
| 511 |
#wie den aktuellen step und timestep. Diese nutzt der Progressbalken-Callback, um den Fortschritt zu berechnen und anzuzeigen.
|