Skip to main content

Simplified library for comfyUI-lcm extensions. support txt2img or img2img

Project description

fasteasySD

fasteasySD is Implementation library of txt2img, img2img function via Latent Consistency Model (LCM) model
This project is designed to enable simple implementation of SD capabilities within other projects

by creating a comfyUI-lcm extension in a standalone library format.

Original version of comfyUI-lcm :
https://github.com/0xbitches/ComfyUI-LCM

Usage

This library supports two functions: txt2img and img2img.

simplest Usage

#import fasteasySD
from fasteasySD import LCM_base

#make LCM_base class
test = LCM_base.FastEasySD(device='cpu',use_fp16=False)

#make img with img2img mode
test.make_image(mode="img2img",prompt="masterpeice, best quality, anime style",seed=0,steps=4,cfg=8,height=1063,width=827,num_images=1,prompt_strength=0.5,input_image_dir="input.jpg")

#make img with txt2img mode
test.make_image(mode="txt2img",prompt="masterpeice, best quality, anime style",seed=0,steps=4,cfg=8,height=768,width=512,num_images=2)

Documentation

Provides simple documentation for this library.

FastEasySD

Main class for LCM model control.

functions

FastEasySD class function list

class FastEasySD:
    """ LCM model pipeline control class.

    Create and manage pipeline objects for LCM models,
    It has functions that process the pipeline input and output values as its main methods.

    """

    def __init__(self, device:str, use_fp16:bool):

        """ Class constructors.

        device : device to use (ex: 'cpu' or 'cuda').

        use_fp16 : Enable fp16 mode. (bool)

        """

    def __makeSampler(self):
        """ Create a txt2img, img2img sampler object. (automatic load with init)

        Create sampler objects for LCM model use.

        """
    
    def make_seed(self,seed: int, random_seed:bool) -> int:

        """ Automatically generate seed value (random number)

        Automatically generate seed value (random number)

        seed : user input seed value (int)

        random_seed : True, False for use random_seed
        
        """
    
    def __load_img(self,img_dir:str):

        """ Load image file for img2img input

        Load the file specified in img_dir and return it to the form available in img2img sampler.

        img_dir : path for input img.

        """
    
    def save_PIL(self,pils,save_name):

        """ PIL image list storage function.

        Store a list of PIL images generated by the LCM model.

        pils : list of PIL images

        save_name : Set image save filename. (ex: {save_name}_1.png)

        """
    
    def return_PIL(self,images):

        """ Converts LCM Model Tensor results to a PIL list.

        Converts the Tensor list generated through the LCM model to a PIL list.

        images : LCM pipeline output tensor

        """
    
    def i2i_batch_save(self,images_list,base_name):

        """ Save img for img2img result values.

        First clean up the Tensor list generated by img2img function.

        and save img2img result.

        images_list : LCM img2img pipeline output tensor list.

        base_name : base name for saving img. (ex : {base_name}_{save_name}_1.png)

        """

    def make(self,mode:str,prompt:str,seed:int,steps:int,cfg:int,
                   height:int,width:int,num_images:int,prompt_strength:float=0,input_image_dir:str="./input.jpg"):
        
        """ Process user input and forward it to the LCM pipeline.

        Forward variable values for image creation to the LCM pipeline and return the corresponding result values

        mode : string for LCM mode (txt2img or img2img)

        prompt : LCM model input prompt (ex : "masterpeice, best quality, anime style" )

        seed : seed for LCM model (input 0 will make random seed)

        steps : steps for LCM model (recommend 2~4)

        cfg : cfg for LCM model (recommend 6~8)

        height , width : setting height and width for img (** if you are using img2img w and h should be the same as the input image. **)

        num_images : How many images will you create for this input

        prompt_strength : (only for img2img) How Strong will the prompts be applied in the img2img feature

        input_image_dir : (only for img2img) input image dir

        """
        
    def make_image(self,mode:str,prompt:str,seed:int,steps:int,cfg:int,
                   height:int,width:int,num_images:int,prompt_strength:float=0,input_image_dir:str="./input.jpg",output_image_dir:str="."):
        
        """ Most Simplified Image Generation Function

        Save the image generated by the txt2img, img2img function as a separate file based on user input.

        the output img will be save like output_image_dir/fesd_0.png(txt2img) or output_image_dir/fesd_i2i_0_0.png(img2img)

        mode : string for LCM mode (txt2img or img2img)

        prompt : LCM model input prompt (ex : "masterpeice, best quality, anime style" )

        seed : seed for LCM model (input 0 will make random seed)

        steps : steps for LCM model (recommend 2~4)

        cfg : cfg for LCM model (recommend 6~8)

        height , width : setting height and width for img (** if you are using img2img w and h should be the same as the input image. **)

        num_images : How many images will you create for this input

        prompt_strength : (only for img2img) How Strong will the prompts be applied in the img2img feature

        input_image_dir : (only for img2img) input image dir

        output_image_dir : output image dir (it will not make dir)

        """

Usage example :

from fasteasySD import FastEasySD

test = FastEasySD(device='cpu',use_fp16=False)

#~~~#

images = test.make(seed=seed,steps=steps,prompt_strength=prompt_strength,cfg=cfg,
                             positive_prompt=prompt,height=height,width=width,num_images=num_images,input_image_dir=input_image_dir)

if mode == "txt2img":
            
    pil_images = test.return_PIL(images)

    images.save_PIL(pils=pil_images,save_name=output_image_dir + "/fesd")

elif mode == "img2img":
            
    images.i2i_batch_save(images_list=images,base_name=output_image_dir + "/fesd_i2i")

Additional Plan Scheduled

add batch mode for img2img input.

add controlnet support

Tech Stack

Python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fasteasySD-0.1.2.tar.gz (26.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fasteasySD-0.1.2-py3-none-any.whl (27.4 kB view details)

Uploaded Python 3

File details

Details for the file fasteasySD-0.1.2.tar.gz.

File metadata

  • Download URL: fasteasySD-0.1.2.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for fasteasySD-0.1.2.tar.gz
Algorithm Hash digest
SHA256 0db07c32423934c67c903df8c1a48cd85f926f3d28e8e70d3f3894fce456c3e0
MD5 73b6d80cd8d2037dd118eb33310e3ff0
BLAKE2b-256 5af112dbfd724b8917d3348621753e536885df522e8aae78fe6a32fa94d865d1

See more details on using hashes here.

File details

Details for the file fasteasySD-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: fasteasySD-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 27.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.5

File hashes

Hashes for fasteasySD-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 998b059393d5851a780d1e9f5eebd36ba07b91287accc2629fb7912a03bf1ae0
MD5 9e878c3b204fe0ff73ead42c1667654b
BLAKE2b-256 d442032ae4f676a939c6ed83bcf4369002f7f92d0327d44f140d20891c8b7f4c

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page