File size: 1,791 Bytes
69f6fc2
78ed83d
866074c
78ed83d
2f0087d
78ed83d
34be351
69f6fc2
 
b6badad
69f6fc2
78ed83d
69f6fc2
78ed83d
 
2f0087d
b6badad
78ed83d
866074c
34be351
 
 
 
69f6fc2
 
78ed83d
d4bb530
34be351
 
 
 
 
 
 
78ed83d
 
34be351
 
 
78ed83d
34be351
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#!/usr/bin/env python3
from diffusers import StableDiffusionPipeline, DPMSolverSinglestepScheduler, DPMSolverMultistepScheduler, DEISMultistepScheduler, HeunDiscreteScheduler
from diffusers.schedulers.scheduling_unipc_multistep import UniPCMultistepScheduler
import time
import os
from huggingface_hub import HfApi
from compel import Compel
import torch
import sys
from pathlib import Path

path = sys.argv[1]

api = HfApi()
start_time = time.time()
#pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16, device_map="auto")
#pipe.scheduler = HeunDiscreteScheduler.from_config(pipe.scheduler.config)
pipe = StableDiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
pipe.scheduler = UniPCMultistepScheduler.from_config(pipe.scheduler.config)

compel = Compel(tokenizer=pipe.tokenizer, text_encoder=pipe.text_encoder)


pipe = pipe.to("cuda")

prompt = "a highly realistic photo of green turtle"

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"]

prompt_embeds = torch.cat([compel.build_conditioning_tensor(prompt) for prompt in prompts])

generator = [torch.Generator(device="cuda").manual_seed(0) for _ in range(prompt_embeds.shape[0])]
images = pipe(prompt_embeds=prompt_embeds, generator=generator, num_inference_steps=15).images

print("Time", time.time() - start_time)

for i, image in enumerate(image):
    path = os.path.join(Path.home(), "images", f"aa_{i}.png")
    image.save(path)

    api.upload_file(
        path_or_fileobj=path,
        path_in_repo=path.split("/")[-1],
        repo_id="patrickvonplaten/images",
        repo_type="dataset",
    )
    print(f"https://huggingface.co./datasets/patrickvonplaten/images/blob/main/aa_{i}.png")