Advertisement
kopyl

Untitled

Mar 23rd, 2023
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.98 KB | None | 0 0
  1. import torch
  2.  
  3. from PIL import Image
  4. from io import BytesIO
  5.  
  6. from diffusers import StableDiffusionImg2ImgPipeline
  7.  
  8. import os
  9.  
  10. device = "cuda"
  11. pipe = StableDiffusionImg2ImgPipeline.from_pretrained(
  12.     "logo-marks-6-1_5", torch_dtype=torch.float16, safety_checker=None
  13. ).to(device)
  14.  
  15.  
  16. def generate_image(user_id, seed, image_order, prompt=""):
  17.  
  18.     init_image = Image.open(
  19.         f"logo-marks-6-1_5/reference-images/{image_order}.png"
  20.     ).convert("RGB")
  21.     init_image.thumbnail((768, 768))
  22.  
  23.     folder_path = f"images/{user_id}"
  24.     os.makedirs(folder_path, exist_ok=True)
  25.  
  26.     generator = torch.Generator(device="cuda").manual_seed(seed)
  27.     images = pipe(
  28.         prompt=f"{prompt} logo mark in zvxsbj style",
  29.         image=init_image,
  30.         strength=0.95,
  31.         guidance_scale=30,
  32.         generator=generator,
  33.     ).images
  34.     images[0].save(f"images/{user_id}/{seed}-{image_order}.png")
  35.     print(f"Image with seed {seed} and image_order {image_order} saved")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement