Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -7,6 +7,7 @@ import time
|
|
| 7 |
import os
|
| 8 |
import tempfile
|
| 9 |
import random
|
|
|
|
| 10 |
|
| 11 |
# === AUTOMATISCHE NEGATIVE PROMPT GENERIERUNG ===
|
| 12 |
def auto_negative_prompt(positive_prompt):
|
|
@@ -301,7 +302,44 @@ def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
|
|
| 301 |
|
| 302 |
print(f"Starting generation for: {prompt}")
|
| 303 |
start_time = time.time()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 304 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 305 |
progress(0, desc="Generierung läuft - CPU benötigt bis zu 10 Minuten!")
|
| 306 |
|
| 307 |
pipe = load_txt2img()
|
|
@@ -317,7 +355,7 @@ def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
|
|
| 317 |
callback = TextToImageProgressCallback(progress, steps)
|
| 318 |
|
| 319 |
image = pipe(
|
| 320 |
-
prompt=
|
| 321 |
negative_prompt=neg_prompt, # Automatischen Negativ-Prompt verwenden
|
| 322 |
height=IMG_SIZE,
|
| 323 |
width=IMG_SIZE,
|
|
|
|
| 7 |
import os
|
| 8 |
import tempfile
|
| 9 |
import random
|
| 10 |
+
import re # Für reguläre Ausdrücke zur Gewichtserkennung
|
| 11 |
|
| 12 |
# === AUTOMATISCHE NEGATIVE PROMPT GENERIERUNG ===
|
| 13 |
def auto_negative_prompt(positive_prompt):
|
|
|
|
| 302 |
|
| 303 |
print(f"Starting generation for: {prompt}")
|
| 304 |
start_time = time.time()
|
| 305 |
+
|
| 306 |
+
# Liste von Qualitätswörtern/Gewichten, die auf Benutzereingaben prüfen
|
| 307 |
+
quality_keywords = ['masterpiece', 'best quality', 'high quality', 'highly detailed',
|
| 308 |
+
'exquisite', 'detailed', 'ultra detailed', 'professional',
|
| 309 |
+
'perfect', 'excellent', 'amazing', 'stunning', 'beautiful']
|
| 310 |
+
|
| 311 |
+
# Prüfe, ob der Benutzer bereits Qualitätswörter/Gewichte verwendet hat
|
| 312 |
+
user_has_quality_words = False
|
| 313 |
+
|
| 314 |
+
# Konvertiere Prompt zu Kleinbuchstaben für die Prüfung
|
| 315 |
+
prompt_lower = prompt.lower()
|
| 316 |
+
|
| 317 |
+
# Prüfe auf einfache Qualitätswörter
|
| 318 |
+
for keyword in quality_keywords:
|
| 319 |
+
if keyword in prompt_lower:
|
| 320 |
+
user_has_quality_words = True
|
| 321 |
+
print(f"✓ Benutzer verwendet bereits Qualitätswort: {keyword}")
|
| 322 |
+
break
|
| 323 |
+
|
| 324 |
+
# Prüfe auf Gewichte (z.B. (word:1.5), [word], etc.)
|
| 325 |
+
weight_patterns = [r'\([^)]+:\d+(\.\d+)?\)', r'\[[^\]]+\]']
|
| 326 |
+
for pattern in weight_patterns:
|
| 327 |
+
if re.search(pattern, prompt):
|
| 328 |
+
user_has_quality_words = True
|
| 329 |
+
print("✓ Benutzer verwendet bereits Gewichte im Prompt")
|
| 330 |
+
break
|
| 331 |
|
| 332 |
+
# Prompt basierend auf Prüfung anpassen
|
| 333 |
+
if not user_has_quality_words:
|
| 334 |
+
enhanced_prompt = f"masterpiece, raw, best quality, highly detailed, {prompt}"
|
| 335 |
+
print(f"🔄 Verbesserter Prompt: {enhanced_prompt}")
|
| 336 |
+
else:
|
| 337 |
+
enhanced_prompt = prompt
|
| 338 |
+
print("✓ Benutzerprompt wird unverändert verwendet")
|
| 339 |
+
|
| 340 |
+
print(f"Finaler Prompt für Generation: {enhanced_prompt}")
|
| 341 |
+
|
| 342 |
+
|
| 343 |
progress(0, desc="Generierung läuft - CPU benötigt bis zu 10 Minuten!")
|
| 344 |
|
| 345 |
pipe = load_txt2img()
|
|
|
|
| 355 |
callback = TextToImageProgressCallback(progress, steps)
|
| 356 |
|
| 357 |
image = pipe(
|
| 358 |
+
prompt=enhanced_prompt,
|
| 359 |
negative_prompt=neg_prompt, # Automatischen Negativ-Prompt verwenden
|
| 360 |
height=IMG_SIZE,
|
| 361 |
width=IMG_SIZE,
|