Update README.md
Browse files
README.md
CHANGED
@@ -17,18 +17,42 @@ please have a look at the [Stable Diffusion](https://huggingface.co/docs/diffuse
|
|
17 |
|
18 |
You can also export the model to [ONNX](https://huggingface.co/docs/diffusers/optimization/onnx), [MPS](https://huggingface.co/docs/diffusers/optimization/mps) and/or [FLAX/JAX]().
|
19 |
|
|
|
|
|
|
|
|
|
20 |
```python
|
21 |
from diffusers import StableDiffusionPipeline
|
22 |
import torch
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
model_id = "CHAITron/KranokThaiV1"
|
25 |
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
26 |
pipe = pipe.to("cuda")
|
27 |
|
28 |
prompt = "a colourful masterpiece thai dog in <knt-style> style, high-quality, professional art, realistic, thai style"
|
29 |
-
image = pipe(prompt).images[0]
|
30 |
|
31 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
```
|
33 |
|
34 |
## License
|
|
|
17 |
|
18 |
You can also export the model to [ONNX](https://huggingface.co/docs/diffusers/optimization/onnx), [MPS](https://huggingface.co/docs/diffusers/optimization/mps) and/or [FLAX/JAX]().
|
19 |
|
20 |
+
```shell
|
21 |
+
pip install torch diffusers accelerate pillow
|
22 |
+
```
|
23 |
+
|
24 |
```python
|
25 |
from diffusers import StableDiffusionPipeline
|
26 |
import torch
|
27 |
+
from PIL import Image
|
28 |
+
|
29 |
+
def image_grid(imgs, rows, cols):
|
30 |
+
assert len(imgs) == rows*cols
|
31 |
+
|
32 |
+
w, h = imgs[0].size
|
33 |
+
grid = Image.new('RGB', size=(cols*w, rows*h))
|
34 |
+
grid_w, grid_h = grid.size
|
35 |
+
|
36 |
+
for i, img in enumerate(imgs):
|
37 |
+
grid.paste(img, box=(i%cols*w, i//cols*h))
|
38 |
+
return grid
|
39 |
|
40 |
model_id = "CHAITron/KranokThaiV1"
|
41 |
pipe = StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.float16)
|
42 |
pipe = pipe.to("cuda")
|
43 |
|
44 |
prompt = "a colourful masterpiece thai dog in <knt-style> style, high-quality, professional art, realistic, thai style"
|
|
|
45 |
|
46 |
+
num_samples = 4
|
47 |
+
num_rows = 1
|
48 |
+
|
49 |
+
all_images = []
|
50 |
+
for _ in range(num_rows):
|
51 |
+
images = pipe(prompt, num_images_per_prompt=num_samples, num_inference_steps=25, guidance_scale=9).images
|
52 |
+
all_images.extend(images)
|
53 |
+
|
54 |
+
grid = image_grid(all_images, num_rows, num_samples)
|
55 |
+
grid
|
56 |
```
|
57 |
|
58 |
## License
|