DEV Community

AnyISalIn
AnyISalIn

Posted on

3 2 2 2 2

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.

AWS Security LIVE!

Tune in for AWS Security LIVE!

Join AWS Security LIVE! for expert insights and actionable tips to protect your organization and keep security teams prepared.

Learn More

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs