mirror of
https://github.com/LostRuins/koboldcpp.git
synced 2026-09-19 09:15:18 +02:00
passthrough mode without any gens
This commit is contained in:
@@ -956,7 +956,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||||||
output.status = 0;
|
output.status = 0;
|
||||||
return output;
|
return output;
|
||||||
}
|
}
|
||||||
sd_image_t * results;
|
sd_image_t * results = nullptr;
|
||||||
|
|
||||||
//sanitize prompts, remove quotes and limit lengths
|
//sanitize prompts, remove quotes and limit lengths
|
||||||
std::string cleanprompt = clean_input_prompt(inputs.prompt);
|
std::string cleanprompt = clean_input_prompt(inputs.prompt);
|
||||||
@@ -1264,6 +1264,9 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||||||
int generated_num_results = 1;
|
int generated_num_results = 1;
|
||||||
remove_limits = inputs.remove_limits;
|
remove_limits = inputs.remove_limits;
|
||||||
|
|
||||||
|
//special case, is img2img and denoise strength is 0 and steps is 1, do a passthru
|
||||||
|
bool is_passthrough = (sd_params->sample_steps<=1 && sd_params->strength<=0 && is_img2img && vid_req_frames<=1 && extra_image_data.size()==0);
|
||||||
|
|
||||||
if(is_vid_model)
|
if(is_vid_model)
|
||||||
{
|
{
|
||||||
std::vector<sd_image_t> control_frames; //empty for now
|
std::vector<sd_image_t> control_frames; //empty for now
|
||||||
@@ -1398,11 +1401,14 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||||||
|
|
||||||
fflush(stdout);
|
fflush(stdout);
|
||||||
|
|
||||||
results = generate_image(sd_ctx, ¶ms);
|
if (is_passthrough) {
|
||||||
|
printf("No generation triggered, passthrough mode.\n");
|
||||||
|
} else {
|
||||||
|
results = generate_image(sd_ctx, ¶ms);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (results == NULL) {
|
if (!is_passthrough && results == NULL) {
|
||||||
printf("\nKCPP SD generate failed!\n");
|
printf("\nKCPP SD generate failed!\n");
|
||||||
output.data = "";
|
output.data = "";
|
||||||
output.data_extra = "";
|
output.data_extra = "";
|
||||||
@@ -1415,94 +1421,108 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
|
|||||||
sd_image_t upscaled_image;
|
sd_image_t upscaled_image;
|
||||||
upscaled_image.data = nullptr;
|
upscaled_image.data = nullptr;
|
||||||
|
|
||||||
for (int i = 0; i < params.batch_count; i++) {
|
if (is_passthrough)
|
||||||
if (results[i].data == NULL) {
|
{
|
||||||
continue;
|
//either return original image or upscale if needed
|
||||||
}
|
int out_data_len;
|
||||||
|
unsigned char * png = nullptr;
|
||||||
//if multiframe, make a video
|
if(inputs.upscale && upscaler_ctx != nullptr)
|
||||||
if(vid_req_frames>1 && generated_num_results>1 && is_vid_model)
|
|
||||||
{
|
{
|
||||||
if(!sd_is_quiet && sddebugmode==1)
|
printf("Upscaling original image (passthrough)...\n");
|
||||||
{
|
upscaled_image = upscale(upscaler_ctx, input_image, 2);
|
||||||
printf("\nSaving video buffer, VIDEO_OUTPUT_TYPE=%d...",video_output_type);
|
png = stbi_write_png_to_mem(upscaled_image.data, 0, upscaled_image.width, upscaled_image.height, upscaled_image.channel, &out_data_len, get_image_params(params, lora_meta).c_str());
|
||||||
}
|
} else {
|
||||||
uint8_t * out_data = nullptr;
|
png = stbi_write_png_to_mem(input_image.data, 0, input_image.width, input_image.height, input_image.channel, &out_data_len, get_image_params(params, lora_meta).c_str());
|
||||||
uint8_t * out_data2 = nullptr;
|
}
|
||||||
size_t out_len = 0;
|
if (png != NULL)
|
||||||
size_t out_len2 = 0;
|
{
|
||||||
int status = 0;
|
recent_data = kcpp_base64_encode(png,out_data_len);
|
||||||
int status2 = 0;
|
|
||||||
wasanim = true;
|
|
||||||
|
|
||||||
if(video_output_type==0 || video_output_type==2)
|
|
||||||
{
|
|
||||||
status = create_gif_buf_from_sd_images_msf(results, generated_num_results, 16, &out_data,&out_len);
|
|
||||||
}
|
|
||||||
if(video_output_type==1 || video_output_type==2)
|
|
||||||
{
|
|
||||||
status2 = create_mjpg_avi_membuf_from_sd_images(results, generated_num_results, 16, 40, &out_data2,&out_len2);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!sd_is_quiet && sddebugmode==1)
|
|
||||||
{
|
|
||||||
printf("Video Output Sizes: GIF=%zu AVI=%zu\n",out_len,out_len2);
|
|
||||||
if(status==0 && status2==0)
|
|
||||||
{
|
|
||||||
printf("Video(s) Saved (Len %zu)!\n",out_len);
|
|
||||||
} else {
|
|
||||||
printf("Save Failed!\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
recent_data = "";
|
|
||||||
recent_data2 = "";
|
recent_data2 = "";
|
||||||
if(status==0 && out_len>0)
|
free(png);
|
||||||
{
|
|
||||||
recent_data = kcpp_base64_encode(out_data, out_len);
|
|
||||||
free(out_data);
|
|
||||||
}
|
|
||||||
if (status2 == 0 && out_len2 > 0) {
|
|
||||||
if (recent_data == "") {
|
|
||||||
recent_data = kcpp_base64_encode(out_data2, out_len2);
|
|
||||||
} else {
|
|
||||||
recent_data2 = kcpp_base64_encode(out_data2, out_len2);
|
|
||||||
}
|
|
||||||
free(out_data2);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
for (int i = 0; i < params.batch_count; i++)
|
||||||
{
|
{
|
||||||
int out_data_len;
|
if (results[i].data == NULL) {
|
||||||
unsigned char * png = nullptr;
|
continue;
|
||||||
if(inputs.upscale && upscaler_ctx != nullptr)
|
}
|
||||||
|
|
||||||
|
//if multiframe, make a video
|
||||||
|
if(vid_req_frames>1 && generated_num_results>1 && is_vid_model)
|
||||||
{
|
{
|
||||||
//special case, is img2img and denoise strength is 0 and steps is 1, do a passthru
|
if(!sd_is_quiet && sddebugmode==1)
|
||||||
if(sd_params->sample_steps<=1 && sd_params->strength<=0 && is_img2img && extra_image_data.size()==0)
|
|
||||||
{
|
{
|
||||||
printf("Upscaling input image (passthrough mode)...\n");
|
printf("\nSaving video buffer, VIDEO_OUTPUT_TYPE=%d...",video_output_type);
|
||||||
upscaled_image = upscale(upscaler_ctx, input_image, 2);
|
|
||||||
}
|
}
|
||||||
else
|
uint8_t * out_data = nullptr;
|
||||||
|
uint8_t * out_data2 = nullptr;
|
||||||
|
size_t out_len = 0;
|
||||||
|
size_t out_len2 = 0;
|
||||||
|
int status = 0;
|
||||||
|
int status2 = 0;
|
||||||
|
wasanim = true;
|
||||||
|
|
||||||
|
if(video_output_type==0 || video_output_type==2)
|
||||||
|
{
|
||||||
|
status = create_gif_buf_from_sd_images_msf(results, generated_num_results, 16, &out_data,&out_len);
|
||||||
|
}
|
||||||
|
if(video_output_type==1 || video_output_type==2)
|
||||||
|
{
|
||||||
|
status2 = create_mjpg_avi_membuf_from_sd_images(results, generated_num_results, 16, 40, &out_data2,&out_len2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!sd_is_quiet && sddebugmode==1)
|
||||||
|
{
|
||||||
|
printf("Video Output Sizes: GIF=%zu AVI=%zu\n",out_len,out_len2);
|
||||||
|
if(status==0 && status2==0)
|
||||||
|
{
|
||||||
|
printf("Video(s) Saved (Len %zu)!\n",out_len);
|
||||||
|
} else {
|
||||||
|
printf("Save Failed!\n");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recent_data = "";
|
||||||
|
recent_data2 = "";
|
||||||
|
if(status==0 && out_len>0)
|
||||||
|
{
|
||||||
|
recent_data = kcpp_base64_encode(out_data, out_len);
|
||||||
|
free(out_data);
|
||||||
|
}
|
||||||
|
if (status2 == 0 && out_len2 > 0) {
|
||||||
|
if (recent_data == "") {
|
||||||
|
recent_data = kcpp_base64_encode(out_data2, out_len2);
|
||||||
|
} else {
|
||||||
|
recent_data2 = kcpp_base64_encode(out_data2, out_len2);
|
||||||
|
}
|
||||||
|
free(out_data2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
int out_data_len;
|
||||||
|
unsigned char * png = nullptr;
|
||||||
|
if(inputs.upscale && upscaler_ctx != nullptr)
|
||||||
{
|
{
|
||||||
printf("Upscaling output image...\n");
|
printf("Upscaling output image...\n");
|
||||||
upscaled_image = upscale(upscaler_ctx, results[i], 2);
|
upscaled_image = upscale(upscaler_ctx, results[i], 2);
|
||||||
|
png = stbi_write_png_to_mem(upscaled_image.data, 0, upscaled_image.width, upscaled_image.height, upscaled_image.channel, &out_data_len, nullptr);
|
||||||
|
} else {
|
||||||
|
png = stbi_write_png_to_mem(results[i].data, 0, results[i].width, results[i].height, results[i].channel, &out_data_len, nullptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
png = stbi_write_png_to_mem(upscaled_image.data, 0, upscaled_image.width, upscaled_image.height, upscaled_image.channel, &out_data_len, get_image_params(params, lora_meta).c_str());
|
if (png != NULL)
|
||||||
} else {
|
{
|
||||||
png = stbi_write_png_to_mem(results[i].data, 0, results[i].width, results[i].height, results[i].channel, &out_data_len, get_image_params(params, lora_meta).c_str());
|
recent_data = kcpp_base64_encode(png,out_data_len);
|
||||||
|
recent_data2 = "";
|
||||||
|
free(png);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (png != NULL)
|
free(results[i].data);
|
||||||
{
|
results[i].data = NULL;
|
||||||
recent_data = kcpp_base64_encode(png,out_data_len);
|
|
||||||
recent_data2 = "";
|
|
||||||
free(png);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
free(results[i].data);
|
|
||||||
results[i].data = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if(upscaled_image.data)
|
if(upscaled_image.data)
|
||||||
|
|||||||
Reference in New Issue
Block a user