Update app.py
Browse files
app.py
CHANGED
|
@@ -275,14 +275,25 @@ def update_live_preview(image, x1, y1, x2, y2, face_preserve):
|
|
| 275 |
|
| 276 |
return preview
|
| 277 |
|
| 278 |
-
|
|
|
|
| 279 |
def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress()):
|
| 280 |
try:
|
| 281 |
if not prompt or not prompt.strip():
|
| 282 |
return None, "Bitte einen Prompt eingeben"
|
| 283 |
|
| 284 |
-
print(f"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 285 |
auto_negatives = auto_negative_prompt(prompt)
|
|
|
|
|
|
|
| 286 |
start_time = time.time()
|
| 287 |
|
| 288 |
# Qualitäts-Boost nur wenn nicht vorhanden
|
|
@@ -291,13 +302,16 @@ def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress(
|
|
| 291 |
has_weights = bool(re.search(r':\d+\.\d+|\([^)]+:\d', prompt))
|
| 292 |
|
| 293 |
enhanced_prompt = f"masterpiece, raw, best quality, highly detailed, {prompt}" if not (has_quality or has_weights) else prompt
|
|
|
|
| 294 |
|
| 295 |
progress(0, desc="Lade Modell...")
|
| 296 |
pipe = load_txt2img(model_id)
|
| 297 |
|
| 298 |
seed = random.randint(0, 2**32 - 1)
|
| 299 |
generator = torch.Generator(device=device).manual_seed(seed)
|
|
|
|
| 300 |
|
|
|
|
| 301 |
image = pipe(
|
| 302 |
prompt=enhanced_prompt,
|
| 303 |
negative_prompt=auto_negatives,
|
|
@@ -309,16 +323,22 @@ def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress(
|
|
| 309 |
callback_on_step_end_tensor_inputs=[],
|
| 310 |
).images[0]
|
| 311 |
|
|
|
|
|
|
|
| 312 |
# AUTOMATISCHER FACE-FIX NUR BEI PERSONEN
|
| 313 |
-
if FACEFIX_AVAILABLE and
|
| 314 |
-
print("
|
| 315 |
-
|
|
|
|
|
|
|
|
|
|
| 316 |
try:
|
| 317 |
# Originalbild speichern für Vergleich
|
| 318 |
original_image = image.copy()
|
|
|
|
| 319 |
|
| 320 |
# Face-Fix anwenden
|
| 321 |
-
|
| 322 |
image=image,
|
| 323 |
prompt=enhanced_prompt,
|
| 324 |
negative_prompt=auto_negatives,
|
|
@@ -326,7 +346,8 @@ def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress(
|
|
| 326 |
model_id=model_id
|
| 327 |
)
|
| 328 |
|
| 329 |
-
|
|
|
|
| 330 |
|
| 331 |
# Optional: Vergleichsbild erstellen
|
| 332 |
try:
|
|
@@ -350,30 +371,44 @@ def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress(
|
|
| 350 |
|
| 351 |
# Vergleichsbild als Option zurückgeben
|
| 352 |
image = comparison
|
|
|
|
| 353 |
|
| 354 |
except Exception as e:
|
| 355 |
-
print(f"Vergleichsbild konnte nicht erstellt werden: {e}")
|
| 356 |
-
# Bei Fehler einfach das verbesserte Bild verwenden
|
| 357 |
|
| 358 |
except Exception as e:
|
| 359 |
-
print(f"Face-Fix
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 360 |
|
| 361 |
duration = time.time() - start_time
|
| 362 |
config = MODEL_CONFIGS.get(model_id, {"name": model_id})
|
| 363 |
-
status_msg = f"Generiert mit {config.get('name', model_id)} in {duration:.1f}s"
|
| 364 |
|
| 365 |
-
# Face-Fix Info
|
| 366 |
-
if FACEFIX_AVAILABLE and
|
| 367 |
-
status_msg
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 368 |
|
| 369 |
return image, status_msg
|
| 370 |
|
| 371 |
except Exception as e:
|
| 372 |
-
print(f"Fehler in text_to_image: {e}")
|
| 373 |
import traceback
|
| 374 |
traceback.print_exc()
|
| 375 |
return None, f"Fehler: {str(e)}"
|
| 376 |
|
|
|
|
|
|
|
| 377 |
def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
|
| 378 |
face_preserve, bbox_x1, bbox_y1, bbox_x2, bbox_y2,
|
| 379 |
progress=gr.Progress()):
|
|
|
|
| 275 |
|
| 276 |
return preview
|
| 277 |
|
| 278 |
+
|
| 279 |
+
# === HAUPTFUNKTION: TEXT ZU BILD MIT AUTOMATISCHEM FACE-FIX - KORRIGIERT ===
|
| 280 |
def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress()):
|
| 281 |
try:
|
| 282 |
if not prompt or not prompt.strip():
|
| 283 |
return None, "Bitte einen Prompt eingeben"
|
| 284 |
|
| 285 |
+
print(f"\n" + "="*60)
|
| 286 |
+
print(f"🔧 START: Text zu Bild Generierung")
|
| 287 |
+
print(f"🔧 Prompt: {prompt}")
|
| 288 |
+
print(f"🔧 Modell: {model_id}")
|
| 289 |
+
|
| 290 |
+
# Personenerkennung ZUERST auf dem ORIGINAL Prompt!
|
| 291 |
+
is_person = is_person_prompt(prompt)
|
| 292 |
+
print(f"🔧 Person erkannt? {is_person}")
|
| 293 |
+
|
| 294 |
auto_negatives = auto_negative_prompt(prompt)
|
| 295 |
+
print(f"🔧 Auto Negative Prompt: {auto_negatives[:100]}...")
|
| 296 |
+
|
| 297 |
start_time = time.time()
|
| 298 |
|
| 299 |
# Qualitäts-Boost nur wenn nicht vorhanden
|
|
|
|
| 302 |
has_weights = bool(re.search(r':\d+\.\d+|\([^)]+:\d', prompt))
|
| 303 |
|
| 304 |
enhanced_prompt = f"masterpiece, raw, best quality, highly detailed, {prompt}" if not (has_quality or has_weights) else prompt
|
| 305 |
+
print(f"🔧 Enhanced Prompt: {enhanced_prompt[:100]}...")
|
| 306 |
|
| 307 |
progress(0, desc="Lade Modell...")
|
| 308 |
pipe = load_txt2img(model_id)
|
| 309 |
|
| 310 |
seed = random.randint(0, 2**32 - 1)
|
| 311 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 312 |
+
print(f"🔧 Seed: {seed}")
|
| 313 |
|
| 314 |
+
print(f"🔧 Starte Bildgenerierung...")
|
| 315 |
image = pipe(
|
| 316 |
prompt=enhanced_prompt,
|
| 317 |
negative_prompt=auto_negatives,
|
|
|
|
| 323 |
callback_on_step_end_tensor_inputs=[],
|
| 324 |
).images[0]
|
| 325 |
|
| 326 |
+
print(f"✅ Bildgenerierung abgeschlossen")
|
| 327 |
+
|
| 328 |
# AUTOMATISCHER FACE-FIX NUR BEI PERSONEN
|
| 329 |
+
if FACEFIX_AVAILABLE and is_person:
|
| 330 |
+
print("\n" + "🎭"*30)
|
| 331 |
+
print("🎭 PERSON ERKANNT → Starte Face-Fix für perfekte Gesichter...")
|
| 332 |
+
print("🎭"*30)
|
| 333 |
+
|
| 334 |
+
progress(0.9, desc="Perfektioniere Gesicht & Hände...")
|
| 335 |
try:
|
| 336 |
# Originalbild speichern für Vergleich
|
| 337 |
original_image = image.copy()
|
| 338 |
+
print("🎭 Originalbild gespeichert, starte Face-Fix...")
|
| 339 |
|
| 340 |
# Face-Fix anwenden
|
| 341 |
+
fixed_image = apply_facefix(
|
| 342 |
image=image,
|
| 343 |
prompt=enhanced_prompt,
|
| 344 |
negative_prompt=auto_negatives,
|
|
|
|
| 346 |
model_id=model_id
|
| 347 |
)
|
| 348 |
|
| 349 |
+
image = fixed_image
|
| 350 |
+
print("✅✅✅ Face-Fix ABGESCHLOSSEN! ✅✅✅")
|
| 351 |
|
| 352 |
# Optional: Vergleichsbild erstellen
|
| 353 |
try:
|
|
|
|
| 371 |
|
| 372 |
# Vergleichsbild als Option zurückgeben
|
| 373 |
image = comparison
|
| 374 |
+
print("✅ Vergleichsbild erstellt")
|
| 375 |
|
| 376 |
except Exception as e:
|
| 377 |
+
print(f"⚠️ Vergleichsbild konnte nicht erstellt werden: {e}")
|
|
|
|
| 378 |
|
| 379 |
except Exception as e:
|
| 380 |
+
print(f"❌❌❌ Face-Fix FEHLGESCHLAGEN: {e} ❌❌❌")
|
| 381 |
+
import traceback
|
| 382 |
+
traceback.print_exc()
|
| 383 |
+
else:
|
| 384 |
+
if not FACEFIX_AVAILABLE:
|
| 385 |
+
print("ℹ️ Face-Fix nicht verfügbar")
|
| 386 |
+
if not is_person:
|
| 387 |
+
print("ℹ️ Keine Person im Prompt erkannt")
|
| 388 |
|
| 389 |
duration = time.time() - start_time
|
| 390 |
config = MODEL_CONFIGS.get(model_id, {"name": model_id})
|
|
|
|
| 391 |
|
| 392 |
+
# Status-Nachricht mit Face-Fix Info
|
| 393 |
+
if FACEFIX_AVAILABLE and is_person:
|
| 394 |
+
status_msg = f"✅ Generiert mit {config.get('name', model_id)} + Face-Fix in {duration:.1f}s"
|
| 395 |
+
else:
|
| 396 |
+
status_msg = f"Generiert mit {config.get('name', model_id)} in {duration:.1f}s"
|
| 397 |
+
|
| 398 |
+
print(f"\n" + "="*60)
|
| 399 |
+
print(f"✅ FERTIG: {status_msg}")
|
| 400 |
+
print(f"="*60 + "\n")
|
| 401 |
|
| 402 |
return image, status_msg
|
| 403 |
|
| 404 |
except Exception as e:
|
| 405 |
+
print(f"❌ Fehler in text_to_image: {e}")
|
| 406 |
import traceback
|
| 407 |
traceback.print_exc()
|
| 408 |
return None, f"Fehler: {str(e)}"
|
| 409 |
|
| 410 |
+
|
| 411 |
+
|
| 412 |
def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
|
| 413 |
face_preserve, bbox_x1, bbox_y1, bbox_x2, bbox_y2,
|
| 414 |
progress=gr.Progress()):
|