patrickvonplaten commited on
Commit
34be351
1 Parent(s): 58b66fd
Files changed (1) hide show
  1. run_local.py +22 -11
run_local.py CHANGED
@@ -4,6 +4,7 @@ from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepSchedu
4
  import time
5
  import os
6
  from huggingface_hub import HfApi
 
7
  import torch
8
  import sys
9
  from pathlib import Path
@@ -16,21 +17,31 @@ start_time = time.time()
16
  #pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config)
17
  pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
18
  pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
 
 
 
 
19
  pipe = pipe.to("cuda")
20
 
21
  prompt = "a highly realistic photo of green turtle"
22
 
23
- generator = torch.Generator(device="cuda").manual_seed(0)
24
- image = pipe(prompt, generator=generator, num_inference_steps=15).images[0]
 
 
 
 
 
25
  print("Time", time.time() - start_time)
26
 
27
- path = os.path.join(Path.home(), "images", "aa.png")
28
- image.save(path)
 
29
 
30
- api.upload_file(
31
- path_or_fileobj=path,
32
- path_in_repo=path.split("/")[-1],
33
- repo_id="patrickvonplaten/images",
34
- repo_type="dataset",
35
- )
36
- print("https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa.png")
 
4
  import time
5
  import os
6
  from huggingface_hub import HfApi
7
+ from compel import Compel
8
  import torch
9
  import sys
10
  from pathlib import Path
 
17
  #pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config)
18
  pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
19
  pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)
20
+
21
+ compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)
22
+
23
+
24
  pipe = pipe.to("cuda")
25
 
26
  prompt = "a highly realistic photo of green turtle"
27
 
28
+ prompts = ["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"]
29
+
30
+ prompt_embeds = torch.cat([compel.build_conditioning_tensor(prompt) for prompt in prompts])
31
+
32
+ generator = [torch.Generator(device="cuda").manual_seed(0) for _ in range(prompt_embeds.shape[0])]
33
+ images = pipe(prompt_embeds=prompt_embeds, generator=generator, num_inference_steps=15).images
34
+
35
  print("Time", time.time() - start_time)
36
 
37
+ for i, image in enumerate(image):
38
+ path = os.path.join(Path.home(), "images", f"aa_{i}.png")
39
+ image.save(path)
40
 
41
+ api.upload_file(
42
+ path_or_fileobj=path,
43
+ path_in_repo=path.split("/")[-1],
44
+ repo_id="patrickvonplaten/images",
45
+ repo_type="dataset",
46
+ )
47
+ print(f"https://huggingface.co/datasets/patrickvonplaten/images/blob/main/aa_{i}.png")