tools / run_local_fuse_xl.py
patrickvonplaten's picture
fix more tests
811d1c6
raw
history blame
1.11 kB
#!/usr/bin/env python3
from huggingface_hub import HfApi
import torch
from pathlib import Path
import os
import time
api = HfApi()
start_time = time.time()
from diffusers import DiffusionPipeline
import torch
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16)
pipe.load_lora_weights("stabilityai/stable-diffusion-xl-base-1.0", weight_name="sd_xl_offset_example-lora_1.0.safetensors")
pipe.unet.fuse_lora()
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", "ediffi_sdxl", 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")