Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,7 @@ function refresh() {
|
|
22 |
const url = new URL(window.location);
|
23 |
}
|
24 |
"""
|
|
|
25 |
def nms(x, t, s):
|
26 |
x = cv2.GaussianBlur(x.astype(np.float32), (0, 0), s)
|
27 |
|
@@ -63,56 +64,7 @@ if not torch.cuda.is_available():
|
|
63 |
DESCRIPTION += ""
|
64 |
|
65 |
style_list = [
|
66 |
-
|
67 |
-
"name": "(No style)",
|
68 |
-
"prompt": "{prompt}",
|
69 |
-
"negative_prompt": "longbody, lowres, bad anatomy, bad hands, missing fingers, extra digit, fewer digits, cropped, worst quality, low quality",
|
70 |
-
},
|
71 |
-
{
|
72 |
-
"name": "Cinematic",
|
73 |
-
"prompt": "cinematic still {prompt} . emotional, harmonious, vignette, highly detailed, high budget, bokeh, cinemascope, moody, epic, gorgeous, film grain, grainy",
|
74 |
-
"negative_prompt": "anime, cartoon, graphic, text, painting, crayon, graphite, abstract, glitch, deformed, mutated, ugly, disfigured",
|
75 |
-
},
|
76 |
-
{
|
77 |
-
"name": "3D Model",
|
78 |
-
"prompt": "professional 3d model {prompt} . octane render, highly detailed, volumetric, dramatic lighting",
|
79 |
-
"negative_prompt": "ugly, deformed, noisy, low poly, blurry, painting",
|
80 |
-
},
|
81 |
-
{
|
82 |
-
"name": "Anime",
|
83 |
-
"prompt": "anime artwork {prompt} . anime style, key visual, vibrant, studio anime, highly detailed",
|
84 |
-
"negative_prompt": "photo, deformed, black and white, realism, disfigured, low contrast",
|
85 |
-
},
|
86 |
-
{
|
87 |
-
"name": "Digital Art",
|
88 |
-
"prompt": "concept art {prompt} . digital artwork, illustrative, painterly, matte painting, highly detailed",
|
89 |
-
"negative_prompt": "photo, photorealistic, realism, ugly",
|
90 |
-
},
|
91 |
-
{
|
92 |
-
"name": "Photographic",
|
93 |
-
"prompt": "cinematic photo {prompt} . 35mm photograph, film, bokeh, professional, 4k, highly detailed",
|
94 |
-
"negative_prompt": "drawing, painting, crayon, sketch, graphite, impressionist, noisy, blurry, soft, deformed, ugly",
|
95 |
-
},
|
96 |
-
{
|
97 |
-
"name": "Pixel art",
|
98 |
-
"prompt": "pixel-art {prompt} . low-res, blocky, pixel art style, 8-bit graphics",
|
99 |
-
"negative_prompt": "sloppy, messy, blurry, noisy, highly detailed, ultra textured, photo, realistic",
|
100 |
-
},
|
101 |
-
{
|
102 |
-
"name": "Fantasy art",
|
103 |
-
"prompt": "ethereal fantasy concept art of {prompt} . magnificent, celestial, ethereal, painterly, epic, majestic, magical, fantasy art, cover art, dreamy",
|
104 |
-
"negative_prompt": "photographic, realistic, realism, 35mm film, dslr, cropped, frame, text, deformed, glitch, noise, noisy, off-center, deformed, cross-eyed, closed eyes, bad anatomy, ugly, disfigured, sloppy, duplicate, mutated, black and white",
|
105 |
-
},
|
106 |
-
{
|
107 |
-
"name": "Neonpunk",
|
108 |
-
"prompt": "neonpunk style {prompt} . cyberpunk, vaporwave, neon, vibes, vibrant, stunningly beautiful, crisp, detailed, sleek, ultramodern, magenta highlights, dark purple shadows, high contrast, cinematic, ultra detailed, intricate, professional",
|
109 |
-
"negative_prompt": "painting, drawing, illustration, glitch, deformed, mutated, cross-eyed, ugly, disfigured",
|
110 |
-
},
|
111 |
-
{
|
112 |
-
"name": "Manga",
|
113 |
-
"prompt": "manga style {prompt} . vibrant, high-energy, detailed, iconic, Japanese comic style",
|
114 |
-
"negative_prompt": "ugly, deformed, noisy, blurry, low contrast, realism, photorealistic, Western comic style",
|
115 |
-
},
|
116 |
]
|
117 |
|
118 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
@@ -153,35 +105,15 @@ pipe_stallion = StableDiffusionXLControlNetPipeline.from_pretrained(
|
|
153 |
ckpt_dir_stallion, controlnet=controlnet_stallion, vae=vae_stallion, torch_dtype=torch.float16, scheduler=eulera_scheduler
|
154 |
)
|
155 |
|
156 |
-
pipe_pony.to(device)
|
157 |
-
pipe_cyber.to(device)
|
158 |
-
pipe_stallion.to(device)
|
159 |
-
|
160 |
MAX_SEED = np.iinfo(np.int32).max
|
161 |
processor = HEDdetector.from_pretrained('lllyasviel/Annotators')
|
162 |
-
def nms(x, t, s):
|
163 |
-
x = cv2.GaussianBlur(x.astype(np.float32), (0, 0), s)
|
164 |
-
|
165 |
-
f1 = np.array([[0, 0, 0], [1, 1, 1], [0, 0, 0]], dtype=np.uint8)
|
166 |
-
f2 = np.array([[0, 1, 0], [0, 1, 0], [0, 1, 0]], dtype=np.uint8)
|
167 |
-
f3 = np.array([[1, 0, 0], [0, 1, 0], [0, 0, 1]], dtype=np.uint8)
|
168 |
-
f4 = np.array([[0, 0, 1], [0, 1, 0], [1, 0, 0]], dtype=np.uint8)
|
169 |
-
|
170 |
-
y = np.zeros_like(x)
|
171 |
-
|
172 |
-
for f in [f1, f2, f3, f4]:
|
173 |
-
np.putmask(y, cv2.dilate(x, kernel=f) == x, x)
|
174 |
-
|
175 |
-
z = np.zeros_like(y, dtype=np.uint8)
|
176 |
-
z[y > t] = 255
|
177 |
-
return z
|
178 |
|
179 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
180 |
if randomize_seed:
|
181 |
seed = random.randint(0, MAX_SEED)
|
182 |
return seed
|
183 |
|
184 |
-
@spaces.GPU
|
185 |
def run(
|
186 |
image: dict,
|
187 |
prompt: str,
|
@@ -239,6 +171,8 @@ def run(
|
|
239 |
else: # "Stallion Dreams Pony Realistic v1"
|
240 |
pipe = pipe_stallion
|
241 |
|
|
|
|
|
242 |
if use_canny:
|
243 |
out = pipe(
|
244 |
prompt=prompt,
|
@@ -264,6 +198,9 @@ def run(
|
|
264 |
height=new_height,
|
265 |
).images[0]
|
266 |
|
|
|
|
|
|
|
267 |
return (controlnet_img, out)
|
268 |
|
269 |
with gr.Blocks(css="style.css", js=js_func) as demo:
|
|
|
22 |
const url = new URL(window.location);
|
23 |
}
|
24 |
"""
|
25 |
+
|
26 |
def nms(x, t, s):
|
27 |
x = cv2.GaussianBlur(x.astype(np.float32), (0, 0), s)
|
28 |
|
|
|
64 |
DESCRIPTION += ""
|
65 |
|
66 |
style_list = [
|
67 |
+
# ... (style list remains the same)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
68 |
]
|
69 |
|
70 |
styles = {k["name"]: (k["prompt"], k["negative_prompt"]) for k in style_list}
|
|
|
105 |
ckpt_dir_stallion, controlnet=controlnet_stallion, vae=vae_stallion, torch_dtype=torch.float16, scheduler=eulera_scheduler
|
106 |
)
|
107 |
|
|
|
|
|
|
|
|
|
108 |
MAX_SEED = np.iinfo(np.int32).max
|
109 |
processor = HEDdetector.from_pretrained('lllyasviel/Annotators')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
|
111 |
def randomize_seed_fn(seed: int, randomize_seed: bool) -> int:
|
112 |
if randomize_seed:
|
113 |
seed = random.randint(0, MAX_SEED)
|
114 |
return seed
|
115 |
|
116 |
+
@spaces.GPU(duration=120)
|
117 |
def run(
|
118 |
image: dict,
|
119 |
prompt: str,
|
|
|
171 |
else: # "Stallion Dreams Pony Realistic v1"
|
172 |
pipe = pipe_stallion
|
173 |
|
174 |
+
pipe.to(device)
|
175 |
+
|
176 |
if use_canny:
|
177 |
out = pipe(
|
178 |
prompt=prompt,
|
|
|
198 |
height=new_height,
|
199 |
).images[0]
|
200 |
|
201 |
+
pipe.to("cpu")
|
202 |
+
torch.cuda.empty_cache()
|
203 |
+
|
204 |
return (controlnet_img, out)
|
205 |
|
206 |
with gr.Blocks(css="style.css", js=js_func) as demo:
|