|
|
|
from diffusers import DiffusionPipeline |
|
import torch |
|
from pathlib import Path |
|
from huggingface_hub import HfApi |
|
import os |
|
|
|
api = HfApi() |
|
|
|
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16) |
|
pipe.load_lora_weights("./sd_xl_offset_example-lora_1.0.safetensors") |
|
pipe.to(torch_dtype=torch.float16) |
|
pipe.to("cuda") |
|
|
|
torch.manual_seed(0) |
|
|
|
prompt = "beautiful scenery nature glass bottle landscape, , purple galaxy bottle" |
|
negative_prompt = "text, watermark" |
|
|
|
image = pipe(prompt, negative_prompt=negative_prompt, num_inference_steps=25).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") |
|
|