mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2025-09-11 01:24:36 +00:00
photomaker renamed to extra image to handle future extension
This commit is contained in:
parent
815d2056d9
commit
0bd648ffa4
4 changed files with 41 additions and 43 deletions
2
expose.h
2
expose.h
|
@ -181,7 +181,7 @@ struct sd_generation_inputs
|
|||
const char * negative_prompt = nullptr;
|
||||
const char * init_images = "";
|
||||
const char * mask = "";
|
||||
const char * photomaker_image = "";
|
||||
const char * extra_image = "";
|
||||
const bool flip_mask = false;
|
||||
const float denoising_strength = 0.0f;
|
||||
const float cfg_scale = 0.0f;
|
||||
|
|
File diff suppressed because one or more lines are too long
|
@ -291,7 +291,7 @@ class sd_generation_inputs(ctypes.Structure):
|
|||
("negative_prompt", ctypes.c_char_p),
|
||||
("init_images", ctypes.c_char_p),
|
||||
("mask", ctypes.c_char_p),
|
||||
("photomaker_image", ctypes.c_char_p),
|
||||
("extra_image", ctypes.c_char_p),
|
||||
("flip_mask", ctypes.c_bool),
|
||||
("denoising_strength", ctypes.c_float),
|
||||
("cfg_scale", ctypes.c_float),
|
||||
|
@ -1714,7 +1714,7 @@ def sd_generate(genparams):
|
|||
seed = random.randint(100000, 999999)
|
||||
sample_method = genparams.get("sampler_name", "k_euler_a")
|
||||
clip_skip = tryparseint(genparams.get("clip_skip", -1),-1)
|
||||
photomaker_image = strip_base64_prefix(genparams.get("photomaker_image", ""))
|
||||
extra_image = strip_base64_prefix(genparams.get("extra_image", ""))
|
||||
|
||||
#clean vars
|
||||
cfg_scale = (1 if cfg_scale < 1 else (25 if cfg_scale > 25 else cfg_scale))
|
||||
|
@ -1728,7 +1728,7 @@ def sd_generate(genparams):
|
|||
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.photomaker_image = "".encode("UTF-8") if not photomaker_image else photomaker_image.encode("UTF-8")
|
||||
inputs.extra_image = "".encode("UTF-8") if not extra_image else extra_image.encode("UTF-8")
|
||||
inputs.flip_mask = flip_mask
|
||||
inputs.cfg_scale = cfg_scale
|
||||
inputs.denoising_strength = denoising_strength
|
||||
|
|
|
@ -116,7 +116,7 @@ static int sddebugmode = 0;
|
|||
static std::string recent_data = "";
|
||||
static uint8_t * input_image_buffer = NULL;
|
||||
static uint8_t * input_mask_buffer = NULL;
|
||||
static uint8_t * input_photomaker_buffer = NULL;
|
||||
static uint8_t * input_extraimage_buffer = NULL;
|
||||
|
||||
static std::string sdplatformenv, sddeviceenv, sdvulkandeviceenv;
|
||||
static int cfg_tiled_vae_threshold = 0;
|
||||
|
@ -434,14 +434,9 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||
std::string cleannegprompt = clean_input_prompt(inputs.negative_prompt);
|
||||
std::string img2img_data = std::string(inputs.init_images);
|
||||
std::string img2img_mask = std::string(inputs.mask);
|
||||
std::string photomaker_image_data = std::string(inputs.photomaker_image);
|
||||
std::string extra_image_data = std::string(inputs.extra_image);
|
||||
std::string sampler = inputs.sample_method;
|
||||
|
||||
if(!photomaker_enabled)
|
||||
{
|
||||
photomaker_image_data = "";
|
||||
}
|
||||
|
||||
sd_params->prompt = cleanprompt;
|
||||
sd_params->negative_prompt = cleannegprompt;
|
||||
sd_params->cfg_scale = inputs.cfg_scale;
|
||||
|
@ -508,17 +503,17 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||
|
||||
//for img2img
|
||||
sd_image_t input_image = {0,0,0,nullptr};
|
||||
sd_image_t photomaker_reference = {0,0,0,nullptr};
|
||||
sd_image_t extraimage_reference = {0,0,0,nullptr};
|
||||
std::vector<uint8_t> image_buffer;
|
||||
std::vector<uint8_t> image_mask_buffer;
|
||||
std::vector<uint8_t> photomaker_buffer;
|
||||
std::vector<uint8_t> extraimage_buffer;
|
||||
int nx, ny, nc;
|
||||
int img2imgW = sd_params->width; //for img2img input
|
||||
int img2imgH = sd_params->height;
|
||||
int img2imgC = 3; // Assuming RGB image
|
||||
std::vector<uint8_t> resized_image_buf(img2imgW * img2imgH * img2imgC);
|
||||
std::vector<uint8_t> resized_mask_buf(img2imgW * img2imgH * img2imgC);
|
||||
std::vector<uint8_t> resized_photomaker_buf(img2imgW * img2imgH * img2imgC);
|
||||
std::vector<uint8_t> resized_extraimage_buf(img2imgW * img2imgH * img2imgC);
|
||||
|
||||
std::string ts = get_timestamp_str();
|
||||
if(!sd_is_quiet)
|
||||
|
@ -563,35 +558,38 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||
sd_params->sample_method = sample_method_t::EULER_A;
|
||||
}
|
||||
|
||||
if(photomaker_image_data!="")
|
||||
if(extra_image_data!="")
|
||||
{
|
||||
if(input_photomaker_buffer!=nullptr) //just in time free old buffer
|
||||
if(input_extraimage_buffer!=nullptr) //just in time free old buffer
|
||||
{
|
||||
stbi_image_free(input_photomaker_buffer);
|
||||
input_photomaker_buffer = nullptr;
|
||||
stbi_image_free(input_extraimage_buffer);
|
||||
input_extraimage_buffer = nullptr;
|
||||
}
|
||||
int nx2, ny2, nc2;
|
||||
photomaker_buffer = kcpp_base64_decode(photomaker_image_data);
|
||||
input_photomaker_buffer = stbi_load_from_memory(photomaker_buffer.data(), photomaker_buffer.size(), &nx2, &ny2, &nc2, 1);
|
||||
extraimage_buffer = kcpp_base64_decode(extra_image_data);
|
||||
input_extraimage_buffer = stbi_load_from_memory(extraimage_buffer.data(), extraimage_buffer.size(), &nx2, &ny2, &nc2, 1);
|
||||
// Resize the image
|
||||
int resok = stbir_resize_uint8(input_photomaker_buffer, nx2, ny2, 0, resized_photomaker_buf.data(), img2imgW, img2imgH, 0, 1);
|
||||
int resok = stbir_resize_uint8(input_extraimage_buffer, nx2, ny2, 0, resized_extraimage_buf.data(), img2imgW, img2imgH, 0, 1);
|
||||
if (!resok) {
|
||||
printf("\nKCPP SD: resize photomaker image failed!\n");
|
||||
printf("\nKCPP SD: resize extra image failed!\n");
|
||||
output.data = "";
|
||||
output.status = 0;
|
||||
return output;
|
||||
}
|
||||
photomaker_reference.width = img2imgW;
|
||||
photomaker_reference.height = img2imgH;
|
||||
photomaker_reference.channel = img2imgC;
|
||||
photomaker_reference.data = resized_photomaker_buf.data();
|
||||
extraimage_reference.width = img2imgW;
|
||||
extraimage_reference.height = img2imgH;
|
||||
extraimage_reference.channel = img2imgC;
|
||||
extraimage_reference.data = resized_extraimage_buf.data();
|
||||
|
||||
//ensure prompt has img keyword, otherwise append it
|
||||
if (sd_params->prompt.find("img") == std::string::npos) {
|
||||
sd_params->prompt += " img";
|
||||
} else if (sd_params->prompt.rfind("img", 0) == 0) {
|
||||
// "img" found at the start of the string (position 0), which is not allowed. Add some text before it
|
||||
sd_params->prompt = "person " + sd_params->prompt;
|
||||
if(photomaker_enabled)
|
||||
{
|
||||
if (sd_params->prompt.find("img") == std::string::npos) {
|
||||
sd_params->prompt += " img";
|
||||
} else if (sd_params->prompt.rfind("img", 0) == 0) {
|
||||
// "img" found at the start of the string (position 0), which is not allowed. Add some text before it
|
||||
sd_params->prompt = "person " + sd_params->prompt;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -638,7 +636,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||
sd_params->slg_scale,
|
||||
sd_params->skip_layer_start,
|
||||
sd_params->skip_layer_end,
|
||||
(photomaker_image_data!=""?(&photomaker_reference):nullptr));
|
||||
(photomaker_enabled && extra_image_data!=""?(&extraimage_reference):nullptr));
|
||||
} else {
|
||||
|
||||
if (sd_params->width <= 0 || sd_params->width % 64 != 0 || sd_params->height <= 0 || sd_params->height % 64 != 0) {
|
||||
|
@ -762,7 +760,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||
sd_params->slg_scale,
|
||||
sd_params->skip_layer_start,
|
||||
sd_params->skip_layer_end,
|
||||
(photomaker_image_data!=""?(&photomaker_reference):nullptr));
|
||||
(photomaker_enabled && extra_image_data!=""?(&extraimage_reference):nullptr));
|
||||
}
|
||||
|
||||
if (results == NULL) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue