Spaces:
Running
on
Zero
Running
on
Zero
patrickvonplaten
commited on
Commit
•
886c072
1
Parent(s):
ba05f1b
first try
Browse files- README.md +3 -4
- app.py +47 -130
- requirements.txt +2 -7
README.md
CHANGED
@@ -1,14 +1,13 @@
|
|
1 |
---
|
2 |
title: Protogen Web-UI
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.15.0
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: mit
|
11 |
-
duplicated_from: darkstorm2150/protogen-web-ui
|
12 |
---
|
13 |
|
14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
1 |
---
|
2 |
title: Protogen Web-UI
|
3 |
+
emoji: ➕
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: black
|
6 |
sdk: gradio
|
7 |
sdk_version: 3.15.0
|
8 |
app_file: app.py
|
9 |
pinned: true
|
10 |
license: mit
|
|
|
11 |
---
|
12 |
|
13 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
@@ -1,7 +1,7 @@
|
|
1 |
from diffusers import (
|
2 |
StableDiffusionPipeline,
|
3 |
-
StableDiffusionImg2ImgPipeline,
|
4 |
DPMSolverMultistepScheduler,
|
|
|
5 |
)
|
6 |
import gradio as gr
|
7 |
import torch
|
@@ -17,6 +17,10 @@ current_steps = 25
|
|
17 |
|
18 |
SAFETY_CHECKER = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker", torch_dtype=torch.float16)
|
19 |
|
|
|
|
|
|
|
|
|
20 |
|
21 |
class Model:
|
22 |
def __init__(self, name, path=""):
|
@@ -30,21 +34,12 @@ class Model:
|
|
30 |
self.pipe_t2i.scheduler = DPMSolverMultistepScheduler.from_config(
|
31 |
self.pipe_t2i.scheduler.config
|
32 |
)
|
33 |
-
self.pipe_i2i = StableDiffusionImg2ImgPipeline(**self.pipe_t2i.components)
|
34 |
else:
|
35 |
self.pipe_t2i = None
|
36 |
-
self.pipe_i2i = None
|
37 |
|
38 |
|
39 |
models = [
|
40 |
-
Model("
|
41 |
-
Model("Protogen x3.4 (Photorealism)", "darkstorm2150/Protogen_x3.4_Official_Release"),
|
42 |
-
Model("Protogen x5.3 (Photorealism)", "darkstorm2150/Protogen_x5.3_Official_Release"),
|
43 |
-
Model("Protogen x5.8 Rebuilt (Scifi+Anime)", "darkstorm2150/Protogen_x5.8_Official_Release"),
|
44 |
-
Model("Protogen Dragon (RPG Model)", "darkstorm2150/Protogen_Dragon_Official_Release"),
|
45 |
-
Model("Protogen Nova", "darkstorm2150/Protogen_Nova_Official_Release"),
|
46 |
-
Model("Protogen Eclipse", "darkstorm2150/Protogen_Eclipse_Official_Release"),
|
47 |
-
Model("Protogen Infinity", "darkstorm2150/Protogen_Infinity_Official_Release"),
|
48 |
]
|
49 |
|
50 |
MODELS = {m.name: m for m in models}
|
@@ -66,12 +61,9 @@ def inference(
|
|
66 |
prompt,
|
67 |
guidance,
|
68 |
steps,
|
69 |
-
n_images=1,
|
70 |
width=512,
|
71 |
height=512,
|
72 |
seed=0,
|
73 |
-
img=None,
|
74 |
-
strength=0.5,
|
75 |
neg_prompt="",
|
76 |
):
|
77 |
|
@@ -83,55 +75,30 @@ def inference(
|
|
83 |
generator = torch.Generator("cuda").manual_seed(seed)
|
84 |
|
85 |
try:
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
width,
|
98 |
-
height,
|
99 |
-
generator,
|
100 |
-
seed,
|
101 |
-
),
|
102 |
-
f"Done. Seed: {seed}",
|
103 |
-
)
|
104 |
-
else:
|
105 |
-
return (
|
106 |
-
txt_to_img(
|
107 |
-
model_name,
|
108 |
-
prompt,
|
109 |
-
n_images,
|
110 |
-
neg_prompt,
|
111 |
-
guidance,
|
112 |
-
steps,
|
113 |
-
width,
|
114 |
-
height,
|
115 |
-
generator,
|
116 |
-
seed,
|
117 |
-
),
|
118 |
-
f"Done. Seed: {seed}",
|
119 |
-
)
|
120 |
except Exception as e:
|
121 |
-
return None, error_str(e)
|
122 |
|
123 |
|
124 |
def txt_to_img(
|
125 |
model_name,
|
126 |
prompt,
|
127 |
-
n_images,
|
128 |
neg_prompt,
|
129 |
guidance,
|
130 |
steps,
|
131 |
width,
|
132 |
height,
|
133 |
generator,
|
134 |
-
seed,
|
135 |
):
|
136 |
pipe = MODELS[model_name].pipe_t2i
|
137 |
|
@@ -139,61 +106,34 @@ def txt_to_img(
|
|
139 |
pipe = pipe.to("cuda")
|
140 |
pipe.enable_xformers_memory_efficient_attention()
|
141 |
|
142 |
-
|
143 |
prompt,
|
144 |
negative_prompt=neg_prompt,
|
145 |
-
num_images_per_prompt=n_images,
|
146 |
num_inference_steps=int(steps),
|
147 |
guidance_scale=guidance,
|
148 |
width=width,
|
149 |
height=height,
|
150 |
generator=generator,
|
151 |
-
|
152 |
-
|
153 |
-
pipe.to("cpu")
|
154 |
-
torch.cuda.empty_cache()
|
155 |
-
|
156 |
-
return replace_nsfw_images(result)
|
157 |
-
|
158 |
|
159 |
-
|
160 |
-
|
161 |
-
|
162 |
-
n_images,
|
163 |
-
neg_prompt,
|
164 |
-
img,
|
165 |
-
strength,
|
166 |
-
guidance,
|
167 |
-
steps,
|
168 |
-
width,
|
169 |
-
height,
|
170 |
-
generator,
|
171 |
-
seed,
|
172 |
-
):
|
173 |
-
pipe = MODELS[model_name].pipe_i2i
|
174 |
|
175 |
-
|
176 |
-
|
177 |
-
pipe.enable_xformers_memory_efficient_attention()
|
178 |
-
|
179 |
-
ratio = min(height / img.height, width / img.width)
|
180 |
-
img = img.resize((int(img.width * ratio), int(img.height * ratio)), Image.LANCZOS)
|
181 |
-
|
182 |
-
result = pipe(
|
183 |
-
prompt,
|
184 |
negative_prompt=neg_prompt,
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
-
strength=strength,
|
189 |
-
guidance_scale=guidance,
|
190 |
generator=generator,
|
191 |
-
)
|
192 |
|
193 |
pipe.to("cpu")
|
194 |
torch.cuda.empty_cache()
|
195 |
|
196 |
-
return
|
197 |
|
198 |
|
199 |
def replace_nsfw_images(results):
|
@@ -252,8 +192,12 @@ with gr.Blocks(css="style.css") as demo:
|
|
252 |
)
|
253 |
|
254 |
# image_out = gr.Image(height=512)
|
255 |
-
|
256 |
-
label="
|
|
|
|
|
|
|
|
|
257 |
).style(grid=[2], height="auto")
|
258 |
|
259 |
state_info = gr.Textbox(label="State", show_label=False, max_lines=2).style(
|
@@ -269,10 +213,6 @@ with gr.Blocks(css="style.css") as demo:
|
|
269 |
placeholder="What to exclude from the image",
|
270 |
)
|
271 |
|
272 |
-
n_images = gr.Slider(
|
273 |
-
label="Images", value=1, minimum=1, maximum=4, step=1
|
274 |
-
)
|
275 |
-
|
276 |
with gr.Row():
|
277 |
guidance = gr.Slider(
|
278 |
label="Guidance scale", value=7.5, maximum=15
|
@@ -297,52 +237,29 @@ with gr.Blocks(css="style.css") as demo:
|
|
297 |
0, 2147483647, label="Seed (0 = random)", value=0, step=1
|
298 |
)
|
299 |
|
300 |
-
with gr.Tab("Image to image"):
|
301 |
-
with gr.Group():
|
302 |
-
image = gr.Image(
|
303 |
-
label="Image", height=256, tool="editor", type="pil"
|
304 |
-
)
|
305 |
-
strength = gr.Slider(
|
306 |
-
label="Transformation strength",
|
307 |
-
minimum=0,
|
308 |
-
maximum=1,
|
309 |
-
step=0.01,
|
310 |
-
value=0.5,
|
311 |
-
)
|
312 |
-
|
313 |
inputs = [
|
314 |
model_name,
|
315 |
prompt,
|
316 |
guidance,
|
317 |
steps,
|
318 |
-
n_images,
|
319 |
width,
|
320 |
height,
|
321 |
seed,
|
322 |
-
image,
|
323 |
-
strength,
|
324 |
neg_prompt,
|
325 |
]
|
326 |
-
outputs = [
|
327 |
prompt.submit(inference, inputs=inputs, outputs=outputs)
|
328 |
generate.click(inference, inputs=inputs, outputs=outputs)
|
329 |
|
330 |
-
ex = gr.Examples(
|
331 |
-
[
|
332 |
-
[models[0].name, "portrait of a beautiful alyx vance half life", 10, 50, "canvas frame, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), weird colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy"],
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
[models[7].name, "(extremely detailed CG unity 8k wallpaper), full body portrait of (david:1.1), staring at us with a mysterious gaze, realistic, masterpiece, highest quality, ((scifi)), lens flare, ((light sparkles)), unreal engine, digital painting, trending on ArtStation, trending on CGSociety, Intricate, High Detail, dramatic, realism, beautiful and detailed lighting, shadows", 7.5, 50, "canvas frame, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), weird colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy"],
|
340 |
-
],
|
341 |
-
inputs=[model_name, prompt, guidance, steps, neg_prompt],
|
342 |
-
outputs=outputs,
|
343 |
-
fn=inference,
|
344 |
-
cache_examples=False,
|
345 |
-
)
|
346 |
|
347 |
gr.HTML(
|
348 |
"""
|
|
|
1 |
from diffusers import (
|
2 |
StableDiffusionPipeline,
|
|
|
3 |
DPMSolverMultistepScheduler,
|
4 |
+
DiffusionPipeline,
|
5 |
)
|
6 |
import gradio as gr
|
7 |
import torch
|
|
|
17 |
|
18 |
SAFETY_CHECKER = StableDiffusionSafetyChecker.from_pretrained("CompVis/stable-diffusion-safety-checker", torch_dtype=torch.float16)
|
19 |
|
20 |
+
UPSCALER = DiffusionPipeline.from_pretrained("stabilityai/sd-x2-latent-upscaler", torch_dtype=torch.float16)
|
21 |
+
UPSCALER.to("cuda")
|
22 |
+
UPSCALER.enable_xformers_memory_efficient_attention()
|
23 |
+
|
24 |
|
25 |
class Model:
|
26 |
def __init__(self, name, path=""):
|
|
|
34 |
self.pipe_t2i.scheduler = DPMSolverMultistepScheduler.from_config(
|
35 |
self.pipe_t2i.scheduler.config
|
36 |
)
|
|
|
37 |
else:
|
38 |
self.pipe_t2i = None
|
|
|
39 |
|
40 |
|
41 |
models = [
|
42 |
+
Model("Stable Diffusion v1-4", "CompVis/stable-diffusion-v1-4"),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
]
|
44 |
|
45 |
MODELS = {m.name: m for m in models}
|
|
|
61 |
prompt,
|
62 |
guidance,
|
63 |
steps,
|
|
|
64 |
width=512,
|
65 |
height=512,
|
66 |
seed=0,
|
|
|
|
|
67 |
neg_prompt="",
|
68 |
):
|
69 |
|
|
|
75 |
generator = torch.Generator("cuda").manual_seed(seed)
|
76 |
|
77 |
try:
|
78 |
+
low_res_image, up_res_image = txt_to_img(
|
79 |
+
model_name,
|
80 |
+
prompt,
|
81 |
+
neg_prompt,
|
82 |
+
guidance,
|
83 |
+
steps,
|
84 |
+
width,
|
85 |
+
height,
|
86 |
+
generator,
|
87 |
+
)
|
88 |
+
return low_res_image, up_res_image, f"Done. Seed: {seed}",
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
89 |
except Exception as e:
|
90 |
+
return None, None, error_str(e)
|
91 |
|
92 |
|
93 |
def txt_to_img(
|
94 |
model_name,
|
95 |
prompt,
|
|
|
96 |
neg_prompt,
|
97 |
guidance,
|
98 |
steps,
|
99 |
width,
|
100 |
height,
|
101 |
generator,
|
|
|
102 |
):
|
103 |
pipe = MODELS[model_name].pipe_t2i
|
104 |
|
|
|
106 |
pipe = pipe.to("cuda")
|
107 |
pipe.enable_xformers_memory_efficient_attention()
|
108 |
|
109 |
+
low_res_latents = pipe(
|
110 |
prompt,
|
111 |
negative_prompt=neg_prompt,
|
|
|
112 |
num_inference_steps=int(steps),
|
113 |
guidance_scale=guidance,
|
114 |
width=width,
|
115 |
height=height,
|
116 |
generator=generator,
|
117 |
+
output_type="latent",
|
118 |
+
).images
|
|
|
|
|
|
|
|
|
|
|
119 |
|
120 |
+
with torch.no_grad():
|
121 |
+
low_res_image = pipe.decode_latents(low_res_latents)
|
122 |
+
low_res_image = pipe.numpy_to_pil(low_res_image)[0]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
123 |
|
124 |
+
up_res_image = UPSCALER(
|
125 |
+
prompt=prompt,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
negative_prompt=neg_prompt,
|
127 |
+
image=low_res_latents,
|
128 |
+
num_inference_steps=20,
|
129 |
+
guidance_scale=0,
|
|
|
|
|
130 |
generator=generator,
|
131 |
+
).images[0]
|
132 |
|
133 |
pipe.to("cpu")
|
134 |
torch.cuda.empty_cache()
|
135 |
|
136 |
+
return low_res_image, up_res_image
|
137 |
|
138 |
|
139 |
def replace_nsfw_images(results):
|
|
|
192 |
)
|
193 |
|
194 |
# image_out = gr.Image(height=512)
|
195 |
+
low_res_image = gr.Gallery(
|
196 |
+
label="512-pix image", show_label=False, elem_id="gallery"
|
197 |
+
).style(grid=[2], height="auto")
|
198 |
+
|
199 |
+
up_res_image = gr.Gallery(
|
200 |
+
label="1024-pix image", show_label=False, elem_id="gallery"
|
201 |
).style(grid=[2], height="auto")
|
202 |
|
203 |
state_info = gr.Textbox(label="State", show_label=False, max_lines=2).style(
|
|
|
213 |
placeholder="What to exclude from the image",
|
214 |
)
|
215 |
|
|
|
|
|
|
|
|
|
216 |
with gr.Row():
|
217 |
guidance = gr.Slider(
|
218 |
label="Guidance scale", value=7.5, maximum=15
|
|
|
237 |
0, 2147483647, label="Seed (0 = random)", value=0, step=1
|
238 |
)
|
239 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
240 |
inputs = [
|
241 |
model_name,
|
242 |
prompt,
|
243 |
guidance,
|
244 |
steps,
|
|
|
245 |
width,
|
246 |
height,
|
247 |
seed,
|
|
|
|
|
248 |
neg_prompt,
|
249 |
]
|
250 |
+
outputs = [low_res_image, up_res_image, error_output]
|
251 |
prompt.submit(inference, inputs=inputs, outputs=outputs)
|
252 |
generate.click(inference, inputs=inputs, outputs=outputs)
|
253 |
|
254 |
+
# ex = gr.Examples(
|
255 |
+
# [
|
256 |
+
# [models[0].name, "portrait of a beautiful alyx vance half life", 10, 50, "canvas frame, ((disfigured)), ((bad art)), ((deformed)),((extra limbs)),((close up)),((b&w)), weird colors, blurry, (((duplicate))), ((morbid)), ((mutilated)), [out of frame], extra fingers, mutated hands, ((poorly drawn hands)), ((poorly drawn face)), (((mutation))), (((deformed))), blurry, ((bad anatomy)), (((bad proportions))), ((extra limbs)), cloned face, (((disfigured))), out of frame, ugly, extra limbs, (bad anatomy), gross proportions, (malformed limbs), ((missing arms)), ((missing legs)), (((extra arms))), (((extra legs))), mutated hands, (fused fingers), (too many fingers), (((long neck))), Photoshop, video game, ugly, tiling, poorly drawn hands, poorly drawn feet, poorly drawn face, out of frame, mutation, mutated, extra limbs, extra legs, extra arms, disfigured, deformed, cross-eye, body out of frame, blurry, bad art, bad anatomy"],
|
257 |
+
# ],
|
258 |
+
# inputs=[model_name, prompt, guidance, steps, neg_prompt],
|
259 |
+
# outputs=outputs,
|
260 |
+
# fn=inference,
|
261 |
+
# cache_examples=False,
|
262 |
+
# )
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
263 |
|
264 |
gr.HTML(
|
265 |
"""
|
requirements.txt
CHANGED
@@ -1,16 +1,11 @@
|
|
1 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
torch
|
3 |
torchvision==0.13.1+cu113
|
4 |
-
#diffusers
|
5 |
git+https://github.com/huggingface/diffusers.git
|
6 |
-
#transformers
|
7 |
git+https://github.com/huggingface/transformers
|
8 |
scipy
|
9 |
ftfy
|
10 |
psutil
|
11 |
-
accelerate
|
12 |
-
#OmegaConf
|
13 |
-
#pytorch_lightning
|
14 |
triton==2.0.0.dev20220701
|
15 |
-
|
16 |
-
https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.15/xformers-0.0.15.dev0+4c06c79.d20221205-cp38-cp38-linux_x86_64.whl
|
|
|
1 |
--extra-index-url https://download.pytorch.org/whl/cu113
|
2 |
torch
|
3 |
torchvision==0.13.1+cu113
|
|
|
4 |
git+https://github.com/huggingface/diffusers.git
|
|
|
5 |
git+https://github.com/huggingface/transformers
|
6 |
scipy
|
7 |
ftfy
|
8 |
psutil
|
9 |
+
accelerate
|
|
|
|
|
10 |
triton==2.0.0.dev20220701
|
11 |
+
https://github.com/camenduru/stable-diffusion-webui-colab/releases/download/0.0.15/xformers-0.0.15.dev0+4c06c79.d20221205-cp38-cp38-linux_x86_64.whl
|
|