art image2image inpaintig text-to-image en region:us
---
language:
- en
pipeline_tag: text-to-image
tags:
- art
- image2image
- inpaintig
---

USAGE URPM Inpainting Model (CUDA/CPU)

Tested on `CPU` (slow) and `GPU` (Nvidia Tesla T4) ~ 8 sec depends on the number of steps and strength

```python
#pip install torch Pillow diffusers transformers requests

import torch
import PIL
from diffusers import StableDiffusionInpaintPipeline
import os, requests

#Model name and path settings
path_to_model = "my_models/"
model_name="urpm.safetensors"

#Download model if not exists (you have to create a folder path_to_model )
if not os.path.exists(f"{path_to_model}{model_name}"):
    print("Downloading model...")
    file = requests.get("https://huggingface.co/goldpulpy/UberRealisticPornMergeUrpmV13Inpainting/resolve/main/UberRealisticPornMergeUrpmV13Inpainting.safetensors").content
    open(f"{path_to_model}{model_name}", "wb").write(file)

#Choose available divice (cpu or cuda)
if torch.cuda.is_available():
    device = torch.device("cuda")
    print("Cuda (GPU support) is available and enabled!")
else:
    device = torch.device("cpu")
    print("Cuda (GPU support) is not available :(")

#Promt (you can edit promt and negative promt for generation)
prompt = "8k, RAW photo, highest quality, masterpiece, High detail, RAW color photo, professional close-up photo, (realistic, photo realism:1. 37), (highest quality), (best shadow),nude ,(naked:1.2), blonde, spreading pussy, (spreading thigh:1.4), butterfly legs, photorealistic,"
negative_prompt="easynegative, muscular, (suntan:2), (sleeves:2), (tattoo:2), (sunglasses:2), (inverted nipples), (mutated:2), (worst quality:2), (low quality:2), (normal quality:2), lowres, blurry, ((nasolabial folds):1.2), 3d, anime, cartoon, cg, comic, drawing, bad detailed background, cropped, grayscale, jpeg artifacts, monochrome, non-linear background, out of frame, paintings, poorly drawn, semi-realistic, sepia, sketches, unclear architectural outline, asymmetric eyes, bad anatomy, cloned, crooked teeth, deformed, dehydrated, disfigured, double nipples, duplicate, extra arms, extra fingers, extra legs, extra limbs, long fingers, long neck, malformed limbs, missing arms, missing legs, missing teeth, more than five fingers on one hand:1.5, more than two arm per body:1.5, more than two leg per body:1.5, mutated, mutation, mutilated, odd eyes, ugly, (artist name:2), (logo:2), (text:2), (watermark:2), acnes, age spot, dark spots, fat, fused, giantess, glans, mole, obesity, skin blemishes, skin spots, animal ears, elf-ears, earrings, childish, morbid"

#Hyperparameters
generator = torch.Generator(device).manual_seed(0) #You can edit seed

#Load model from file *.safetensors
model = StableDiffusionInpaintPipeline.from_single_file(
  f"{path_to_model}{model_name}",
  use_safetensors=True,
  torch_dtype=torch.float16,
  ).to(device)

#Disable block content
model.safety_checker = None
model.requires_safety_checker = False

#Predict func.
def predict(image, mask_image, strength=1, steps=100):

  result = model(
      prompt=prompt, #Promt
      negative_prompt=negative_prompt,#Negative prompt
      strength=strength, #Strength (0.1 - 1)
      num_inference_steps=steps, #Generation steps
      image=image, #PIL Image obj
      mask_image=mask_image, #PIL Image obj
      generator=generator, #Generator
      num_images_per_prompt=1, #Image per predict
  ).images

  return result

#Open image, pre-processing and other operations, must get image, mask : PIL Image Obj
image = ... #PIL Image 512x512
mask = ... #PIL black and white mask image 512x512

#Forward and getting results
image = predict(image,mask)[0] #result <- [array num_images_per_prompt](take the first image index: 0)

image #PIL Image Obj with the result of model generation

```

Based on this code you can create a `class` for convenience

