DEV Community

AnyISalIn
AnyISalIn

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

get NOVITA_API_KEY from https://novita.ai/get-started/

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="https://cdn-images-1.medium.com/max/1600/1*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_generated.save("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)