Package: novita-client
novita Python SDKthis SDK is based on the officialAPI documentationjoin our discord server for helpNew APIslatent-consistency-txt2img- latent consistency txt2imgbased on this papercleanup- remove all your generated imagesremove-background- remove background from imageremove-text- remove text from imagereimagine- reimagine imagedoodle- doodle imagemerge-face- merge facemix-pose- mix poseoutpainting- outpaintingreplace-object- remove objectreplace-background- replace backgroundreplace-sky- replace skycreate-tile- create tileInstallationpipinstallnovita-clientQuick StartGet api key refer tohttps://novita.ai/get-started/importosfromnovita_clientimportNovitaClient,Txt2ImgRequest,Samplers,ModelType,save_imageclient=NovitaClient(os.getenv('NOVITA_API_KEY'),os.getenv('NOVITA_API_URI',None))req=Txt2ImgRequest(model_name='sd_xl_base_1.0.safetensors',prompt='a dog flying in the sky',batch_size=1,cfg_scale=7.5,height=1024,width=1024,sampler_name=Samplers.EULER_A,)save_image(client.sync_txt2img(req).data.imgs_bytes[0],'output.png')Examplestxt2img_with_lora.py#!/usr/bin/env python# -*- coding: UTF-8 -*-importosfromnovita_clientimportNovitaClient,Txt2ImgRequest,Samplers,ProgressResponseStatusCode,ModelType,add_lora_to_prompt,save_imageclient=NovitaClient(os.getenv('NOVITA_API_KEY'),os.getenv('NOVITA_API_URI',None))models=client.models()# Anything V5/Ink, https://civitai.com/models/9409/or-anything-v5inkcheckpoint_model=models.filter_by_type(ModelType.CHECKPOINT).get_by_civitai_version_id(90854)# Detail Tweaker LoRA, https://civitai.com/models/58390/detail-tweaker-lora-loralora_model=models.filter_by_type(ModelType.LORA).get_by_civitai_version_id(62833)prompt=add_lora_to_prompt('a dog flying in the sky',lora_model.sd_name,"0.8")res=client.sync_txt2img(Txt2ImgRequest(prompt=prompt,batch_size=1,cfg_scale=7.5,sampler_name=Samplers.EULER_A,model_name=checkpoint_model.sd_name,seed=103304,))ifres.data.status!=ProgressResponseStatusCode.SUCCESSFUL:raiseException('Failed to generate image with error: '+res.data.failed_reason)save_image(res.data.imgs_bytes[0],"test.png")Model Searchmodel_search.pyfromnovita_clientimportNovitaClient,ModelTypeclient=NovitaClient(os.getenv('NOVITA_API_KEY'),os.getenv('NOVITA_API_URI',None))# filter by model typeprint("lora count",len(client.models().filter_by_type(ModelType.LORA)))print("checkpoint count",len(client.models().filter_by_type(ModelType.CHECKPOINT)))print("textinversion count",len(client.models().filter_by_type(ModelType.TEXT_INVERSION)))print("vae count",len(client.models().filter_by_type(ModelType.VAE)))print("controlnet count",len(client.models().filter_by_type(ModelType.CONTROLNET)))# filter by civitai tagsclient.models().filter_by_civi_tags('anime')# filter by nsfwclient.models().filter_by_nsfw(False)# or True# sort by civitai downloadclient.models().sort_by_civitai_download()# chain filtersclient.models().\filter_by_type(ModelType.CHECKPOINT).\filter_by_nsfw(False).\filter_by_civitai_tags('anime')ControlNet QRCodecontrolnet_qrcode.pyimportosfromnovita_clientimport*# get your api key refer to https://docs.novita.ai/get-started/client=NovitaClient(os.getenv('NOVITA_API_KEY'),os.getenv('NOVITA_API_URI',None))controlnet_model=client.models().filter_by_type(ModelType.CONTROLNET).get_by_name("control_v1p_sd15_qrcode_monster_v2")ifcontrolnet_modelisNone:raiseException("controlnet model not found")req=Txt2ImgRequest(prompt="a beautify butterfly in the colorful flowers, best quality, best details, masterpiece",sampler_name=Samplers.DPMPP_M_KARRAS,width=512,height=512,steps=30,controlnet_units=[ControlnetUnit(input_image=read_image_to_base64(os.path.join(os.path.abspath(os.path.dirname(__file__)),"fixtures/qrcode.png")),control_mode=ControlNetMode.BALANCED,model=controlnet_model.sd_name,module=ControlNetPreprocessor.NULL,resize_mode=ControlNetResizeMode.JUST_RESIZE,weight=2.0,)])res=client.sync_txt2img(req)ifres.data.status!=ProgressResponseStatusCode.SUCCESSFUL:raiseException('Failed to generate image with error: '+res.data.failed_reason)save_image(res.data.imgs_bytes[0],"qrcode-art.png")Txt2Img with Hires.Fixtxt2img_with_hiresfix.pyimportosfromnovita_clientimport*client=NovitaClient(os.getenv('NOVITA_API_KEY'),os.getenv('NOVITA_API_URI',None))req=Txt2ImgRequest(model_name='dreamshaper_8_93211.safetensors',prompt='a dog flying in the sky',width=512,height=512,batch_size=1,cfg_scale=7.5,sampler_name=Samplers.EULER_A,enable_hr=True,hr_scale=2.0)res=client.sync_txt2img(req)ifres.data.status!=ProgressResponseStatusCode.SUCCESSFUL:raiseException('Failed to generate image with error: '+res.data.failed_reason)save_image(res.data.imgs_bytes[0],"txt2img-hiresfix-1024.png")SDXL Refinersdxl_refiner.pyimportosfromnovita_clientimport*client=NovitaClient(os.getenv('NOVITA_API_KEY'),os.getenv('NOVITA_API_URI',None))req=Txt2ImgRequest(model_name='sd_xl_base_1.0.safetensors',prompt='a dog flying in the sky',width=1024,height=1024,batch_size=1,cfg_scale=7.5,sampler_name=Samplers.EULER_A,sd_refiner=Refiner(checkpoint='sd_xl_refiner_1.0.safetensors',switch_at=0.5,))res=client.sync_txt2img(req)ifres.data.status!=ProgressResponseStatusCode.SUCCESSFUL:raiseException('Failed to generate image with error: '+res.data.failed_reason)save_image(res.data.imgs_bytes[0],"txt2img-refiner.png")Testingexport NOVITA_API_KEY=<YOUR_API_KEY>

python -m pytest