Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,6 +8,65 @@ import os
|
|
| 8 |
import tempfile
|
| 9 |
import random
|
| 10 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
# === OPTIMIERTE EINSTELLUNGEN ===
|
| 12 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 13 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
|
@@ -238,6 +297,10 @@ def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
|
|
| 238 |
|
| 239 |
pipe = load_txt2img()
|
| 240 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 241 |
seed = random.randint(0, 2**32 - 1)
|
| 242 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 243 |
print(f"Using seed: {seed}")
|
|
@@ -246,6 +309,7 @@ def text_to_image(prompt, steps, guidance_scale, progress=gr.Progress()):
|
|
| 246 |
|
| 247 |
image = pipe(
|
| 248 |
prompt=prompt,
|
|
|
|
| 249 |
height=IMG_SIZE,
|
| 250 |
width=IMG_SIZE,
|
| 251 |
num_inference_steps=int(steps),
|
|
|
|
| 8 |
import tempfile
|
| 9 |
import random
|
| 10 |
|
| 11 |
+
# === AUTOMATISCHE NEGATIVE PROMPT GENERIERUNG ===
|
| 12 |
+
def auto_negative_prompt(positive_prompt):
|
| 13 |
+
"""Generiert automatisch negative Prompts basierend auf dem positiven Prompt"""
|
| 14 |
+
p = positive_prompt.lower()
|
| 15 |
+
negatives = []
|
| 16 |
+
|
| 17 |
+
# Personen / Portraits
|
| 18 |
+
if any(w in p for w in ["person", "man", "woman", "face", "portrait", "team", "employee", "people", "crowd"]):
|
| 19 |
+
negatives.append(
|
| 20 |
+
"bad anatomy, malformed hands, extra fingers, uneven eyes, distorted face, unrealistic skin, mutated, deformed, ugly, disfigured, poorly drawn face, missing limbs, extra limbs, fused fingers, too many fingers, bad teeth, mutated hands, long neck"
|
| 21 |
+
)
|
| 22 |
+
|
| 23 |
+
# Business / Corporate
|
| 24 |
+
if any(w in p for w in ["office", "business", "team", "meeting", "corporate", "company", "workplace"]):
|
| 25 |
+
negatives.append(
|
| 26 |
+
"overexposed, oversaturated, harsh lighting, watermark, text, logo, amateur photo, lens flare, chromatic aberration, brand"
|
| 27 |
+
)
|
| 28 |
+
|
| 29 |
+
# Produkt / CGI
|
| 30 |
+
if any(w in p for w in ["product", "packshot", "mockup", "render", "3d", "cgi", "packaging"]):
|
| 31 |
+
negatives.append(
|
| 32 |
+
"plastic texture, noisy, overly reflective surfaces, watermark, text, render artifacts, unrealistic shadows, 3d model artifacts, low poly"
|
| 33 |
+
)
|
| 34 |
+
|
| 35 |
+
# Landschaft / Umgebung
|
| 36 |
+
if any(w in p for w in ["landscape", "nature", "mountain", "forest", "outdoor", "beach", "sky"]):
|
| 37 |
+
negatives.append(
|
| 38 |
+
"blurry, oversaturated, unnatural colors, distorted horizon, repeating patterns, plastic grass, unrealistic water, floating objects"
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Logos / Symbole
|
| 42 |
+
if any(w in p for w in ["logo", "symbol", "icon", "typography", "badge", "emblem"]):
|
| 43 |
+
negatives.append(
|
| 44 |
+
"watermark, signature, username, text, writing, scribble, pixelated, distorted shapes, misaligned elements, messy"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
# Architektur / Gebäude
|
| 48 |
+
if any(w in p for w in ["building", "architecture", "house", "interior", "room", "facade"]):
|
| 49 |
+
negatives.append(
|
| 50 |
+
"deformed, distorted perspective, floating objects, unrealistic materials, leaning building, warped surfaces, collapsing structure"
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
# Kunst / Stil (NEUE KATEGORIE)
|
| 54 |
+
if any(w in p for w in ["art", "painting", "drawing", "illustration", "sketch", "artwork", "creative", "style"]):
|
| 55 |
+
negatives.append(
|
| 56 |
+
"3d render, cgi, cartoon, anime, painting, drawing, sketch, plastic look, digital painting, unrealistic"
|
| 57 |
+
)
|
| 58 |
+
|
| 59 |
+
# Basis negative Prompts für alle Fälle
|
| 60 |
+
base_negatives = "low quality, worst quality, blurry, jpeg artifacts, ugly, deformed"
|
| 61 |
+
|
| 62 |
+
if negatives:
|
| 63 |
+
result = base_negatives + ", " + ", ".join(negatives)
|
| 64 |
+
else:
|
| 65 |
+
result = base_negatives
|
| 66 |
+
|
| 67 |
+
print(f"🔍 Automatischer Negativ-Prompt generiert: {result[:100]}...")
|
| 68 |
+
return result
|
| 69 |
+
|
| 70 |
# === OPTIMIERTE EINSTELLUNGEN ===
|
| 71 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 72 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
|
|
|
| 297 |
|
| 298 |
pipe = load_txt2img()
|
| 299 |
|
| 300 |
+
# Automatischen Negativ-Prompt generieren
|
| 301 |
+
neg_prompt = auto_negative_prompt(prompt)
|
| 302 |
+
print(f"🔍 Verwendeter Negativ-Prompt: {neg_prompt}")
|
| 303 |
+
|
| 304 |
seed = random.randint(0, 2**32 - 1)
|
| 305 |
generator = torch.Generator(device=device).manual_seed(seed)
|
| 306 |
print(f"Using seed: {seed}")
|
|
|
|
| 309 |
|
| 310 |
image = pipe(
|
| 311 |
prompt=prompt,
|
| 312 |
+
negative_prompt=neg_prompt, # Automatischen Negativ-Prompt verwenden
|
| 313 |
height=IMG_SIZE,
|
| 314 |
width=IMG_SIZE,
|
| 315 |
num_inference_steps=int(steps),
|