Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,9 +1,8 @@
|
|
| 1 |
-
import spaces
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionXLPipeline
|
| 4 |
import gradio as gr
|
|
|
|
| 5 |
import random
|
| 6 |
-
import re
|
| 7 |
|
| 8 |
model_id = "kkntr/sdxl-kkntr"
|
| 9 |
|
|
@@ -13,8 +12,18 @@ pipe = StableDiffusionXLPipeline.from_pretrained(
|
|
| 13 |
use_safetensors=True
|
| 14 |
).to("cuda")
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"animal": [
|
| 19 |
"kangaroo", "otter", "tiger", "lion", "wolf", "fox", "polar bear", "deer", "reindeer", "hyena", "bull", "rabbit", "panther", "moose", "cheetah", "badger", "striped hyena", "rat", "crash bandicoot", "leopard", "thylacine", "bighorn sheep", "zebra", "horse", "donkey", "unicorn, white fur, rainbow hair, mythological equine", "alligator", "western dragon", "lizard", "crocodile", "theropod", "montgomery gator, fnaf", "tagg, dinosaur, reptile, scalie, theropod", "black russian terrier", "pit bull", "schnauzer", "dobermann", "mastiff", "molosser", "pinscher", "rottweiler", "tamaskan dog", "wolfdog", "alaskan husky", "alaskan malamute", "canadian eskimo dog", "german shepherd", "labrador husky", "siberian husky", "labrador", "golden retriever", "dalmatian", "border collie", "collie", "herding dog", "pastoral dog", "sheepdog", "carolina dog", "rhodesian ridgeback", "nordic sled dog", "spitz", "husky", "akita", "mountain dog", "primitive dog", "siberian retriever", "hunting dog", "australian cattle dog",
|
| 20 |
],
|
|
@@ -38,22 +47,60 @@ scratchpads = {
|
|
| 38 |
],
|
| 39 |
}
|
| 40 |
|
| 41 |
-
def
|
| 42 |
-
"""
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
return random.choice(scratchpads[tag])
|
| 49 |
-
return match.group(0) # jätä koskematta jos ei löydy
|
| 50 |
|
| 51 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
| 53 |
@spaces.GPU
|
| 54 |
-
def generate(prompt, negative_prompt, width, height):
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
quality_suffix = (
|
| 59 |
", (anthro), (male), (best quality), high resolution, (ultra detailed),"
|
|
@@ -77,30 +124,27 @@ def generate(prompt, negative_prompt, width, height):
|
|
| 77 |
|
| 78 |
return image, full_prompt
|
| 79 |
|
| 80 |
-
# Gradio UI
|
| 81 |
gr.Interface(
|
| 82 |
fn=generate,
|
| 83 |
inputs=[
|
| 84 |
-
gr.Textbox(label="Prompt"),
|
| 85 |
gr.Textbox(
|
| 86 |
label="Negative Prompt",
|
| 87 |
-
value="(worst quality), (low quality), (blurry), (bad anatomy), "
|
| 88 |
-
"(fused fingers), (extra fingers), (missing fingers), "
|
| 89 |
-
"(deformed), (jpeg artifacts), (watermark), (signature), "
|
| 90 |
-
"text, error, out of frame, bad hands, bad feet, bad proportions, "
|
| 91 |
-
"fused limbs, cropped, username, logo, bad perspective, "
|
| 92 |
-
"lowres, overexposure, bad artist, bad composition, "
|
| 93 |
-
"distorted, oversaturated, mutated, bad shadow, multiple limbs, "
|
| 94 |
-
"extra arms, extra legs, bad background, tilted, bad lighting, "
|
| 95 |
-
"bad face, ugly, bad eyes, disfigured, multiple pictures"
|
| 96 |
),
|
| 97 |
gr.Slider(minimum=512, maximum=1024, step=64, value=768, label="Width"),
|
| 98 |
gr.Slider(minimum=512, maximum=1024, step=64, value=768, label="Height"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 99 |
],
|
| 100 |
outputs=[
|
| 101 |
gr.Image(label="Generated Image"),
|
| 102 |
gr.Textbox(label="Used Prompt", lines=4)
|
| 103 |
],
|
| 104 |
-
title="FURRYSTYLE
|
| 105 |
-
description="
|
| 106 |
).launch()
|
|
|
|
|
|
|
| 1 |
import torch
|
| 2 |
from diffusers import StableDiffusionXLPipeline
|
| 3 |
import gradio as gr
|
| 4 |
+
import spaces
|
| 5 |
import random
|
|
|
|
| 6 |
|
| 7 |
model_id = "kkntr/sdxl-kkntr"
|
| 8 |
|
|
|
|
| 12 |
use_safetensors=True
|
| 13 |
).to("cuda")
|
| 14 |
|
| 15 |
+
pipe.load_lora_weights(
|
| 16 |
+
{
|
| 17 |
+
"kkntr/lora1": 0.2,
|
| 18 |
+
"kkntr/lora2": 0.3,
|
| 19 |
+
"kkntr/lora12": 0.4,
|
| 20 |
+
"kkntr/lora10": 0.1,
|
| 21 |
+
}
|
| 22 |
+
)
|
| 23 |
+
pipe.fuse_lora()
|
| 24 |
+
|
| 25 |
+
# Scratchpad vaihtoehdot
|
| 26 |
+
scratchpad = {
|
| 27 |
"animal": [
|
| 28 |
"kangaroo", "otter", "tiger", "lion", "wolf", "fox", "polar bear", "deer", "reindeer", "hyena", "bull", "rabbit", "panther", "moose", "cheetah", "badger", "striped hyena", "rat", "crash bandicoot", "leopard", "thylacine", "bighorn sheep", "zebra", "horse", "donkey", "unicorn, white fur, rainbow hair, mythological equine", "alligator", "western dragon", "lizard", "crocodile", "theropod", "montgomery gator, fnaf", "tagg, dinosaur, reptile, scalie, theropod", "black russian terrier", "pit bull", "schnauzer", "dobermann", "mastiff", "molosser", "pinscher", "rottweiler", "tamaskan dog", "wolfdog", "alaskan husky", "alaskan malamute", "canadian eskimo dog", "german shepherd", "labrador husky", "siberian husky", "labrador", "golden retriever", "dalmatian", "border collie", "collie", "herding dog", "pastoral dog", "sheepdog", "carolina dog", "rhodesian ridgeback", "nordic sled dog", "spitz", "husky", "akita", "mountain dog", "primitive dog", "siberian retriever", "hunting dog", "australian cattle dog",
|
| 29 |
],
|
|
|
|
| 47 |
],
|
| 48 |
}
|
| 49 |
|
| 50 |
+
def expand_prompt(prompt: str) -> str:
|
| 51 |
+
"""Korvaa scratchpad-tagit satunnaisilla vaihtoehdoilla"""
|
| 52 |
+
for tag, options in scratchpad.items():
|
| 53 |
+
if tag in prompt:
|
| 54 |
+
choice = random.choice(options)
|
| 55 |
+
prompt = prompt.replace(tag, choice, 1) # korvataan vain kerran
|
| 56 |
+
return prompt
|
|
|
|
|
|
|
| 57 |
|
| 58 |
+
resolutions = [
|
| 59 |
+
(592, 1768), (608, 1696), (640, 1624), (672, 1544),
|
| 60 |
+
(720, 1440), (744, 1392), (784, 1320), (832, 1248),
|
| 61 |
+
(864, 1208), (880, 1184), (912, 1144), (976, 1072),
|
| 62 |
+
(1024, 1024), (1072, 912), (1144, 912), (1184, 880),
|
| 63 |
+
(1208, 864), (1248, 832), (1320, 784), (1392, 744),
|
| 64 |
+
(1440, 720), (1544, 672), (1624, 640), (1696, 608),
|
| 65 |
+
(1768, 592),
|
| 66 |
+
]
|
| 67 |
+
|
| 68 |
+
lora_styles = {
|
| 69 |
+
"None": (None, 0.0, ""),
|
| 70 |
+
"Foreskin play": ("kkntr/lora5", 1.2, "foreskin insertion"),
|
| 71 |
+
"Cum through clothing": ("kkntr/lora6", 1.2, "cum in clothing"),
|
| 72 |
+
"Penis through leghole": ("kkntr/lora7", 9.0, "(((penis through leghole))), (loose shorts), (penis outline), poking out, genital outline, bulge flowing sideways along thigh, visible penis shape under fabric, tight crotch, fabric tension"),
|
| 73 |
+
"Frottage": ("kkntr/lora8", 1.2, "byfrottage, frottage"),
|
| 74 |
+
"Penis towards viewer": ("kkntr/lora9", 1.2, "penis_towards_viewer"),
|
| 75 |
+
"Foreskin play closeup": ("kkntr/lora11", 2.0, "ZonkFS"),
|
| 76 |
+
}
|
| 77 |
|
| 78 |
@spaces.GPU
|
| 79 |
+
def generate(prompt, negative_prompt, width, height, random_res, selected_style):
|
| 80 |
+
if random_res:
|
| 81 |
+
width, height = random.choice(resolutions)
|
| 82 |
+
|
| 83 |
+
# Expandataan scratchpad-tagit
|
| 84 |
+
prompt = expand_prompt(prompt)
|
| 85 |
+
|
| 86 |
+
# Valitaan tyyli-LoRA ja lisätään triggeri
|
| 87 |
+
lora_addition = {}
|
| 88 |
+
if selected_style != "None" and selected_style in lora_styles:
|
| 89 |
+
lora_path, lora_strength, lora_trigger = lora_styles[selected_style]
|
| 90 |
+
prompt = f"{lora_trigger}, {prompt}"
|
| 91 |
+
lora_addition[lora_path] = lora_strength
|
| 92 |
+
|
| 93 |
+
# Ladataan pysyvät + tyyli-LoRA yhteen
|
| 94 |
+
all_loras = {
|
| 95 |
+
"kkntr/lora1": 0.2,
|
| 96 |
+
"kkntr/lora2": 0.3,
|
| 97 |
+
"kkntr/lora12": 0.4,
|
| 98 |
+
"kkntr/lora10": 0.1,
|
| 99 |
+
}
|
| 100 |
+
all_loras.update(lora_addition)
|
| 101 |
+
|
| 102 |
+
pipe.load_lora_weights(all_loras)
|
| 103 |
+
pipe.fuse_lora()
|
| 104 |
|
| 105 |
quality_suffix = (
|
| 106 |
", (anthro), (male), (best quality), high resolution, (ultra detailed),"
|
|
|
|
| 124 |
|
| 125 |
return image, full_prompt
|
| 126 |
|
|
|
|
| 127 |
gr.Interface(
|
| 128 |
fn=generate,
|
| 129 |
inputs=[
|
| 130 |
+
gr.Textbox(label="Prompt", value="a wolf [kuvakulma], [tunnelma], [värit]"),
|
| 131 |
gr.Textbox(
|
| 132 |
label="Negative Prompt",
|
| 133 |
+
value="(worst quality), (low quality), (blurry), (bad anatomy), (fused fingers), (extra fingers), (missing fingers), (deformed), (jpeg artifacts), (watermark), (signature), text, error, out of frame, bad hands, bad feet, bad proportions, fused limbs, cropped, username, logo, bad perspective, lowres, overexposure, bad artist, bad composition, distorted, oversaturated, mutated, bad shadow, multiple limbs, extra arms, extra legs, bad background, tilted, bad lighting, bad face, ugly, bad eyes, disfigured, multiple pictures"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
),
|
| 135 |
gr.Slider(minimum=512, maximum=1024, step=64, value=768, label="Width"),
|
| 136 |
gr.Slider(minimum=512, maximum=1024, step=64, value=768, label="Height"),
|
| 137 |
+
gr.Checkbox(label="Random resolution mode (override sliders)", value=True),
|
| 138 |
+
gr.Dropdown(
|
| 139 |
+
choices=list(lora_styles.keys()),
|
| 140 |
+
value="None",
|
| 141 |
+
label="Select Style"
|
| 142 |
+
)
|
| 143 |
],
|
| 144 |
outputs=[
|
| 145 |
gr.Image(label="Generated Image"),
|
| 146 |
gr.Textbox(label="Used Prompt", lines=4)
|
| 147 |
],
|
| 148 |
+
title="FURRYSTYLE",
|
| 149 |
+
description="Give a prompt (you can use [kuvakulma], [tunnelma], [värit] for random scratchpad expansion)"
|
| 150 |
).launch()
|