Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ IMG_SIZE = 512
|
|
| 17 |
|
| 18 |
print(f"Running on: {device}")
|
| 19 |
|
| 20 |
-
# === MODELLKONFIGURATION ===
|
| 21 |
MODEL_CONFIGS = {
|
| 22 |
"runwayml/stable-diffusion-v1-5": {
|
| 23 |
"name": "🏠 Stable Diffusion 1.5 (Universal)",
|
|
@@ -25,7 +25,7 @@ MODEL_CONFIGS = {
|
|
| 25 |
"requires_vae": False,
|
| 26 |
"recommended_steps": 35,
|
| 27 |
"recommended_cfg": 7.5,
|
| 28 |
-
"supports_fp16": True
|
| 29 |
},
|
| 30 |
"SG161222/Realistic_Vision_V6.0_B1_noVAE": {
|
| 31 |
"name": "👤 Realistic Vision V6.0 (Portraits)",
|
|
@@ -34,40 +34,12 @@ MODEL_CONFIGS = {
|
|
| 34 |
"vae_model": "stabilityai/sd-vae-ft-mse",
|
| 35 |
"recommended_steps": 40,
|
| 36 |
"recommended_cfg": 7.0,
|
| 37 |
-
"supports_fp16": False
|
| 38 |
-
},
|
| 39 |
-
"RunDiffusion/Juggernaut-X-v10": {
|
| 40 |
-
"name": "🏢 Juggernaut X (Business)",
|
| 41 |
-
"description": "Ideal for corporate images, team photos, professional settings",
|
| 42 |
-
"requires_vae": False,
|
| 43 |
-
"recommended_steps": 35,
|
| 44 |
-
"recommended_cfg": 7.5,
|
| 45 |
-
"supports_fp16": False # Custom Model, keine FP16 Variante
|
| 46 |
-
},
|
| 47 |
-
"Lykon/DreamShaper": {
|
| 48 |
-
"name": "🎨 DreamShaper (Artistic)",
|
| 49 |
-
"description": "Creative interpretations, artistic styles, illustrations",
|
| 50 |
-
"requires_vae": False,
|
| 51 |
-
"recommended_steps": 40,
|
| 52 |
-
"recommended_cfg": 8.0,
|
| 53 |
-
"supports_fp16": False # Custom Model, keine FP16 Variante
|
| 54 |
-
},
|
| 55 |
-
"nitrosocke/redshift-diffusion": {
|
| 56 |
-
"name": "🖼️ Redshift Diffusion (Design)",
|
| 57 |
-
"description": "Clean CGI style, product visuals, design mockups",
|
| 58 |
-
"requires_vae": False,
|
| 59 |
-
"recommended_steps": 30,
|
| 60 |
-
"recommended_cfg": 8.5,
|
| 61 |
-
"supports_fp16": False # Custom Model, keine FP16 Variante
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
| 65 |
-
|
| 66 |
# === SAFETENSORS KONFIGURATION ===
|
| 67 |
-
SAFETENSORS_MODELS = [
|
| 68 |
-
"runwayml/stable-diffusion-v1-5",
|
| 69 |
-
"stabilityai/stable-diffusion-2-1"
|
| 70 |
-
]
|
| 71 |
|
| 72 |
# Aktuell ausgewähltes Modell (wird vom User gesetzt)
|
| 73 |
current_model_id = "runwayml/stable-diffusion-v1-5"
|
|
@@ -79,11 +51,19 @@ def auto_negative_prompt(positive_prompt):
|
|
| 79 |
negatives = []
|
| 80 |
|
| 81 |
# Personen / Portraits
|
| 82 |
-
if any(w in p for w in [
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
negatives.append(
|
| 84 |
-
"bad anatomy, malformed hands, extra fingers, uneven eyes, distorted face,
|
|
|
|
|
|
|
|
|
|
| 85 |
)
|
| 86 |
-
|
| 87 |
# Business / Corporate
|
| 88 |
if any(w in p for w in ["office", "business", "team", "meeting", "corporate", "company", "workplace"]):
|
| 89 |
negatives.append(
|
|
@@ -194,7 +174,6 @@ def load_txt2img(model_id):
|
|
| 194 |
print(f"⚠️ Fehler beim Laden der VAE: {vae_error}")
|
| 195 |
print("ℹ️ Versuche ohne VAE weiter...")
|
| 196 |
vae = None
|
| 197 |
-
|
| 198 |
|
| 199 |
# Modellparameter basierend auf Modelltyp
|
| 200 |
model_params = {
|
|
@@ -202,21 +181,18 @@ def load_txt2img(model_id):
|
|
| 202 |
"safety_checker": None,
|
| 203 |
"requires_safety_checker": False,
|
| 204 |
"add_watermarker": False,
|
| 205 |
-
"allow_pickle": True, #
|
| 206 |
-
}
|
| 207 |
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
# SAFETENSORS LOGIK HIER EINFÜGEN:
|
| 211 |
if model_id in SAFETENSORS_MODELS:
|
| 212 |
model_params["use_safetensors"] = True
|
| 213 |
print(f"ℹ️ Verwende safetensors für {model_id}")
|
| 214 |
else:
|
| 215 |
model_params["use_safetensors"] = False
|
| 216 |
print(f"ℹ️ Verwende .bin weights für {model_id}")
|
| 217 |
-
|
| 218 |
|
| 219 |
-
#
|
| 220 |
if config.get("supports_fp16", False) and torch_dtype == torch.float16:
|
| 221 |
model_params["variant"] = "fp16"
|
| 222 |
print("ℹ️ Verwende FP16 Variante")
|
|
@@ -272,7 +248,6 @@ def load_txt2img(model_id):
|
|
| 272 |
except Exception as scheduler_error:
|
| 273 |
print(f"⚠️ Konnte DPM-Scheduler nicht setzen: {scheduler_error}")
|
| 274 |
print("ℹ️ Verwende Standard-Scheduler weiter")
|
| 275 |
-
# Behalte den aktuellen Scheduler bei
|
| 276 |
|
| 277 |
# Optimierungen
|
| 278 |
pipe_txt2img.enable_attention_slicing()
|
|
@@ -727,7 +702,7 @@ def main_ui():
|
|
| 727 |
|
| 728 |
with gr.Row():
|
| 729 |
with gr.Column(scale=2):
|
| 730 |
-
# Modellauswahl Dropdown
|
| 731 |
model_dropdown = gr.Dropdown(
|
| 732 |
choices=[
|
| 733 |
(config["name"], model_id)
|
|
@@ -735,7 +710,7 @@ def main_ui():
|
|
| 735 |
],
|
| 736 |
value="runwayml/stable-diffusion-v1-5",
|
| 737 |
label="📁 Modellauswahl",
|
| 738 |
-
info="
|
| 739 |
)
|
| 740 |
|
| 741 |
# Modellinformationen Box
|
|
@@ -966,5 +941,5 @@ if __name__ == "__main__":
|
|
| 966 |
max_file_size="10MB",
|
| 967 |
show_error=True,
|
| 968 |
share=False,
|
| 969 |
-
ssr_mode=False #
|
| 970 |
)
|
|
|
|
| 17 |
|
| 18 |
print(f"Running on: {device}")
|
| 19 |
|
| 20 |
+
# === MODELLKONFIGURATION (NUR 2 MODELLE) ===
|
| 21 |
MODEL_CONFIGS = {
|
| 22 |
"runwayml/stable-diffusion-v1-5": {
|
| 23 |
"name": "🏠 Stable Diffusion 1.5 (Universal)",
|
|
|
|
| 25 |
"requires_vae": False,
|
| 26 |
"recommended_steps": 35,
|
| 27 |
"recommended_cfg": 7.5,
|
| 28 |
+
"supports_fp16": True
|
| 29 |
},
|
| 30 |
"SG161222/Realistic_Vision_V6.0_B1_noVAE": {
|
| 31 |
"name": "👤 Realistic Vision V6.0 (Portraits)",
|
|
|
|
| 34 |
"vae_model": "stabilityai/sd-vae-ft-mse",
|
| 35 |
"recommended_steps": 40,
|
| 36 |
"recommended_cfg": 7.0,
|
| 37 |
+
"supports_fp16": False
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
|
|
|
| 41 |
# === SAFETENSORS KONFIGURATION ===
|
| 42 |
+
SAFETENSORS_MODELS = ["runwayml/stable-diffusion-v1-5"]
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Aktuell ausgewähltes Modell (wird vom User gesetzt)
|
| 45 |
current_model_id = "runwayml/stable-diffusion-v1-5"
|
|
|
|
| 51 |
negatives = []
|
| 52 |
|
| 53 |
# Personen / Portraits
|
| 54 |
+
if any(w in p for w in [
|
| 55 |
+
"person", "man", "woman", "face", "portrait", "team", "employee",
|
| 56 |
+
"people", "crowd", "character", "figure", "human", "child", "baby",
|
| 57 |
+
"girl", "boy", "lady", "gentleman", "fairy", "elf", "dwarf", "orc",
|
| 58 |
+
"mermaid", "angel", "demon", "witch", "wizard", "creature", "being",
|
| 59 |
+
"model", "actor", "actress", "celebrity", "avatar", "persona"]):
|
| 60 |
negatives.append(
|
| 61 |
+
"bad anatomy, malformed hands, extra fingers, uneven eyes, distorted face, "
|
| 62 |
+
"unrealistic skin, mutated, deformed, ugly, disfigured, poorly drawn face, "
|
| 63 |
+
"missing limbs, extra limbs, fused fingers, too many fingers, bad teeth, "
|
| 64 |
+
"mutated hands, long neck, extra wings, multiple wings"
|
| 65 |
)
|
| 66 |
+
|
| 67 |
# Business / Corporate
|
| 68 |
if any(w in p for w in ["office", "business", "team", "meeting", "corporate", "company", "workplace"]):
|
| 69 |
negatives.append(
|
|
|
|
| 174 |
print(f"⚠️ Fehler beim Laden der VAE: {vae_error}")
|
| 175 |
print("ℹ️ Versuche ohne VAE weiter...")
|
| 176 |
vae = None
|
|
|
|
| 177 |
|
| 178 |
# Modellparameter basierend auf Modelltyp
|
| 179 |
model_params = {
|
|
|
|
| 181 |
"safety_checker": None,
|
| 182 |
"requires_safety_checker": False,
|
| 183 |
"add_watermarker": False,
|
| 184 |
+
"allow_pickle": True, # Für .bin Modelle wichtig
|
| 185 |
+
}
|
| 186 |
|
| 187 |
+
# SAFETENSORS LOGIK
|
|
|
|
|
|
|
| 188 |
if model_id in SAFETENSORS_MODELS:
|
| 189 |
model_params["use_safetensors"] = True
|
| 190 |
print(f"ℹ️ Verwende safetensors für {model_id}")
|
| 191 |
else:
|
| 192 |
model_params["use_safetensors"] = False
|
| 193 |
print(f"ℹ️ Verwende .bin weights für {model_id}")
|
|
|
|
| 194 |
|
| 195 |
+
# FP16 Variante nur wenn Modell sie unterstützt UND wir auf GPU sind
|
| 196 |
if config.get("supports_fp16", False) and torch_dtype == torch.float16:
|
| 197 |
model_params["variant"] = "fp16"
|
| 198 |
print("ℹ️ Verwende FP16 Variante")
|
|
|
|
| 248 |
except Exception as scheduler_error:
|
| 249 |
print(f"⚠️ Konnte DPM-Scheduler nicht setzen: {scheduler_error}")
|
| 250 |
print("ℹ️ Verwende Standard-Scheduler weiter")
|
|
|
|
| 251 |
|
| 252 |
# Optimierungen
|
| 253 |
pipe_txt2img.enable_attention_slicing()
|
|
|
|
| 702 |
|
| 703 |
with gr.Row():
|
| 704 |
with gr.Column(scale=2):
|
| 705 |
+
# Modellauswahl Dropdown (NUR 2 MODELLE)
|
| 706 |
model_dropdown = gr.Dropdown(
|
| 707 |
choices=[
|
| 708 |
(config["name"], model_id)
|
|
|
|
| 710 |
],
|
| 711 |
value="runwayml/stable-diffusion-v1-5",
|
| 712 |
label="📁 Modellauswahl",
|
| 713 |
+
info="🏠 Universal vs 👤 Portraits"
|
| 714 |
)
|
| 715 |
|
| 716 |
# Modellinformationen Box
|
|
|
|
| 941 |
max_file_size="10MB",
|
| 942 |
show_error=True,
|
| 943 |
share=False,
|
| 944 |
+
ssr_mode=False # SSR deaktivieren für Stabilität
|
| 945 |
)
|