Spaces:
Runtime error
Runtime error
Commit
Β·
9b567bb
0
Parent(s):
Duplicate from fffiloni/sd-img-variations
Browse filesCo-authored-by: Sylvain Filoni <[email protected]>
- .gitattributes +31 -0
- README.md +13 -0
- app.py +87 -0
- requirements.txt +5 -0
- unsafe.png +0 -0
.gitattributes
ADDED
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
23 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
26 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Stable Diffusion Img Variations CPU
|
3 |
+
emoji: ππ£π£π£π£
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: pink
|
6 |
+
sdk: gradio
|
7 |
+
sdk_version: 3.3.1
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: fffiloni/sd-img-variations
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,87 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from PIL import Image
|
4 |
+
|
5 |
+
from lambda_diffusers import StableDiffusionImageEmbedPipeline
|
6 |
+
|
7 |
+
def ask(input_im, scale, steps, seed, images):
|
8 |
+
images = images
|
9 |
+
generator = torch.Generator(device=device).manual_seed(int(seed))
|
10 |
+
|
11 |
+
images_list = pipe(
|
12 |
+
2*[input_im],
|
13 |
+
guidance_scale=scale,
|
14 |
+
num_inference_steps=steps,
|
15 |
+
generator=generator,
|
16 |
+
)
|
17 |
+
|
18 |
+
for i, image in enumerate(images_list["sample"]):
|
19 |
+
if(images_list["nsfw_content_detected"][i]):
|
20 |
+
safe_image = Image.open(r"unsafe.png")
|
21 |
+
images.append(safe_image)
|
22 |
+
else:
|
23 |
+
images.append(image)
|
24 |
+
return images
|
25 |
+
|
26 |
+
def main(input_im, n_pairs, scale, steps, seed):
|
27 |
+
print('Start the magic !')
|
28 |
+
images = []
|
29 |
+
for i in range(n_pairs):
|
30 |
+
print('Asking for a new pair of image [' + str(i + 1) + '/' + str(n_pairs) + ']')
|
31 |
+
seed = seed+i
|
32 |
+
images = ask(input_im, scale, steps, seed, images)
|
33 |
+
print('Thanks to Sylvain, it worked like a charm!')
|
34 |
+
return images
|
35 |
+
|
36 |
+
device = "cuda" if torch.cuda.is_available() else "cpu"
|
37 |
+
pipe = StableDiffusionImageEmbedPipeline.from_pretrained(
|
38 |
+
"lambdalabs/sd-image-variations-diffusers",
|
39 |
+
revision="273115e88df42350019ef4d628265b8c29ef4af5",
|
40 |
+
)
|
41 |
+
pipe = pipe.to(device)
|
42 |
+
|
43 |
+
inputs = [
|
44 |
+
gr.Image(),
|
45 |
+
gr.Slider(1, 3, value=2, step=1, label="Pairs of images to ask"),
|
46 |
+
gr.Slider(0, 25, value=3, step=1, label="Guidance scale"),
|
47 |
+
gr.Slider(5, 50, value=25, step=5, label="Steps"),
|
48 |
+
gr.Slider(label = "Seed", minimum = 0, maximum = 2147483647, step = 1, randomize = True)
|
49 |
+
]
|
50 |
+
output = gr.Gallery(label="Generated variations")
|
51 |
+
output.style(grid=2, height="")
|
52 |
+
|
53 |
+
description = \
|
54 |
+
"""
|
55 |
+
<p style='text-align: center;'>This demo is running on CPU. Working version fixed by Sylvain <a href='https://twitter.com/fffiloni' target='_blank'>@fffiloni</a>. You'll get n pairs of images variations. <br />
|
56 |
+
Asking for pairs of images instead of more than 2 images in a row helps us to avoid heavy CPU load and connection error out ;)<br />
|
57 |
+
Waiting time (for 2 pairs): ~5/10 minutes β’ NSFW filters enabled β’ <img id='visitor-badge' alt='visitor badge' src='https://visitor-badge.glitch.me/badge?page_id=gradio-blocks.sd-img-variations' style='display: inline-block' /><br />
|
58 |
+
Generate variations on an input image using a fine-tuned version of Stable Diffusion.<br />
|
59 |
+
Trained by <a href='https://www.justinpinkney.com' target='_blank'>Justin Pinkney</a> (<a href='https://twitter.com/Buntworthy' target='_blank'>@Buntworthy</a>) at <a href='https://lambdalabs.com/' target='_blank'>Lambda</a><br />
|
60 |
+
This version has been ported to π€ Diffusers library, see more details on how to use this version in the <a href='https://github.com/LambdaLabsML/lambda-diffusers' target='_blank'>Lambda Diffusers repo</a>.<br />
|
61 |
+
For the original training code see <a href='https://github.com/justinpinkney/stable-diffusion' target='_blank'>this repo</a>.
|
62 |
+
<img src='https://raw.githubusercontent.com/justinpinkney/stable-diffusion/main/assets/im-vars-thin.jpg' style='display: inline-block;' />
|
63 |
+
</p>
|
64 |
+
"""
|
65 |
+
|
66 |
+
article = \
|
67 |
+
"""
|
68 |
+
β
|
69 |
+
## How does this work?
|
70 |
+
The normal Stable Diffusion model is trained to be conditioned on text input. This version has had the original text encoder (from CLIP) removed, and replaced with
|
71 |
+
the CLIP _image_ encoder instead. So instead of generating images based a text input, images are generated to match CLIP's embedding of the image.
|
72 |
+
This creates images which have the same rough style and content, but different details, in particular the composition is generally quite different.
|
73 |
+
This is a totally different approach to the img2img script of the original Stable Diffusion and gives very different results.
|
74 |
+
The model was fine tuned on the [LAION aethetics v2 6+ dataset](https://laion.ai/blog/laion-aesthetics/) to accept the new conditioning.
|
75 |
+
Training was done on 4xA6000 GPUs on [Lambda GPU Cloud](https://lambdalabs.com/service/gpu-cloud).
|
76 |
+
More details on the method and training will come in a future blog post.
|
77 |
+
"""
|
78 |
+
|
79 |
+
demo = gr.Interface(
|
80 |
+
fn=main,
|
81 |
+
title="Stable Diffusion Image Variations",
|
82 |
+
inputs=inputs,
|
83 |
+
outputs=output,
|
84 |
+
description=description,
|
85 |
+
article=article
|
86 |
+
)
|
87 |
+
demo.launch()
|
requirements.txt
ADDED
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
torch
|
2 |
+
transformers
|
3 |
+
scipy
|
4 |
+
ftfy
|
5 |
+
git+https://github.com/LambdaLabsML/lambda-diffusers.git#egg=lambda-diffusers
|
unsafe.png
ADDED
![]() |