Skip to content

Commit d70214f

Browse files
committed
simplify image metadata generation
Use a stringstream to avoid the explicit conversions to string. Also, generate from the sd.cpp struct, to reduce dependencies on the global context fields.
1 parent fc3b771 commit d70214f

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

otherarch/sdcpp/sdtype_adapter.cpp

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
#include <time.h>
44
#include <iostream>
55
#include <random>
6+
#include <iomanip>
7+
#include <sstream>
68
#include <string>
79
#include <vector>
810

@@ -387,20 +389,21 @@ std::string clean_input_prompt(const std::string& input) {
387389
return result;
388390
}
389391

390-
static std::string get_image_params(const SDParams& params) {
391-
std::string parameter_string = "";
392-
parameter_string += "Prompt: " + params.prompt + " | ";
393-
parameter_string += "NegativePrompt: " + params.negative_prompt + " | ";
394-
parameter_string += "Steps: " + std::to_string(params.sample_steps) + " | ";
395-
parameter_string += "CFGScale: " + std::to_string(params.cfg_scale) + " | ";
396-
parameter_string += "Guidance: " + std::to_string(params.guidance) + " | ";
397-
parameter_string += "Seed: " + std::to_string(params.seed) + " | ";
398-
parameter_string += "Size: " + std::to_string(params.width) + "x" + std::to_string(params.height) + " | ";
399-
parameter_string += "Sampler: " + std::to_string((int)sd_params->sample_method) + " | ";
400-
parameter_string += "Clip skip: " + std::to_string((int)sd_params->clip_skip) + " | ";
401-
parameter_string += "Model: " + sdmodelfilename + " | ";
402-
parameter_string += "Version: KoboldCpp";
403-
return parameter_string;
392+
static std::string get_image_params(const sd_img_gen_params_t & params) {
393+
std::stringstream parameter_string;
394+
parameter_string << std::setprecision(3)
395+
<< "Prompt: " << params.prompt
396+
<< " | NegativePrompt: " << params.negative_prompt
397+
<< " | Steps: " << params.sample_steps
398+
<< " | CFGScale: " << params.guidance.txt_cfg
399+
<< " | Guidance: " << params.guidance.distilled_guidance
400+
<< " | Seed: " << params.seed
401+
<< " | Size: " << params.width << "x" << params.height
402+
<< " | Sampler: " << sd_sample_method_name(params.sample_method)
403+
<< " | Clip skip: " << params.clip_skip
404+
<< " | Model: " << sdmodelfilename
405+
<< " | Version: KoboldCpp";
406+
return parameter_string.str();
404407
}
405408

406409
static inline int rounddown_64(int n) {
@@ -930,7 +933,7 @@ sd_generation_outputs sdtype_generate(const sd_generation_inputs inputs)
930933
}
931934

932935
int out_data_len;
933-
unsigned char * 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(*sd_params).c_str());
936+
unsigned char * 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).c_str());
934937
if (png != NULL)
935938
{
936939
recent_data = kcpp_base64_encode(png,out_data_len);

0 commit comments

Comments
 (0)