File size: 2,415 Bytes
f0735ee 7a300b4 f0735ee 7a300b4 f0735ee 7a300b4 f0735ee 7a300b4 6769c24 7a300b4 6769c24 7a300b4 6769c24 7a300b4 6769c24 7a300b4 6769c24 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 | import torch
from diffusers import StableDiffusionControlNetInpaintPipeline, ControlNetModel
from controlnet_aux import ZoeDetector
from PIL import Image
import time
print("Lade Face-Fix System (Depth-basiert)...")
# Vereinfachte Version NUR mit Depth
try:
depth_processor = ZoeDetector.from_pretrained("lllyasviel/ControlNet")
print("✅ Depth Processor geladen")
controlnet_depth = ControlNetModel.from_pretrained(
"lllyasviel/control_v11f1e_sd15_depth",
torch_dtype=torch.float16
).to("cuda")
print("✅ ControlNet Depth geladen")
_facefix_pipe = None
def _get_facefix_pipeline(model_id: str):
global _facefix_pipe
if _facefix_pipe is None:
print(f"Lade Face-Fix-Pipeline für Modell: {model_id}")
_facefix_pipe = StableDiffusionControlNetInpaintPipeline.from_pretrained(
model_id,
controlnet=[controlnet_depth],
torch_dtype=torch.float16,
safety_checker=None,
).to("cuda")
return _facefix_pipe
def apply_facefix(image: Image.Image, prompt: str, negative_prompt: str, seed: int, model_id: str):
try:
pipe = _get_facefix_pipeline(model_id)
depth_img = depth_processor(image)
face_prompt = prompt + ", perfect face, detailed skin"
face_negative = negative_prompt + ", deformed face"
fixed = pipe(
prompt=face_prompt,
negative_prompt=face_negative,
image=image,
mask_image=None,
control_image=[depth_img],
controlnet_conditioning_scale=[0.7],
strength=0.35,
num_inference_steps=20,
guidance_scale=7.0,
generator=torch.Generator("cuda").manual_seed(seed),
).images[0]
return fixed
except Exception as e:
print(f"Face-Fix Error: {e}")
return image
except Exception as e:
print(f"❌ Face-Fix Setup fehlgeschlagen: {e}")
# Fallback: Dummy-Funktion die nichts macht
def apply_facefix(image: Image.Image, prompt: str, negative_prompt: str, seed: int, model_id: str):
print("⚠️ Face-Fix nicht verfügbar, gebe Original zurück")
return image |