DEV Community


Posted on

Replace any object in a photograph with Stable Diffusion Python SDK.

Stable diffusion API to replace any object

You can install the Novita Python SDK using just one command

pip install novita-client
Enter fullscreen mode Exit fullscreen mode


Finally, you can try the change cat to dog by following this code.

import os

from novita_client import NovitaClient, Txt2ImgRequest, UpscaleRequest
from novita_client.utils import base64_to_image, image_to_base64
from PIL import Image
from io import BytesIO

novita = NovitaClient(os.getenv('NOVITA_API_KEY'))

replace_object_res = novita.replace_object(image="*E3jkiGoC8EfVlqqhE_6SWw.png", object_prompt="a cat", prompt="a dog", response_image_type="png")
replace_object_generated = base64_to_image(replace_object_res.image_file)"replace-object.png")
Enter fullscreen mode Exit fullscreen mode

novita-client is the Python SDK of Novita.AI, which provides the following features.

Top comments (0)