diff --git a/expose.h b/expose.h index fb25fc8ca..149117987 100644 --- a/expose.h +++ b/expose.h @@ -168,6 +168,7 @@ struct sd_generation_inputs const char * prompt = nullptr; const char * negative_prompt = nullptr; const char * init_images = ""; + const char * mask = ""; const float denoising_strength = 0.0f; const float cfg_scale = 0.0f; const int sample_steps = 0; diff --git a/kcpp_sdui.embd b/kcpp_sdui.embd index c9c83f638..f1f4a5efc 100644 --- a/kcpp_sdui.embd +++ b/kcpp_sdui.embd @@ -5,18 +5,18 @@ Stable UI for KoboldCpp - - diff --git a/koboldcpp.py b/koboldcpp.py index fe5463523..dc4dbce6e 100644 --- a/koboldcpp.py +++ b/koboldcpp.py @@ -263,6 +263,7 @@ class sd_generation_inputs(ctypes.Structure): _fields_ = [("prompt", ctypes.c_char_p), ("negative_prompt", ctypes.c_char_p), ("init_images", ctypes.c_char_p), + ("mask", ctypes.c_char_p), ("denoising_strength", ctypes.c_float), ("cfg_scale", ctypes.c_float), ("sample_steps", ctypes.c_int), @@ -1484,6 +1485,7 @@ def sd_generate(genparams): prompt = forced_posprompt init_images_arr = genparams.get("init_images", []) init_images = ("" if (not init_images_arr or len(init_images_arr)==0 or not init_images_arr[0]) else init_images_arr[0]) + mask = genparams.get("mask", "") denoising_strength = tryparsefloat(genparams.get("denoising_strength", 0.6)) cfg_scale = tryparsefloat(genparams.get("cfg_scale", 5)) sample_steps = tryparseint(genparams.get("steps", 20)) @@ -1520,6 +1522,7 @@ def sd_generate(genparams): inputs.prompt = prompt.encode("UTF-8") inputs.negative_prompt = negative_prompt.encode("UTF-8") inputs.init_images = init_images.encode("UTF-8") + inputs.mask = "".encode("UTF-8") if not mask else mask.encode("UTF-8") inputs.cfg_scale = cfg_scale inputs.denoising_strength = denoising_strength inputs.sample_steps = sample_steps diff --git a/otherarch/sdcpp/sdtype_adapter.cpp b/otherarch/sdcpp/sdtype_adapter.cpp index ff06bbe32..8762f8964 100644 --- a/otherarch/sdcpp/sdtype_adapter.cpp +++ b/otherarch/sdcpp/sdtype_adapter.cpp @@ -160,6 +160,7 @@ bool sdtype_load_model(const sd_load_model_inputs inputs) { { printf("With Custom Clip-G Model: %s\n",clipg_filename.c_str()); } + printf("\n"); //duplicated from expose.cpp int cl_parseinfo = inputs.clblast_info; //first digit is whether configured, second is platform, third is devices @@ -320,7 +321,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) std::string cleanprompt = clean_input_prompt(inputs.prompt); std::string cleannegprompt = clean_input_prompt(inputs.negative_prompt); std::string img2img_data = std::string(inputs.init_images); - std::string img2img_mask = ""; + std::string img2img_mask = std::string(inputs.mask); std::string sampler = inputs.sample_method; sd_params->prompt = cleanprompt; @@ -506,9 +507,9 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs) if(img2img_mask!="") { image_mask_buffer = kcpp_base64_decode(img2img_mask); - input_mask_buffer = stbi_load_from_memory(image_mask_buffer.data(), image_mask_buffer.size(), &nx2, &ny2, &nc2, 3); + input_mask_buffer = stbi_load_from_memory(image_mask_buffer.data(), image_mask_buffer.size(), &nx2, &ny2, &nc2, 1); // Resize the image - int resok = stbir_resize_uint8(input_mask_buffer, nx, ny, 0, resized_mask_buf.data(), img2imgW, img2imgH, 0, img2imgC); + int resok = stbir_resize_uint8(input_mask_buffer, nx2, ny2, 0, resized_mask_buf.data(), img2imgW, img2imgH, 0, 1); if (!resok) { printf("\nKCPP SD: resize image failed!\n"); output.data = "";