|
|
|
from diffusers import DiffusionPipeline, EulerDiscreteScheduler, StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler, DDIMScheduler, StableDiffusionXLImg2ImgPipeline |
|
import time |
|
import os |
|
from huggingface_hub import HfApi |
|
|
|
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 = StableDiffusionXLImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16) |
|
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config) |
|
|
|
|
|
|
|
|
|
|
|
|
|
pipe = pipe.to("cuda") |
|
|
|
prompt = "A red castle on a beautiful landscape with a nice sunset" |
|
|
|
|
|
|
|
|
|
|
|
url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" |
|
|
|
response = requests.get(url) |
|
init_image = Image.open(BytesIO(response.content)).convert("RGB").resize((1024, 1024)) |
|
|
|
image = pipe(prompt=prompt, image=init_image, strength=0.9).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") |
|
|