tools / run_local.py
patrickvonplaten's picture
correct vocab
ae23482
raw
history blame
1.82 kB
#!/usr/bin/env python3
from diffusers import StableDiffusionPipeline, DDIMScheduler
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
begin = ["a picture of <rickmann>", "a photo of <rickmann>", "The <rickmann>", "an image of <rickmann>"]
mid = ["", " on a bike", " with sunglasses", " at the beach", " in front of a mountain", " in the water", " on a boat", " at a fashion show", " as a superstar model", " while it snows", " in a forest", " with a nice landscape"]
end = ["", " , disco light style", ", minecraft style", " , picasso style", " as a lego person", ""]
api = HfApi()
start_time = time.time()
path = "patrickvonplaten/papa_out_5"
pipe = StableDiffusionPipeline.from_pretrained(path, safety_checker=None, torch_dtype=torch.float16)
pipe.scheduler = DDIMScheduler.from_config(pipe.scheduler.config)
pipe = pipe.to("cuda")
counter = 0
for b in begin:
for m in mid:
for e in end:
prompt = b + mid + e + ", highly realistic, super resolution, high quality photography, beautiful"
images = pipe(prompt=prompt, num_images_per_prompt=2, eta=1.0, negative_prompt="ugly, bad quality, deformed", num_inference_steps=50).images
for i, image in enumerate(images):
path = os.path.join(Path.home(), "papa", f"{counter}.png")
image.save(path)
api.upload_file(
path_or_fileobj=path,
path_in_repo=path.split("/")[-1],
repo_id="patrickvonplaten/papa",
repo_type="dataset",
)
print(f"https://huggingface.co/datasets/patrickvonplaten/papa/blob/main/{counter}.png")
counter += 1