Astridkraft commited on
Commit
1b18b73
·
verified ·
1 Parent(s): a9a0e92

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -1
app.py CHANGED
@@ -438,6 +438,45 @@ def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress(
438
 
439
  start_time = time.time()
440
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  progress(0, desc="Lade Modell...")
442
  pipe = load_txt2img(model_id)
443
 
@@ -450,7 +489,7 @@ def text_to_image(prompt, model_id, steps, guidance_scale, progress=gr.Progress(
450
  print(f"⚙️ Einstellungen: Steps={steps}, CFG={guidance_scale}")
451
 
452
  image = pipe(
453
- prompt=prompt,
454
  negative_prompt=auto_negatives,
455
  height=512,
456
  width=512,
 
438
 
439
  start_time = time.time()
440
 
441
+
442
+ # Liste von Qualitätswörtern/Gewichten, die auf Benutzereingaben prüfen
443
+ quality_keywords = ['masterpiece', 'best quality', 'high quality', 'highly detailed',
444
+ 'exquisite', 'detailed', 'ultra detailed', 'professional',
445
+ 'perfect', 'excellent', 'amazing', 'stunning', 'beautiful']
446
+
447
+ # Prüfe, ob der Benutzer bereits Qualitätswörter/Gewichte verwendet hat
448
+ user_has_quality_words = False
449
+
450
+ # Konvertiere Prompt zu Kleinbuchstaben für die Prüfung
451
+ prompt_lower = prompt.lower()
452
+
453
+ # Prüfe auf einfache Qualitätswörter
454
+ for keyword in quality_keywords:
455
+ if keyword in prompt_lower:
456
+ user_has_quality_words = True
457
+ print(f"✓ Benutzer verwendet bereits Qualitätswort: {keyword}")
458
+ break
459
+
460
+ # Prüfe auf Gewichte (z.B. (word:1.5), [word], etc.)
461
+ weight_patterns = [r'\([^)]+:\d+(\.\d+)?\)', r'\[[^\]]+\]']
462
+ for pattern in weight_patterns:
463
+ if re.search(pattern, prompt):
464
+ user_has_quality_words = True
465
+ print("✓ Benutzer verwendet bereits Gewichte im Prompt")
466
+ break
467
+
468
+ # Prompt basierend auf Prüfung anpassen
469
+ if not user_has_quality_words:
470
+ enhanced_prompt = f"masterpiece, raw, best quality, highly detailed, {prompt}"
471
+ print(f"🔄 Verbesserter Prompt: {enhanced_prompt}")
472
+ else:
473
+ enhanced_prompt = prompt
474
+ print("✓ Benutzerprompt wird unverändert verwendet")
475
+
476
+ print(f"Finaler Prompt für Generation: {enhanced_prompt}")
477
+
478
+
479
+
480
  progress(0, desc="Lade Modell...")
481
  pipe = load_txt2img(model_id)
482
 
 
489
  print(f"⚙️ Einstellungen: Steps={steps}, CFG={guidance_scale}")
490
 
491
  image = pipe(
492
+ prompt=enhanced_prompt,
493
  negative_prompt=auto_negatives,
494
  height=512,
495
  width=512,