YiYiXu commited on
Commit
a368d32
1 Parent(s): 73bf6fb

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +15 -36
README.md CHANGED
@@ -25,21 +25,16 @@ pip install diffusers transformers accelerate
25
  ### Text to image
26
 
27
  ```python
28
- from diffusers import DiffusionPipeline
29
  import torch
30
 
31
- pipe_prior = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16)
32
- pipe_prior.to("cuda")
33
-
34
- t2i_pipe = DiffusionPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
35
- t2i_pipe.to("cuda")
36
 
37
  prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting"
38
  negative_prompt = "low quality, bad quality"
39
 
40
- image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt, guidance_scale=1.0).to_tuple()
41
-
42
- image = t2i_pipe(prompt, negative_prompt=negative_prompt, image_embeds=image_embeds, negative_image_embeds=negative_image_embeds, height=768, width=768).images[0]
43
  image.save("cheeseburger_monster.png")
44
  ```
45
 
@@ -49,43 +44,27 @@ image.save("cheeseburger_monster.png")
49
  ### Text Guided Image-to-Image Generation
50
 
51
  ```python
52
- from diffusers import KandinskyImg2ImgPipeline, KandinskyPriorPipeline
53
  import torch
54
-
55
- from PIL import Image
56
  import requests
57
  from io import BytesIO
 
 
58
 
59
- url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
60
- response = requests.get(url)
61
- original_image = Image.open(BytesIO(response.content)).convert("RGB")
62
- original_image = original_image.resize((768, 512))
63
-
64
- # create prior
65
- pipe_prior = KandinskyPriorPipeline.from_pretrained(
66
- "kandinsky-community/kandinsky-2-1-prior", torch_dtype=torch.float16
67
- )
68
- pipe_prior.to("cuda")
69
 
70
- # create img2img pipeline
71
- pipe = KandinskyImg2ImgPipeline.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
72
- pipe.to("cuda")
73
 
74
  prompt = "A fantasy landscape, Cinematic lighting"
75
  negative_prompt = "low quality, bad quality"
76
 
77
- image_embeds, negative_image_embeds = pipe_prior(prompt, negative_prompt).to_tuple()
78
-
79
- out = pipe(
80
- prompt,
81
- image=original_image,
82
- image_embeds=image_embeds,
83
- negative_image_embeds=negative_image_embeds,
84
- height=768,
85
- width=768,
86
- strength=0.3,
87
- )
88
 
 
89
  out.images[0].save("fantasy_land.png")
90
  ```
91
 
 
25
  ### Text to image
26
 
27
  ```python
28
+ from diffusers import AutoPipelineForText2Image
29
  import torch
30
 
31
+ pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
32
+ pipe.enable_model_cpu_offload()
 
 
 
33
 
34
  prompt = "A alien cheeseburger creature eating itself, claymation, cinematic, moody lighting"
35
  negative_prompt = "low quality, bad quality"
36
 
37
+ image = pipe(prompt=prompt, negative_prompt=negative_prompt, prior_guidance_scale =1.0, height=768, width=768).images[0]
 
 
38
  image.save("cheeseburger_monster.png")
39
  ```
40
 
 
44
  ### Text Guided Image-to-Image Generation
45
 
46
  ```python
47
+ from diffusers import AutoPipelineForImage2Image
48
  import torch
 
 
49
  import requests
50
  from io import BytesIO
51
+ from PIL import Image
52
+ import os
53
 
54
+ pipe = AutoPipelineForImage2Image.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
 
 
 
 
 
 
 
 
 
55
 
56
+ pipe.enable_model_cpu_offload()
 
 
57
 
58
  prompt = "A fantasy landscape, Cinematic lighting"
59
  negative_prompt = "low quality, bad quality"
60
 
61
+ url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
62
+
63
+ response = requests.get(url)
64
+ original_image = Image.open(BytesIO(response.content)).convert("RGB")
65
+ original_image.thumbnail((768, 768))
 
 
 
 
 
 
66
 
67
+ image = pipe(prompt=prompt, image=original_image, strength=0.3).images[0]
68
  out.images[0].save("fantasy_land.png")
69
  ```
70