| | |
| | from diffusers import StableDiffusionPipeline, KDPM2DiscreteScheduler, StableDiffusionImg2ImgPipeline, HeunDiscreteScheduler, KDPM2AncestralDiscreteScheduler |
| | 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 = StableDiffusionImg2ImgPipeline.from_pretrained(path, torch_dtype=torch.float16, safety_checker=None) |
| | pipe.scheduler = KDPM2AncestralDiscreteScheduler.from_config(pipe.scheduler.config) |
| |
|
| | |
| |
|
| |
|
| | pipe = pipe.to("cuda") |
| |
|
| | prompt = "ghibli style, a fantasy landscape with castles" |
| |
|
| | |
| |
|
| | |
| |
|
| | |
| | |
| | url = "https://raw.githubusercontent.com/CompVis/stable-diffusion/main/assets/stable-samples/img2img/sketch-mountains-input.jpg" |
| |
|
| | response = requests.get(url) |
| | image = Image.open(BytesIO(response.content)).convert("RGB") |
| | image.thumbnail((768, 768)) |
| |
|
| | generator = torch.Generator(device="cpu").manual_seed(0) |
| | images = pipe(prompt=prompt, image=image, generator=generator, strength=0.75, num_inference_steps=30).images |
| |
|
| | print("Time", time.time() - start_time) |
| |
|
| | for i, image in enumerate(images): |
| | path = os.path.join(Path.home(), "images", f"aa_{i}.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/aa_{i}.png") |
| |
|