### Text-to-Image Generation (txt2img) Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Provides a Python example for generating images from text using the txt2img function. It includes essential parameters such as prompt, negative prompt, seed, steps, CFG scale, and sampler name. The example also shows how to access and save the generated image. ```Python import webuiapi result1 = api.txt2img(prompt="cute squirrel", negative_prompt="ugly, out of frame", seed=-1, styles=["anime"], cfg_scale=1, steps=20, enable_hr=False, denoising_strength=0.5, sampler_name= "Euler", scheduler= "Simple" ) img = result1.image img # OR file_path = "output_image.png" result1.image.save(file_path) ``` -------------------------------- ### Initialize WebUI API Connection Source: https://github.com/mix1009/sdwebuiapi/blob/main/webuiapi_demo.ipynb Establishes a connection to the Stable Diffusion WebUI API. It shows how to import the library and instantiate the API client, optionally specifying host, port, sampler, and steps. ```Python # use webuiapi.py from webuiapi folder import sys sys.path.append('./webuiapi') # or install using pip install webuiapi import webuiapi # api = webuiapi.WebUIApi() api = webuiapi.WebUIApi(host='127.0.0.1', port=7860, sampler='Euler a', steps=20) ``` -------------------------------- ### Manage Web UI Options with sdwebuiapi Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Provides examples of how to get and set configuration options for the Stable Diffusion Web UI using the sdwebuiapi. This includes retrieving current options, changing the SD model checkpoint, and a cautionary note about not passing all options when setting them. ```Python # return map of current options options = api.get_options() # change sd model options = {} options['sd_model_checkpoint'] = 'model.ckpt [7460a6fa]' api.set_options(options) # when calling set_options, do not pass all options returned by get_options(). # it makes webui unusable (2022/11/21). ``` -------------------------------- ### Async txt2img API Call Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Demonstrates an asynchronous text-to-image generation using the txt2img API with the `use_async=True` parameter. This requires the `asyncio` and `aiohttp` packages to be installed. ```Python result = await api.txt2img(prompt="cute kitten", seed=1001, use_async=True ) result.image ``` -------------------------------- ### Create API Client Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Demonstrates how to create an instance of the WebUIApi client. It shows examples of creating a client with default settings, custom host and port, using HTTPS, and setting default sampler and steps. Authentication can also be configured. ```Python import webuiapi # create API client api = webuiapi.WebUIApi() # create API client with custom host, port #api = webuiapi.WebUIApi(host='127.0.0.1', port=7860) # create API client with custom host, port and https #api = webuiapi.WebUIApi(host='webui.example.com', port=443, use_https=True) # create API client with default sampler, steps. #api = webuiapi.WebUIApi(sampler='Euler a', steps=20) # optionally set username, password when --api-auth=username:password is set on webui. # username, password are not protected and can be derived easily if the communication channel is not encrypted. # you can also pass username, password to the WebUIApi constructor. api.set_auth('username', 'password') ``` -------------------------------- ### Install webuiapi Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Installs the sdwebuiapi Python package using pip. This package is a client for the AUTOMATIC1111 Stable Diffusion WebUI API. ```shell pip install webuiapi ``` -------------------------------- ### Retrieve Available Models and Samplers with sdwebuiapi Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Shows how to fetch lists of available Stable Diffusion models and samplers using the sdwebuiapi. It also includes examples for retrieving other configuration details like command-line flags, hypernetworks, face restorers, and more. ```Python # get available sd models api.get_sd_models() # misc get apis api.get_samplers() api.get_cmd_flags() api.get_hypernetworks() api.get_face_restorers() api.get_realesrgan_models() api.get_prompt_styles() api.get_artist_categories() # deprecated ? api.get_artists() # deprecated ? api.get_progress() api.get_embeddings() api.get_cmd_flags() api.get_scripts() api.get_schedulers() api.get_memory() ``` -------------------------------- ### Get Available Schedulers Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Retrieves the names of all available schedulers that can be used for image generation. ```Python api.util_get_scheduler_names() ``` -------------------------------- ### Image-to-Image Transformation (img2img) Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Demonstrates how to perform image-to-image transformations using the img2img function. This example includes loading an image, setting parameters like prompt, steps, seed, CFG scale, denoising strength, resize mode, dimensions, sampler, and scheduler, and saving the resulting image. ```Python import webuiapi from PIL import Image img = Image.open("/path/to/your/image.jpg") api = webuiapi.WebUIApi() result1 = api.img2img( images=[img], prompt="a cute squirrel", steps=20, seed=-1, cfg_scale=1, denoising_strength=0.5, resize_mode=2, width=512, height=512, sampler_name= "Euler", scheduler= "Simple" ) file_path = "face_swapped_image.png" result1.image.save(file_path) ``` -------------------------------- ### Text-to-Image Generation Source: https://github.com/mix1009/sdwebuiapi/blob/main/webuiapi_demo.ipynb Generates an image from a text prompt using the txt2img endpoint. It includes parameters for prompt, negative prompt, seed, styles, and CFG scale. The generated image is accessed via `result.image`. ```Python # txt2img result1 = api.txt2img(prompt="cute squirrel", negative_prompt="ugly, out of frame", seed=1003, styles=["anime"], cfg_scale=7, # sampler_index='DDIM', # steps=30, ) result1.image ``` -------------------------------- ### Use X/Y/Z Plot Script with sdwebuiapi Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Demonstrates how to use the X/Y/Z Plot script with the sdwebuiapi. It shows how to define axis types and values, and pass them as script arguments to the txt2img API call. The example includes lists of available axis options for both txt2img and img2img. ```Python # Available Axis options (Different for txt2img and img2img!) XYZPlotAvailableTxt2ImgScripts = [ "Nothing", "Seed", "Var. seed", "Var. strength", "Steps", "Hires steps", "CFG Scale", "Prompt S/R", "Prompt order", "Sampler", "Checkpoint name", "Sigma Churn", "Sigma min", "Sigma max", "Sigma noise", "Eta", "Clip skip", "Denoising", "Hires upscaler", "VAE", "Styles", ] XYZPlotAvailableImg2ImgScripts = [ "Nothing", "Seed", "Var. seed", "Var. strength", "Steps", "CFG Scale", "Image CFG Scale", "Prompt S/R", "Prompt order", "Sampler", "Checkpoint name", "Sigma Churn", "Sigma min", "Sigma max", "Sigma noise", "Eta", "Clip skip", "Denoising", "Cond. Image Mask Weight", "VAE", "Styles", ] # Example call XAxisType = "Steps" XAxisValues = "20,30" XAxisValuesDropdown = "" YAxisType = "Sampler" YAxisValues = "Euler a, LMS" YAxisValuesDropdown = "" ZAxisType = "Nothing" ZAxisValues = "" ZAxisValuesDropdown = "" drawLegend = "True" includeLoneImages = "False" includeSubGrids = "False" noFixedSeeds = "False" marginSize = 0 # x_type, x_values, y_type, y_values, z_type, z_values, draw_legend, include_lone_images, include_sub_grids, no_fixed_seeds, margin_size result = api.txt2img( prompt="cute girl with short brown hair in black t-shirt in animation style", seed=1003, script_name="X/Y/Z Plot", script_args=[ XYZPlotAvailableTxt2ImgScripts.index(XAxisType), XAxisValues, XAxisValuesDropdown, XYZPlotAvailableTxt2ImgScripts.index(YAxisType), YAxisValues, YAxisValuesDropdown, XYZPlotAvailableTxt2ImgScripts.index(ZAxisType), ZAxisValues, ZAxisValuesDropdown, drawLegend, includeLoneImages, includeSubGrids, noFixedSeeds, marginSize, ] ) result.image ``` -------------------------------- ### Image-to-Image Transformation Source: https://github.com/mix1009/sdwebuiapi/blob/main/webuiapi_demo.ipynb Transforms an existing image based on a text prompt using the img2img endpoint. It takes a list of images, a prompt, seed, CFG scale, and denoising strength as input. The output image is accessed via `result.image`. ```Python # img2img result2 = api.img2img(images=[result1.image], prompt="cute cat", seed=5555, cfg_scale=6.5, denoising_strength=0.6) result2.image ``` -------------------------------- ### Upscale Batch Images Source: https://github.com/mix1009/sdwebuiapi/blob/main/webuiapi_demo.ipynb Applies upscaling to multiple images in a batch using the extra_batch_images endpoint. It takes a list of images, an upscaler model, and a resize factor. The number of upscaled images is returned, and individual images are accessed via `result.images[index]`. ```Python result4 = api.extra_batch_images(images=[result1.image, result2.image], upscaler_1="ESRGAN_4x", upscaling_resize=1.5) len(result4.images) result4.images[0] result4.images[1] ``` -------------------------------- ### Inpainting with Image-to-Image Source: https://github.com/mix1009/sdwebuiapi/blob/main/webuiapi_demo.ipynb Performs inpainting on an image using the img2img endpoint with a mask. It requires the original image, a mask image, inpainting fill mode, prompt, seed, CFG scale, and denoising strength. The result is accessed via `result.image`. ```Python # inpainting with img2img from PIL import Image, ImageDraw mask = Image.new('RGB', result2.image.size, color = 'black') # mask = result2.image.copy() draw = ImageDraw.Draw(mask) draw.ellipse((210,150,310,250), fill='white') draw.ellipse((80,120,160,120+80), fill='white') # mask inpainting_result = api.img2img(images=[result2.image], mask_image=mask, inpainting_fill=1, prompt="cute cat", seed=104, cfg_scale=5.0, denoising_strength=0.7) inpainting_result.image ``` -------------------------------- ### Upscale Single Image Source: https://github.com/mix1009/sdwebuiapi/blob/main/webuiapi_demo.ipynb Applies upscaling to a single image using the extra_single_image endpoint. It takes the image, an upscaler model, and a resize factor as parameters. The size of the upscaled image is printed, and the image is accessed via `result.image`. ```Python result3 = api.extra_single_image(image=result2.image, upscaler_1="ESRGAN_4x", upscaling_resize=1.5) print(result3.image.size) result3.image ``` -------------------------------- ### Text-to-Image with XY Plot Script Source: https://github.com/mix1009/sdwebuiapi/blob/main/webuiapi_demo.ipynb Generates images using the txt2img endpoint with the 'X/Y Plot' script. This allows for systematic variation of parameters like steps, sampler, or CFG scale across a grid of images. It requires defining the X and Y axis types and values. ```Python # txt2img with scripts XYPlotAvailableScripts = [ "Nothing", "Seed", "Var. seed", "Var. strength", "Steps", "CFG Scale", "Prompt S/R", "Prompt order", "Sampler", "Checkpoint Name", "Hypernetwork", "Hypernet str.", "Sigma Churn", "Sigma min", "Sigma max", "Sigma noise", "Eta", "Clip skip", "Denoising", "Hires upscaler", "Cond. Image Mask Weight", "VAE", "Styles" ] # Example call XAxisType = "Steps" XAxisValues = "32,64" YAxisType = "Sampler" YAxisValues = "k_euler_a, ddim, k_dpm_2_a" drawLegend = "True" includeSeparateImages = "False" keepRandomSeed = "False" result5 = api.txt2img( prompt="cute squirrel", negative_prompt="ugly, out of frame", seed=1003, cfg_scale=7, script_name="X/Y Plot", script_args=[ XYPlotAvailableScripts.index(XAxisType), XAxisValues, XYPlotAvailableScripts.index(YAxisType), YAxisValues, drawLegend, includeSeparateImages, keepRandomSeed ] ) result5.image ``` -------------------------------- ### Generate Text with PromptGen Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Demonstrates how to use the prompt_gen function from the sdwebuiapi library to generate text. It shows basic usage with a default model and how to specify a different model, along with complete usage with various parameters like batch count, length, temperature, and sampling mode. ```Python result = api.prompt_gen(text=text) ``` ```Python result = api.prompt_gen(text=text, model_name="AUTOMATIC/promptgen-majinai-unsafe") ``` ```Python result = api.prompt_gen( text=text, model_name="AUTOMATIC/promptgen-majinai-unsafe", batch_count= 1, batch_size=10, min_length=20, max_length=150, num_beams=1, temperature=1, repetition_penalty=1, length_preference=1, sampling_mode="Top K", top_k=12, top_p=0.15 ) ``` -------------------------------- ### Instruct-Pix2Pix Image-to-Image Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs image-to-image translation using the Instruct-Pix2Pix functionality, which is now integrated into the standard img2img endpoint. Requires loading an Instruct-Pix2Pix model and using the 'image_cfg_scale' parameter. ```Python r = api.img2img(prompt='sunset', images=[pil_img], cfg_scale=7.5, image_cfg_scale=1.5) r.image ``` -------------------------------- ### List available prompt generation models Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Retrieves a list of available prompt generation models from the promptgen API. This is useful for selecting a model for prompt creation. Requires an initialized WebUIApi. ```Python api = webuiapi.WebUIApi() result = api.list_prompt_gen_models() print("list of models") print(result) ``` -------------------------------- ### txt2img API Call Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs a text-to-image generation using the txt2img API. It includes parameters for prompt, negative prompt, seed, styles, and CFG scale. Optional parameters for high-resolution fix and sampler steps are commented out. ```Python result1 = api.txt2img(prompt="cute squirrel", negative_prompt="ugly, out of frame", seed=1003, styles=["anime"], cfg_scale=7, # sampler_index='DDIM', # steps=30, # enable_hr=True, # hr_scale=2, # hr_upscaler=webuiapi.HiResUpscaler.Latent, # hr_second_pass_steps=20, # hr_resize_x=1536, # hr_resize_y=1024, # denoising_strength=0.4, ) # images contains the returned images (PIL images) result1.images # image is shorthand for images[0] result1.image # info contains text info about the api call result1.info # info contains paramteres of the api call result1.parameters result1.image ``` -------------------------------- ### ControlNet Version and Module List Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Fetches the version of the ControlNet extension and lists the available modules that can be utilized for various control tasks. ```Python api.controlnet_version() api.controlnet_module_list() ``` -------------------------------- ### img2img with ADetailer Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs image-to-image transformation with ADetailer integration for improved results. Allows specifying an input image, prompt, and ADetailer model. Requires an initialized WebUIApi, PIL Image, and ADetailer object. ```Python img = Image.open("/path/to/your/image.jpg") ads = webuiapi.ADetailer(ad_model="face_yolov8n.pt") result1 = api.img2img( images=[img], prompt="a cute squirrel", steps=25, seed=-1, cfg_scale=7, denoising_strength=0.5, resize_mode=2, width=512, height=512, adetailer=[ads], ) ``` -------------------------------- ### Basic Text-to-Image Generation Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Generates an image from a text prompt using the standard txt2img endpoint with specified height and seed for reproducibility. ```Python r = api.txt2img(prompt="photo of a beautiful girl with blonde hair", height=512, seed=100) img = r.image img ``` -------------------------------- ### Face swapping with ReActor in img2img Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs an image-to-image transformation while swapping faces using the ReActor extension. Requires the target image, a source face image, and ReActor configuration. Requires an initialized WebUIApi, PIL Images, and ReActor object. ```Python img = Image.open("/path/to/your/image.jpg") your_desired_face = Image.open("/path/to/your/desired/face.jpeg") reactor = webuiapi.ReActor( img=your_desired_face, enable=True ) result1 = api.img2img( images=[img], prompt="a cute squirrel", steps=25, seed=-1, cfg_scale=7, denoising_strength=0.5, resize_mode=2, width=512, height=512, reactor=reactor ) ``` -------------------------------- ### Text-to-Image with ControlNet (Single Unit) Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Generates an image from a text prompt using txt2img, conditioned by a single ControlNet unit. The 'image' parameter is used for the input image, and 'module' and 'model' specify the ControlNet configuration. ```Python unit1 = webuiapi.ControlNetUnit(image=img, module='canny', model='control_v11p_sd15_canny [d14c016b]') r = api.txt2img(prompt="photo of a beautiful girl", controlnet_units=[unit1]) r.image ``` -------------------------------- ### Interrogate image with DeepDanbooru model Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Interrogates an image to generate descriptive tags using the DeepDanbooru model. Also supports the 'clip' model (default). Returns the generated prompt information. Requires an initialized WebUIApi and a PIL Image. ```Python img = Image.open("/path/to/your/image.jpg") interrogate_result = api.interrogate(image=img, model="deepdanbooru") prompt = interrogate_result.info print(prompt) ``` -------------------------------- ### ControlNet Model List Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Retrieves a list of all available ControlNet models that can be used for conditioning image generation. ```Python api.controlnet_model_list() ``` -------------------------------- ### Wait for Ready Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Waits until the Stable Diffusion Web UI is ready to accept new jobs. This is useful for ensuring the API is responsive before sending commands. ```Python api.util_wait_for_ready() ``` -------------------------------- ### Text-to-Image with LORA and Alwayson Scripts Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Generates an image from text using the txt2img endpoint, incorporating LORA models for style modification and utilizing the 'alwayson_scripts' parameter for extensions like Simple Wildcards. ```Python r = api.txt2img(prompt='photo of a cute girl with green hair shuimobysim __juice__', seed=1000, save_images=True, alwayson_scripts={'Simple wildcards':[]}) r.image ``` -------------------------------- ### txt2img with ADetailer Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Generates an image from text using txt2img, with ADetailer integration for enhanced subject-specific details. Supports standard txt2img parameters plus ADetailer model configuration. Requires an initialized WebUIApi and ADetailer object. ```Python ads = webuiapi.ADetailer(ad_model="face_yolov8n.pt") result1 = api.txt2img(prompt="cute squirrel", negative_prompt="ugly, out of frame", seed=-1, styles=["anime"], cfg_scale=7, adetailer=[ads], steps=30, enable_hr=True, denoising_strength=0.5 ) ``` -------------------------------- ### Manage Model and Sampler Names with sdwebuiapi Utilities Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Illustrates how to use utility methods to save the current model name and retrieve lists of available model and sampler names. These functions are helpful for managing and querying the resources available within the Stable Diffusion Web UI. ```Python # save current model name old_model = api.util_get_current_model() # get list of available models models = api.util_get_model_names() # get list of available samplers api.util_get_sampler_names() ``` -------------------------------- ### Perform SAM segmentation with GroundingDINO Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs image segmentation using the SAM model, optionally enabled with GroundingDINO for text-prompt-based segmentation. Requires the 'segment' module and an image input. ```Python sam_result2 = segment.sam_predict( image=img, dino_enabled=True, dino_text_prompt="A text prompt for GroundingDINO", ) ``` -------------------------------- ### Image-to-Image with Multiple ControlNets Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs image-to-image translation with multiple ControlNet units applied simultaneously. Each unit can have a different module, model, and weight to influence the generation process. ```Python unit1 = webuiapi.ControlNetUnit(image=img, module='canny', model='control_v11p_sd15_canny [d14c016b]') unit2 = webuiapi.ControlNetUnit(image=img, module='depth', model='control_v11f1p_sd15_depth [cfd03158]', weight=0.5) r2 = api.img2img(prompt="girl", images=[img], width=512, height=512, controlnet_units=[unit1, unit2], sampler_name="Euler a", cfg_scale=7, ) r2.image ``` -------------------------------- ### Tag images using WD14 Tagger Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Interrogates an image to generate tags using the WD14 Tagger extension. Returns a dictionary containing the generated caption. Requires an initialized TaggerInterface and an image. ```Python tagger = webuiapi.TaggerInterface(api) result = tagger.tagger_interrogate(image) print(result) ``` -------------------------------- ### extra-batch-images API Call Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs upscaling on multiple images using the extra_batch_images API. It takes a list of images and applies the specified upscaler and resize factor to all of them. ```Python result4 = api.extra_batch_images(images=[result1.image, inpainting_result.image], upscaler_1=webuiapi.Upscaler.ESRGAN_4x, upscaling_resize=1.5) result4.images[0] ``` ```Python result4.images[1] ``` -------------------------------- ### Model Keyword Interface Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Interacts with the Model-Keyword extension to retrieve keywords associated with models. Requires the ModelKeywordInterface to be initialized with the API object. ```Python mki = webuiapi.ModelKeywordInterface(api) mki.get_keywords() ``` -------------------------------- ### img2img API Call Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs an image-to-image translation using the img2img API. It takes a list of images (in this case, the result from a previous txt2img call) and a prompt to generate a new image. Parameters include seed, CFG scale, and denoising strength. ```Python result2 = api.img2img(images=[result1.image], prompt="cute cat", seed=5555, cfg_scale=6.5, denoising_strength=0.6) result2.image ``` -------------------------------- ### AnimateDiff for GIF Generation Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Generates an animated GIF using the AnimateDiff extension. This involves configuring the AnimateDiff object with parameters like model, video length, loop type, and format, then passing it to the txt2img endpoint. ```Python adiff = webuiapi.AnimateDiff(model='mm_sd15_v3.safetensors', video_length=24, closed_loop='R+P', format=['GIF']) r = api.txt2img(prompt='cute puppy', animatediff=adiff) # save GIF file. need save_all=True to save animated GIF. r.image.save('puppy.gif', save_all=True) # Display animated GIF in Jupyter notebook from IPython.display import HTML HTML(''.format(r.json['images'][0])) ``` -------------------------------- ### Self Attention Guidance (SAG) in img2img Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Applies Self Attention Guidance (SAG) during an image-to-image transformation to enhance specific image regions. Allows configuration of SAG parameters like scale and mask threshold. Requires an initialized WebUIApi, PIL Image, and Sag object. ```Python img = Image.open("/path/to/your/image.jpg") sag = webuiapi.Sag( enable=True, scale=0.75, mask_threshold=1.00 ) result1 = api.img2img( images=[img], prompt="a cute squirrel", steps=25, seed=-1, cfg_scale=7, denoising_strength=0.5, resize_mode=2, width=512, height=512, sag=sag ) ``` -------------------------------- ### img2img Inpainting Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Demonstrates image inpainting using the img2img API. It involves creating a mask to specify the area to be inpainted, then calling the API with the original image, the mask, and inpainting-specific parameters like inpainting_fill. ```Python from PIL import Image, ImageDraw mask = Image.new('RGB', result2.image.size, color = 'black') # mask = result2.image.copy() draw = ImageDraw.Draw(mask) draw.ellipse((210,150,310,250), fill='white') draw.ellipse((80,120,160,120+80), fill='white') mask ``` ```Python inpainting_result = api.img2img(images=[result2.image], mask_image=mask, inpainting_fill=1, prompt="cute cat", seed=104, cfg_scale=5.0, denoising_strength=0.7) inpainting_result.image ``` -------------------------------- ### Perform Actions like Interrupt and Skip with sdwebuiapi Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Demonstrates the use of utility methods for controlling the generation process, such as interrupting a running task or skipping the current step. These functions allow for dynamic control over the Web UI's operations. ```Python # misc apis api.interrupt() api.skip() ``` -------------------------------- ### RemBG Interface for Background Removal Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Utilizes the RemBG extension to remove the background from an image. The RemBGInterface is initialized with the API object, and the rembg method is called with the input image and desired model. ```Python rembg = webuiapi.RemBGInterface(api) r = rembg.rembg(input_image=img, model='u2net', return_mask=False) r.image ``` -------------------------------- ### extra-single-image API Call Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs upscaling on a single image using the extra_single_image API. It specifies the upscaler model (e.g., ESRGAN_4x) and the scaling resize factor. ```Python result3 = api.extra_single_image(image=result2.image, upscaler_1=webuiapi.Upscaler.ESRGAN_4x, upscaling_resize=1.5) print(result3.image.size) result3.image ``` -------------------------------- ### SegmentAnything Interface for Image Segmentation Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Performs image segmentation using the Segment Anything Model (SAM) via the SegmentAnythingInterface. The sam_predict method takes the image and positive points as input to identify segments. ```Python segment = webuiapi.SegmentAnythingInterface(api) # Perform a segmentation prediction using the SAM model using points sam_result = segment.sam_predict( image=img, sam_positive_points=[(0.5, 0.25), (0.75, 0.75)], # add other parameters as needed ) ``` -------------------------------- ### Generate semantic segmentation with category IDs Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Generates semantic segmentation for an image, allowing specification of category IDs. Supports multiple categories separated by '+'. Requires the image and a string of category IDs. ```Python semantic_seg_result = segment.sam_and_semantic_seg_with_cat_id( image=img, category="1+2+3", # Category IDs separated by '+' ) ``` -------------------------------- ### Refresh Models Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Refreshes the list of available models in the Stable Diffusion Web UI. This is useful after adding or removing models. ```Python api.refresh_checkpoints() ``` -------------------------------- ### Set Model Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Sets the active model for image generation. It can be set using the exact model name or by finding the closest match. ```Python api.util_set_model(models[0]) ``` ```Python api.util_set_model('robodiffusion') ``` -------------------------------- ### ControlNet Image Detection Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Detects features in an image using a specified ControlNet module (e.g., 'canny') and returns the processed image. This is useful for preparing conditioning images. ```Python r = api.controlnet_detect(images=[img], module='canny') r.image ``` -------------------------------- ### Dilate a segmentation mask Source: https://github.com/mix1009/sdwebuiapi/blob/main/README.md Dilates a given segmentation mask by a specified amount. This is useful for expanding the boundaries of a detected object. Requires an image, a mask, and the dilation amount. ```Python dilation_result = segment.dilate_mask( image=img, mask=sam_result.masks[0], # using the first mask from the SAM prediction dilate_amount=30 ) ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.