mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-11 17:44:38 +00:00
inpainting works in kcpp!
This commit is contained in:
parent
fea3b2bd4a
commit
23339ace9b
4 changed files with 39 additions and 34 deletions
1
expose.h
1
expose.h
|
@ -168,6 +168,7 @@ struct sd_generation_inputs
|
||||||
const char * prompt = nullptr;
|
const char * prompt = nullptr;
|
||||||
const char * negative_prompt = nullptr;
|
const char * negative_prompt = nullptr;
|
||||||
const char * init_images = "";
|
const char * init_images = "";
|
||||||
|
const char * mask = "";
|
||||||
const float denoising_strength = 0.0f;
|
const float denoising_strength = 0.0f;
|
||||||
const float cfg_scale = 0.0f;
|
const float cfg_scale = 0.0f;
|
||||||
const int sample_steps = 0;
|
const int sample_steps = 0;
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -263,6 +263,7 @@ class sd_generation_inputs(ctypes.Structure):
|
||||||
_fields_ = [("prompt", ctypes.c_char_p),
|
_fields_ = [("prompt", ctypes.c_char_p),
|
||||||
("negative_prompt", ctypes.c_char_p),
|
("negative_prompt", ctypes.c_char_p),
|
||||||
("init_images", ctypes.c_char_p),
|
("init_images", ctypes.c_char_p),
|
||||||
|
("mask", ctypes.c_char_p),
|
||||||
("denoising_strength", ctypes.c_float),
|
("denoising_strength", ctypes.c_float),
|
||||||
("cfg_scale", ctypes.c_float),
|
("cfg_scale", ctypes.c_float),
|
||||||
("sample_steps", ctypes.c_int),
|
("sample_steps", ctypes.c_int),
|
||||||
|
@ -1484,6 +1485,7 @@ def sd_generate(genparams):
|
||||||
prompt = forced_posprompt
|
prompt = forced_posprompt
|
||||||
init_images_arr = genparams.get("init_images", [])
|
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])
|
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))
|
denoising_strength = tryparsefloat(genparams.get("denoising_strength", 0.6))
|
||||||
cfg_scale = tryparsefloat(genparams.get("cfg_scale", 5))
|
cfg_scale = tryparsefloat(genparams.get("cfg_scale", 5))
|
||||||
sample_steps = tryparseint(genparams.get("steps", 20))
|
sample_steps = tryparseint(genparams.get("steps", 20))
|
||||||
|
@ -1520,6 +1522,7 @@ def sd_generate(genparams):
|
||||||
inputs.prompt = prompt.encode("UTF-8")
|
inputs.prompt = prompt.encode("UTF-8")
|
||||||
inputs.negative_prompt = negative_prompt.encode("UTF-8")
|
inputs.negative_prompt = negative_prompt.encode("UTF-8")
|
||||||
inputs.init_images = init_images.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.cfg_scale = cfg_scale
|
||||||
inputs.denoising_strength = denoising_strength
|
inputs.denoising_strength = denoising_strength
|
||||||
inputs.sample_steps = sample_steps
|
inputs.sample_steps = sample_steps
|
||||||
|
|
|
@ -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("With Custom Clip-G Model: %s\n",clipg_filename.c_str());
|
||||||
}
|
}
|
||||||
|
printf("\n");
|
||||||
|
|
||||||
//duplicated from expose.cpp
|
//duplicated from expose.cpp
|
||||||
int cl_parseinfo = inputs.clblast_info; //first digit is whether configured, second is platform, third is devices
|
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 cleanprompt = clean_input_prompt(inputs.prompt);
|
||||||
std::string cleannegprompt = clean_input_prompt(inputs.negative_prompt);
|
std::string cleannegprompt = clean_input_prompt(inputs.negative_prompt);
|
||||||
std::string img2img_data = std::string(inputs.init_images);
|
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;
|
std::string sampler = inputs.sample_method;
|
||||||
|
|
||||||
sd_params->prompt = cleanprompt;
|
sd_params->prompt = cleanprompt;
|
||||||
|
@ -506,9 +507,9 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
||||||
if(img2img_mask!="")
|
if(img2img_mask!="")
|
||||||
{
|
{
|
||||||
image_mask_buffer = kcpp_base64_decode(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
|
// 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) {
|
if (!resok) {
|
||||||
printf("\nKCPP SD: resize image failed!\n");
|
printf("\nKCPP SD: resize image failed!\n");
|
||||||
output.data = "";
|
output.data = "";
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue