patrickvonplaten commited on
Commit
6ed2376
1 Parent(s): ee24263
Files changed (2) hide show
  1. combined_pipe.py +71 -2
  2. control_net_canny.py +2 -0
combined_pipe.py CHANGED
@@ -1,4 +1,73 @@
1
  #!/usr/bin/env python3
2
- from diffusers import KandinskyV22CombinedPipeline
 
 
 
 
 
 
 
 
 
3
 
4
- pipe = KandinskyV22CombinedPipeline.from_pretrained("kandinsky-community/kandinsky-2-2-decoder")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  #!/usr/bin/env python3
2
+ from diffusers import AutoPipelineForText2Image, AutoPipelineForImage2Image, AutoPipelineForInpainting
3
+ from diffusers.utils import load_image
4
+ from pathlib import Path
5
+ import torch
6
+ import numpy as np
7
+ import requests
8
+ from io import BytesIO
9
+ from PIL import Image
10
+ from huggingface_hub import HfApi
11
+ import os
12
 
13
+ api = HfApi()
14
+
15
+ url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
16
+ response = requests.get(url)
17
+ original_image = Image.open(BytesIO(response.content)).convert("RGB")
18
+ original_image = original_image.resize((768, 512))
19
+
20
+ original_image = load_image(
21
+ "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main" "/kandinsky/cat.png"
22
+ )
23
+
24
+ mask = np.ones((768, 768), dtype=np.float32)
25
+ # Let's mask out an area above the cat's head
26
+ mask[:250, 250:-250] = 0
27
+
28
+ # pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
29
+ # pipe = AutoPipelineForImage2Image.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
30
+ pipe = AutoPipelineForInpainting.from_pretrained("kandinsky-community/kandinsky-2-1", torch_dtype=torch.float16)
31
+
32
+ # pipe = AutoPipelineForText2Image.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16)
33
+ # pipe = AutoPipelineForImage2Image.from_pretrained("kandinsky-community/kandinsky-2-2-decoder", torch_dtype=torch.float16)
34
+ # pipe = AutoPipelineForInpainting.from_pretrained("kandinsky-community/kandinsky-2-2-decoder-inpaint", torch_dtype=torch.float16)
35
+ pipe.enable_model_cpu_offload()
36
+
37
+ prompt = "A lion in galaxies, spirals, nebulae, stars, smoke, iridescent, intricate detail, octane render, 8k"
38
+ negative_prompt = ""
39
+
40
+ prompt = "A fantasy landscape, Cinematic lighting"
41
+ prompt = "a hat"
42
+ negative_prompt = "low quality, bad quality"
43
+
44
+ # rompts = ["a cat playing with a ball++ in the forest", "a cat playing with a ball++ in the forest", "a cat playing with a ball-- in the forest"]
45
+
46
+ # prompt_embeds = torch.cat([compel.build_conditioning_tensor(prompt) for prompt in prompts])
47
+
48
+ # generator = [torch.Generator(device="cuda").manual_seed(0) for _ in range(prompt_embeds.shape[0])]
49
+ #
50
+ # url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg"
51
+
52
+ # response = requests.get(url)
53
+ # image = Image.open(BytesIO(response.content)).convert("RGB")
54
+ # image.thumbnail((768, 768))
55
+
56
+
57
+ generator = torch.Generator(device="cpu").manual_seed(0)
58
+ # images = pipe(prompt=prompt, generator=generator, num_images_per_prompt=1, num_inference_steps=25).images
59
+ # images = pipe(prompt=prompt, image=original_image, generator=generator, num_images_per_prompt=1, num_inference_steps=25).images
60
+ images = pipe(prompt=prompt, image=original_image, mask_image=mask, generator=generator, num_images_per_prompt=1, num_inference_steps=25).images
61
+
62
+ for i, image in enumerate(images):
63
+ file_name = f"bb_1_{i}"
64
+ path = os.path.join(Path.home(), "images", f"{file_name}.png")
65
+ image.save(path)
66
+
67
+ api.upload_file(
68
+ path_or_fileobj=path,
69
+ path_in_repo=path.split("/")[-1],
70
+ repo_id="patrickvonplaten/images",
71
+ repo_type="dataset",
72
+ )
73
+ print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/{file_name}.png")
control_net_canny.py CHANGED
@@ -47,6 +47,8 @@ else:
47
  )
48
  size = 512
49
 
 
 
50
  # pipe.enable_model_cpu_offload()
51
  pipe.to("cuda")
52
 
 
47
  )
48
  size = 512
49
 
50
+ import ipdb; ipdb.set_trace()
51
+
52
  # pipe.enable_model_cpu_offload()
53
  pipe.to("cuda")
54