Update app.py
Browse files
app.py
CHANGED
|
@@ -2,7 +2,7 @@
|
|
| 2 |
#und deutlich besserem Prompt-Verständnis - (Änderung Architektur).
|
| 3 |
#Eine deutsche Alternative zur Umsetzung von Text-Bild zu Bild ist Flux - mit einer völlig anderen Architektur als SD!
|
| 4 |
import gradio as gr
|
| 5 |
-
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline
|
| 6 |
from diffusers import StableDiffusionInpaintPipeline
|
| 7 |
from controlnet_module import controlnet_processor
|
| 8 |
import torch
|
|
@@ -17,7 +17,7 @@ import random
|
|
| 17 |
# === OPTIMIERTE EINSTELLUNGEN ===
|
| 18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
| 20 |
-
IMG_SIZE =
|
| 21 |
|
| 22 |
print(f"Running on: {device}")
|
| 23 |
|
|
@@ -65,18 +65,20 @@ pipe_img2img = None
|
|
| 65 |
def load_txt2img():
|
| 66 |
global pipe_txt2img
|
| 67 |
if pipe_txt2img is None:
|
| 68 |
-
print("Loading Text-to-Image model...")
|
| 69 |
-
pipe_txt2img =
|
| 70 |
-
"
|
| 71 |
torch_dtype=torch_dtype,
|
| 72 |
use_safetensors=True,
|
| 73 |
-
|
| 74 |
-
requires_safety_checker=False,
|
| 75 |
-
#clean_up_tokenization_spaces=False #bei der neuen Version ändert sich die Architektur, Clip wird ersetzt/erweitert/integriert. Tokenizer nicht mehr nur auf englisch, kein 77-Token Limit!
|
| 76 |
).to(device)
|
| 77 |
|
| 78 |
from diffusers import DPMSolverMultistepScheduler
|
| 79 |
-
pipe_txt2img.scheduler = DPMSolverMultistepScheduler.from_config(
|
|
|
|
|
|
|
|
|
|
|
|
|
| 80 |
pipe_txt2img.enable_attention_slicing()
|
| 81 |
return pipe_txt2img
|
| 82 |
|
|
@@ -331,7 +333,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
|
|
| 331 |
pipe = load_img2img() # ← deine bestehende Funktion
|
| 332 |
|
| 333 |
# inpaint_input ist IMMER das Originalbild (laut neuer ControlNet-Logik)
|
| 334 |
-
img_resized = inpaint_input.convert("RGB").resize((
|
| 335 |
|
| 336 |
adj_guidance = min(guidance_scale, 12.0)
|
| 337 |
seed = random.randint(0, 2**32 - 1)
|
|
@@ -344,7 +346,7 @@ def img_to_image(image, prompt, neg_prompt, strength, steps, guidance_scale,
|
|
| 344 |
mask = None
|
| 345 |
if bbox_x1 and bbox_y1 and bbox_x2 and bbox_y2:
|
| 346 |
orig_w, orig_h = image.size
|
| 347 |
-
scale_x, scale_y =
|
| 348 |
bbox_coords = [
|
| 349 |
int(bbox_x1 * scale_x),
|
| 350 |
int(bbox_y1 * scale_y),
|
|
@@ -476,7 +478,7 @@ def main_ui():
|
|
| 476 |
# --- Hauptanwendungsbereich (zunächst versteckt) ---
|
| 477 |
with gr.Column(visible=True) as content_area:
|
| 478 |
with gr.Tab("Text zu Bild"):
|
| 479 |
-
gr.Markdown("**Beschreibe dein gewünschtes Bild
|
| 480 |
|
| 481 |
with gr.Row():
|
| 482 |
txt_input = gr.Textbox(
|
|
@@ -580,14 +582,14 @@ def main_ui():
|
|
| 580 |
img_prompt = gr.Textbox(
|
| 581 |
placeholder="change background to beach with palm trees, keep person unchanged, sunny day",
|
| 582 |
lines=2,
|
| 583 |
-
label="Transformations-Prompt (Englisch
|
| 584 |
info="Was soll verändert werden? Sei spezifisch."
|
| 585 |
)
|
| 586 |
with gr.Column():
|
| 587 |
img_neg_prompt = gr.Textbox(
|
| 588 |
placeholder="blurry, deformed, ugly, bad anatomy, extra limbs, poorly drawn hands",
|
| 589 |
lines=2,
|
| 590 |
-
label="Negativ-Prompt (Englisch
|
| 591 |
info="Was soll vermieden werden? Unerwünschte Elemente auflisten."
|
| 592 |
)
|
| 593 |
|
|
|
|
| 2 |
#und deutlich besserem Prompt-Verständnis - (Änderung Architektur).
|
| 3 |
#Eine deutsche Alternative zur Umsetzung von Text-Bild zu Bild ist Flux - mit einer völlig anderen Architektur als SD!
|
| 4 |
import gradio as gr
|
| 5 |
+
from diffusers import StableDiffusionPipeline, StableDiffusionImg2ImgPipeline, StableDiffusionXLPipeline
|
| 6 |
from diffusers import StableDiffusionInpaintPipeline
|
| 7 |
from controlnet_module import controlnet_processor
|
| 8 |
import torch
|
|
|
|
| 17 |
# === OPTIMIERTE EINSTELLUNGEN ===
|
| 18 |
device = "cuda" if torch.cuda.is_available() else "cpu"
|
| 19 |
torch_dtype = torch.float16 if device == "cuda" else torch.float32
|
| 20 |
+
IMG_SIZE = 1024 # SDXL verwendet 1024x1024 statt 512x512
|
| 21 |
|
| 22 |
print(f"Running on: {device}")
|
| 23 |
|
|
|
|
| 65 |
def load_txt2img():
|
| 66 |
global pipe_txt2img
|
| 67 |
if pipe_txt2img is None:
|
| 68 |
+
print("Loading SDXL Text-to-Image model...")
|
| 69 |
+
pipe_txt2img = StableDiffusionXLPipeline.from_pretrained(
|
| 70 |
+
"stabilityai/stable-diffusion-xl-base-1.0",
|
| 71 |
torch_dtype=torch_dtype,
|
| 72 |
use_safetensors=True,
|
| 73 |
+
add_watermarker=False,
|
|
|
|
|
|
|
| 74 |
).to(device)
|
| 75 |
|
| 76 |
from diffusers import DPMSolverMultistepScheduler
|
| 77 |
+
pipe_txt2img.scheduler = DPMSolverMultistepScheduler.from_config(
|
| 78 |
+
pipe_txt2img.scheduler.config,
|
| 79 |
+
use_karras_sigmas=True, # Noch bessere Qualität
|
| 80 |
+
algorithm_type="sde-dpmsolver++"
|
| 81 |
+
)
|
| 82 |
pipe_txt2img.enable_attention_slicing()
|
| 83 |
return pipe_txt2img
|
| 84 |
|
|
|
|
| 333 |
pipe = load_img2img() # ← deine bestehende Funktion
|
| 334 |
|
| 335 |
# inpaint_input ist IMMER das Originalbild (laut neuer ControlNet-Logik)
|
| 336 |
+
img_resized = inpaint_input.convert("RGB").resize((512, 512)) # Bleibt bei 512 für Inpaint
|
| 337 |
|
| 338 |
adj_guidance = min(guidance_scale, 12.0)
|
| 339 |
seed = random.randint(0, 2**32 - 1)
|
|
|
|
| 346 |
mask = None
|
| 347 |
if bbox_x1 and bbox_y1 and bbox_x2 and bbox_y2:
|
| 348 |
orig_w, orig_h = image.size
|
| 349 |
+
scale_x, scale_y = 512 / orig_w, 512 / orig_h # Skalierung für Inpaint (512px)
|
| 350 |
bbox_coords = [
|
| 351 |
int(bbox_x1 * scale_x),
|
| 352 |
int(bbox_y1 * scale_y),
|
|
|
|
| 478 |
# --- Hauptanwendungsbereich (zunächst versteckt) ---
|
| 479 |
with gr.Column(visible=True) as content_area:
|
| 480 |
with gr.Tab("Text zu Bild"):
|
| 481 |
+
gr.Markdown("**Beschreibe dein gewünschtes Bild:**")
|
| 482 |
|
| 483 |
with gr.Row():
|
| 484 |
txt_input = gr.Textbox(
|
|
|
|
| 582 |
img_prompt = gr.Textbox(
|
| 583 |
placeholder="change background to beach with palm trees, keep person unchanged, sunny day",
|
| 584 |
lines=2,
|
| 585 |
+
label="Transformations-Prompt (Englisch)",
|
| 586 |
info="Was soll verändert werden? Sei spezifisch."
|
| 587 |
)
|
| 588 |
with gr.Column():
|
| 589 |
img_neg_prompt = gr.Textbox(
|
| 590 |
placeholder="blurry, deformed, ugly, bad anatomy, extra limbs, poorly drawn hands",
|
| 591 |
lines=2,
|
| 592 |
+
label="Negativ-Prompt (Englisch)",
|
| 593 |
info="Was soll vermieden werden? Unerwünschte Elemente auflisten."
|
| 594 |
)
|
| 595 |
|