|
|
|
from diffusers import DiffusionPipeline |
|
from huggingface_hub import HfApi |
|
import os |
|
from pathlib import Path |
|
from compel import Compel |
|
import torch |
|
|
|
api = HfApi() |
|
|
|
pipeline = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-0.9", variant="fp16", use_safetensors=True, torch_dtype=torch.float16).to("cuda") |
|
compel = Compel(tokenizer=[pipeline.tokenizer, pipeline.tokenizer_2] , text_encoder=[pipeline.text_encoder, pipeline.text_encoder_2], use_penultimate_clip_layer=True, use_penultimate_layer_norm=False, requires_pooled=[False, True]) |
|
|
|
|
|
prompt = "a cat playing with a ball-- in the forest" |
|
conditioning, pooled = compel(prompt) |
|
|
|
|
|
image = pipeline(prompt_embeds=conditioning, pooled_prompt_embeds=pooled, num_inference_steps=30).images[0] |
|
|
|
file_name = f"ball_minus_minus" |
|
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") |
|
|