File size: 1,835 Bytes
2acb9f2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
819a296
 
2acb9f2
819a296
 
 
 
 
 
 
2acb9f2
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
52
53
#!/usr/bin/env python3
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler
import time
import os
from huggingface_hub import HfApi
# from compel import Compel
import torch
import sys
from pathlib import Path
import requests
from PIL import Image
from io import BytesIO

path = sys.argv[1]

api = HfApi()
start_time = time.time()
pipe = DiffusionPipeline.from_pretrained(path, torch_dtype=torch.float16)
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
# pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
# pipe = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None

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


pipe = pipe.to("cuda")

prompt = "Elon Musk riding a green horse on Mars"

# pipe.unet.to(memory_format=torch.channels_last)
# pipe.unet = torch.compile(pipe.unet, mode="reduce-overhead", fullgraph=True)
# pipe(prompt=prompt, num_inference_steps=2).images[0]

image = pipe(prompt=prompt, num_images_per_prompt=1, num_inference_steps=40, output_type="latent").images
pipe.to("cpu")

pipe = DiffusionPipeline.from_pretrained("/home/patrick/diffusers-sd-xl/stable-diffusion-xl-refiner-0.9", torch_dtype=torch.float16)
pipe.to("cuda")

image = pipe(prompt=prompt, image=image, strength=0.5).images[0]

file_name = f"aaa"
path = os.path.join(Path.home(), "images", f"{file_name}.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/{file_name}.png")