Astridkraft commited on
Commit
b8fcada
·
verified ·
1 Parent(s): cfbbb13

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +46 -2
app.py CHANGED
@@ -490,6 +490,50 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
490
  print(f"Prompt: {prompt}")
491
  print(f"Negativ-Prompt: {neg_prompt}")
492
  print(f"Gesicht beibehalten: {face_preserve}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
493
 
494
  progress(0, desc="Starte Generierung mit ControlNet...")
495
 
@@ -511,7 +555,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
511
  controlnet_output, inpaint_input = controlnet_processor.generate_with_controlnet(
512
  image=image,
513
  prompt=prompt,
514
- negative_prompt=neg_prompt,
515
  steps=controlnet_steps,
516
  guidance_scale=guidance_scale,
517
  controlnet_strength=controlnet_strength,
@@ -558,7 +602,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
558
 
559
  result = pipe(
560
  prompt=prompt,
561
- negative_prompt=neg_prompt,
562
  image=img_resized,
563
  mask_image=mask,
564
  strength=adj_strength,
 
490
  print(f"Prompt: {prompt}")
491
  print(f"Negativ-Prompt: {neg_prompt}")
492
  print(f"Gesicht beibehalten: {face_preserve}")
493
+
494
+
495
+ # ===== NEU: AUTOMATISCHEN NEGATIV-PROMPT GENERIEREN =====
496
+ auto_negatives = auto_negative_prompt(prompt)
497
+ print(f"🤖 Automatisch generierter Negativ-Prompt: {auto_negatives}")
498
+
499
+ # ===== NEU: KOMBINIERE MANUELLEN UND AUTOMATISCHEN PROMPT =====
500
+ combined_negative_prompt = ""
501
+
502
+ if neg_prompt and neg_prompt.strip():
503
+ # Benutzer hat einen Negativ-Prompt eingegeben
504
+ user_neg = neg_prompt.strip()
505
+ print(f"👤 Benutzer Negativ-Prompt: {user_neg}")
506
+
507
+ # Entferne Duplikate zwischen automatischen und manuellen Prompts
508
+ # Konvertiere beide in Sets für einfachen Duplikatvergleich
509
+ user_words = [word.strip().lower() for word in user_neg.split(",")]
510
+ auto_words = [word.strip().lower() for word in auto_negatives.split(",")]
511
+
512
+ # Starte mit dem Benutzer-Prompt
513
+ combined_words = user_words.copy()
514
+
515
+ # Füge automatische Wörter hinzu, die nicht bereits vorhanden sind
516
+ for auto_word in auto_words:
517
+ if auto_word and auto_word not in user_words:
518
+ combined_words.append(auto_word)
519
+
520
+ # Zusammenfügen und Duplikate entfernen (für den Fall von Duplikaten innerhalb des gleichen Prompts)
521
+ unique_words = []
522
+ seen_words = set()
523
+ for word in combined_words:
524
+ if word and word not in seen_words:
525
+ unique_words.append(word)
526
+ seen_words.add(word)
527
+
528
+ combined_negative_prompt = ", ".join(unique_words)
529
+ else:
530
+ # Kein Benutzer-Prompt, verwende nur den automatischen
531
+ combined_negative_prompt = auto_negatives
532
+ print(f"ℹ️ Kein manueller Negativ-Prompt, verwende nur automatischen: {combined_negative_prompt}")
533
+
534
+ print(f"✅ Finaler kombinierter Negativ-Prompt: {combined_negative_prompt}")
535
+ # ===== ENDE DER NEUEN LOGIK =====
536
+
537
 
538
  progress(0, desc="Starte Generierung mit ControlNet...")
539
 
 
555
  controlnet_output, inpaint_input = controlnet_processor.generate_with_controlnet(
556
  image=image,
557
  prompt=prompt,
558
+ negative_prompt=combined_negative_prompt,
559
  steps=controlnet_steps,
560
  guidance_scale=guidance_scale,
561
  controlnet_strength=controlnet_strength,
 
602
 
603
  result = pipe(
604
  prompt=prompt,
605
+ negative_prompt=combined_negative_prompt,
606
  image=img_resized,
607
  mask_image=mask,
608
  strength=adj_strength,