feat(server): add ADetailer support to image generation (#2164)

This commit is contained in:
losewayy authored and GitHub committed 2026-10-21 23:11:36 +08:00
1 parent 0518b34374
commit 845646b034
10 files changed
+515 -61

No files matched your search

+4
View File
@@ -244,6 +244,10 @@ bool execute_img_gen_job(ServerRuntime& runtime,
}
clear_preview_callback();
results.adopt(raw_results, num_results);
if (!results.empty() && !apply_server_adetailer(runtime, job.img_gen, params, results)) {
error_message = "ADetailer failed";
return false;
}
}
const int num_results = results.count();
+20 -16
View File
@@ -75,7 +75,7 @@ static bool build_openai_generation_request(const httplib::Request& req,
error_message = "invalid params";
return false;
}
return true;
return validate_server_img_gen_request(runtime, request, error_message);
}
static bool build_openai_edit_request(const httplib::Request& req,
@@ -158,22 +158,22 @@ static bool build_openai_edit_request(const httplib::Request& req,
request.gen_params.height = height;
request.gen_params.batch_count = n;
std::string sd_cpp_extra_args_str = extract_and_remove_sd_cpp_extra_args(request.gen_params.prompt);
const json extra_args = sd_cpp_extra_args_str.empty()
? json::object()
: json::parse(sd_cpp_extra_args_str, nullptr, false);
const bool has_extra_init_image_override = extra_args.is_object() && extra_args.contains("init_image");
const bool has_extra_ref_images_override = extra_args.is_object() && extra_args.contains("ref_images");
const bool has_extra_strength_override = extra_args.is_object() &&
extra_args.contains("strength") &&
extra_args["strength"].is_number();
const bool has_extra_mask_image = extra_args.is_object() &&
extra_args.contains("mask_image") &&
!extra_args["mask_image"].is_null();
std::string sd_cpp_extra_args_str = extract_and_remove_sd_cpp_extra_args(request.gen_params.prompt);
const json extra_args = sd_cpp_extra_args_str.empty()
? json::object()
: json::parse(sd_cpp_extra_args_str, nullptr, false);
const bool has_extra_init_image_override = extra_args.is_object() && extra_args.contains("init_image");
const bool has_extra_ref_images_override = extra_args.is_object() && extra_args.contains("ref_images");
const bool has_extra_strength_override = extra_args.is_object() &&
extra_args.contains("strength") &&
extra_args["strength"].is_number();
const bool has_extra_mask_image = extra_args.is_object() &&
extra_args.contains("mask_image") &&
!extra_args["mask_image"].is_null();
const bool supports_ref_image_conditioning = sd_ctx_supports_ref_image_conditioning(runtime.sd_ctx);
const bool may_need_uploaded_init_image = !has_extra_init_image_override &&
(!supports_ref_image_conditioning || !mask_bytes.empty() ||
has_extra_mask_image || has_extra_strength_override || has_extra_ref_images_override);
(!supports_ref_image_conditioning || !mask_bytes.empty() ||
has_extra_mask_image || has_extra_strength_override || has_extra_ref_images_override);
SDImageOwner uploaded_image_for_init;
bool uploaded_image_was_first_reference = false;
for (auto& bytes : images_bytes) {
@@ -252,7 +252,7 @@ static bool build_openai_edit_request(const httplib::Request& req,
return false;
}
return true;
return validate_server_img_gen_request(runtime, request, error_message);
}
static bool execute_sync_img_gen_request(ServerRuntime& runtime,
@@ -270,6 +270,10 @@ static bool execute_sync_img_gen_request(ServerRuntime& runtime,
num_results = 0;
}
results.adopt(raw_results, num_results);
if (!results.empty() && !apply_server_adetailer(runtime, request, img_gen_params, results)) {
error_message = "ADetailer failed";
return false;
}
}
if (results.empty()) {
+221 -4
View File
@@ -3,9 +3,12 @@
#include <algorithm>
#include <cctype>
#include <cstring>
#include <limits>
#include <regex>
#include <stdexcept>
#include <string_view>
#include <unordered_map>
#include <unordered_set>
#include "common/common.h"
#include "common/media_io.h"
@@ -81,6 +84,202 @@ static enum sample_method_t get_sdapi_sample_method(std::string name) {
return it != hardcoded.end() ? it->second : SAMPLE_METHOD_COUNT;
}
static bool parse_sdapi_adetailer(const json& body,
ServerRuntime& runtime,
bool img2img,
ImgGenJobRequest& request,
std::string& error_message) {
request.adetailer_enabled = false;
request.adetailer_passes.clear();
if (!body.contains("alwayson_scripts")) {
return true;
}
try {
const auto& scripts = body.at("alwayson_scripts");
if (!scripts.is_object()) {
throw std::invalid_argument("alwayson_scripts must be an object");
}
if (!scripts.contains("ADetailer")) {
return true;
}
const auto& args = scripts.at("ADetailer").at("args");
if (!args.is_array()) {
throw std::invalid_argument("ADetailer.args must be an array");
}
if (args.empty() || (args[0].is_boolean() && !args[0].get<bool>())) {
return true;
}
static const std::unordered_set<std::string> keys = {
"ad_model", "ad_model_classes", "ad_tab_enable", "ad_prompt", "ad_negative_prompt",
"ad_confidence", "ad_mask_filter_method", "ad_mask_k", "ad_mask_min_ratio", "ad_mask_max_ratio",
"ad_dilate_erode", "ad_x_offset", "ad_y_offset", "ad_mask_merge_invert", "ad_mask_blur",
"ad_denoising_strength", "ad_inpaint_only_masked", "ad_inpaint_only_masked_padding",
"ad_use_inpaint_width_height", "ad_inpaint_width", "ad_inpaint_height", "ad_use_steps", "ad_steps",
"ad_use_cfg_scale", "ad_cfg_scale", "ad_use_sampler", "ad_sampler", "ad_scheduler",
"ad_use_checkpoint", "ad_checkpoint", "ad_use_vae", "ad_vae", "ad_use_noise_multiplier",
"ad_noise_multiplier", "ad_use_clip_skip", "ad_clip_skip", "ad_restore_face", "ad_controlnet_model",
"ad_controlnet_module", "ad_controlnet_weight", "ad_controlnet_guidance_start", "ad_controlnet_guidance_end", "is_api"};
for (const auto& config : args) {
if (!config.is_object()) {
continue;
}
auto boolean = [&](const char* key, bool fallback) {
if (!config.contains(key))
return fallback;
if (!config.at(key).is_boolean())
throw std::invalid_argument(std::string(key) + " must be boolean");
return config.at(key).get<bool>();
};
auto text = [&](const char* key, const char* fallback) {
if (!config.contains(key))
return std::string(fallback);
if (!config.at(key).is_string())
throw std::invalid_argument(std::string(key) + " must be a string");
return config.at(key).get<std::string>();
};
auto number = [&](const char* key, double fallback, double minimum, double maximum) {
double value = fallback;
if (config.contains(key)) {
if (!config.at(key).is_number())
throw std::invalid_argument(std::string(key) + " must be numeric");
value = config.at(key).get<double>();
}
if (!std::isfinite(value) || value < minimum || value > maximum)
throw std::invalid_argument(std::string(key) + " is out of range");
return value;
};
auto integer = [&](const char* key, int fallback, int minimum, int maximum = std::numeric_limits<int>::max()) {
if (config.contains(key) && !config.at(key).is_number_integer())
throw std::invalid_argument(std::string(key) + " must be an integer");
return static_cast<int>(number(key, fallback, minimum, maximum));
};
const std::string model = text("ad_model", "None");
if (model == "None" || !boolean("ad_tab_enable", true)) {
continue;
}
for (const auto& item : config.items()) {
if (keys.count(item.key()) == 0)
throw std::invalid_argument("unsupported ADetailer setting: " + item.key());
}
const auto& configured = runtime.default_gen_params->ad_model_path;
if (configured.empty())
throw std::invalid_argument("ADetailer requires a server-configured --ad-model");
const auto path = fs::u8path(configured);
if (model.find_first_of("/\\") != std::string::npos ||
(lower_ascii(model) != lower_ascii(path.filename().u8string()) && lower_ascii(model) != lower_ascii(path.stem().u8string() + ".pt"))) {
throw std::invalid_argument("ADetailer model must match the server-configured detector");
}
if (!text("ad_model_classes", "").empty())
throw std::invalid_argument("ad_model_classes is not supported");
if (boolean("ad_use_checkpoint", false)) {
const auto checkpoint = config.contains("ad_checkpoint") && config.at("ad_checkpoint").is_null() ? "" : text("ad_checkpoint", "Use same checkpoint");
if (!checkpoint.empty() && checkpoint != "None" && checkpoint != "Use same checkpoint")
throw std::invalid_argument("ADetailer checkpoint switching is not supported");
}
if (boolean("ad_use_vae", false)) {
const auto vae = config.contains("ad_vae") && config.at("ad_vae").is_null() ? "" : text("ad_vae", "Use same VAE");
if (!vae.empty() && vae != "None" && vae != "Use same VAE")
throw std::invalid_argument("ADetailer VAE switching is not supported");
}
if (boolean("ad_use_noise_multiplier", false) && number("ad_noise_multiplier", 1, 0.5, 1.5) != 1)
throw std::invalid_argument("ADetailer noise multiplier is not supported");
if (boolean("ad_restore_face", false))
throw std::invalid_argument("ADetailer face restoration is not supported");
if (text("ad_controlnet_model", "None") != "None")
throw std::invalid_argument("ADetailer ControlNet is not supported");
ServerADetailerPass pass;
pass.prompt = text("ad_prompt", "");
pass.negative_prompt = text("ad_negative_prompt", "");
pass.width = request.gen_params.get_resolved_width();
pass.height = request.gen_params.get_resolved_height();
pass.strength = static_cast<float>(number("ad_denoising_strength", 0.4, 0, 1));
auto append = [&](const char* key, const std::string& value) {
if (!pass.extra_args.empty())
pass.extra_args += ",";
pass.extra_args += std::string(key) + "=" + value;
};
auto append_number = [&](const char* target, const char* key, double fallback, double minimum, double maximum) {
append(target, json(number(key, fallback, minimum, maximum)).dump());
};
auto append_integer = [&](const char* target, const char* key, int fallback, int minimum, int maximum = std::numeric_limits<int>::max()) {
append(target, std::to_string(integer(key, fallback, minimum, maximum)));
};
append_number("confidence", "ad_confidence", 0.3, 0, 1);
append_integer("mask_k_largest", "ad_mask_k", 0, 0);
const auto filter = text("ad_mask_filter_method", "Area");
if (filter != "Area" && filter != "Confidence")
throw std::invalid_argument("invalid ad_mask_filter_method");
append("mask_filter_method", lower_ascii(filter));
const auto min_ratio = number("ad_mask_min_ratio", 0, 0, 1);
const auto max_ratio = number("ad_mask_max_ratio", 1, 0, 1);
if (min_ratio > max_ratio)
throw std::invalid_argument("ad_mask_min_ratio exceeds ad_mask_max_ratio");
append("mask_min_ratio", json(min_ratio).dump());
append("mask_max_ratio", json(max_ratio).dump());
// Bound pixel operations before converting them to the native mask parameters.
const int mask_limit = std::clamp(std::max(pass.width, pass.height), 32, 16384);
append_integer("dilate_erode", "ad_dilate_erode", 4, -mask_limit, mask_limit);
append_integer("x_offset", "ad_x_offset", 0, -mask_limit, mask_limit);
append_integer("y_offset", "ad_y_offset", 0, -mask_limit, mask_limit);
append_integer("mask_blur", "ad_mask_blur", 4, 0, mask_limit);
append_integer("inpaint_padding", "ad_inpaint_only_masked_padding", 32, 0, mask_limit);
append("inpaint_only_masked", boolean("ad_inpaint_only_masked", true) ? "true" : "false");
const auto merge = text("ad_mask_merge_invert", "None");
if (merge != "None" && merge != "Merge" && merge != "Merge and Invert")
throw std::invalid_argument("invalid ad_mask_merge_invert");
append("mask_mode", merge == "None" ? "none" : merge == "Merge" ? "merge"
: "merge_invert");
if (boolean("ad_use_inpaint_width_height", false)) {
pass.width = integer("ad_inpaint_width", 512, 1, k_max_generation_dimension);
pass.height = integer("ad_inpaint_height", 512, 1, k_max_generation_dimension);
}
if (boolean("ad_use_steps", false))
append_integer("steps", "ad_steps", 28, 1, k_max_adetailer_steps);
if (boolean("ad_use_cfg_scale", false))
append_number("cfg_scale", "ad_cfg_scale", 7, 0, std::numeric_limits<float>::max());
if (boolean("ad_use_clip_skip", false)) {
pass.clip_skip = integer("ad_clip_skip", 1, 1);
if (pass.clip_skip > 12)
throw std::invalid_argument("ad_clip_skip is out of range");
}
if (boolean("ad_use_sampler", false)) {
std::string sampler = text("ad_sampler", "DPM++ 2M Karras");
if (sampler != "Use same sampler") {
const std::string suffix = " karras";
const bool legacy_karras = sampler.size() > suffix.size() && lower_ascii(sampler.substr(sampler.size() - suffix.size())) == suffix;
if (legacy_karras)
sampler.resize(sampler.size() - suffix.size());
const auto method = get_sdapi_sample_method(sampler);
if (method == SAMPLE_METHOD_COUNT)
throw std::invalid_argument("unsupported ADetailer sampler");
append("sample_method", sd_sample_method_name(method));
if (legacy_karras && text("ad_scheduler", "Use same scheduler") == "Use same scheduler")
append("scheduler", sd_scheduler_name(KARRAS_SCHEDULER));
}
const auto scheduler = text("ad_scheduler", "Use same scheduler");
if (scheduler == "Automatic") {
pass.automatic_scheduler = true;
} else if (scheduler != "Use same scheduler") {
const auto value = str_to_scheduler(scheduler.c_str());
if (value == SCHEDULER_COUNT)
throw std::invalid_argument("unsupported ADetailer scheduler");
append("scheduler", sd_scheduler_name(value));
}
}
request.adetailer_passes.push_back(std::move(pass));
}
if (!request.adetailer_passes.empty() && img2img && args.size() > 1 && args[1].is_boolean() && args[1].get<bool>()) {
throw std::invalid_argument("ADetailer skip img2img is not supported");
}
request.adetailer_enabled = !request.adetailer_passes.empty();
return true;
} catch (const std::exception& error) {
error_message = std::string("invalid ADetailer args: ") + error.what();
return false;
}
}
static bool build_sdapi_img_gen_request(const json& j,
ServerRuntime& runtime,
bool img2img,
@@ -259,7 +458,8 @@ static bool build_sdapi_img_gen_request(const json& j,
return false;
}
return true;
return parse_sdapi_adetailer(j, runtime, img2img, request, error_message) &&
validate_server_img_gen_request(runtime, request, error_message);
}
static nlohmann::json prepare_info_field(const SDContextParams& ctx_params,
@@ -349,7 +549,7 @@ static void preview_callback(int step, int frame_count, sd_image_t* frames, bool
}
struct SDAPIPreviewGuard {
SDAPIPreviewGuard(const std::string& id_task, const sd_img_gen_params_t& params, const std::string& job_type) {
SDAPIPreviewGuard(const std::string& id_task, const sd_img_gen_params_t& params, const std::string& job_type, bool detailing = false) {
std::lock_guard<std::mutex> lock(g_preview.mutex);
g_preview.id_task = id_task;
g_preview.total = 0;
@@ -358,11 +558,20 @@ struct SDAPIPreviewGuard {
g_preview.step = 0;
g_preview.active = true;
// Each batch item has a base pass and, when enabled, a hires pass.
g_preview.job_count = static_cast<int64_t>(std::max(1, params.batch_count)) * (params.hires.enabled ? 2 : 1);
g_preview.job_count = static_cast<int64_t>(std::max(1, params.batch_count)) * (params.hires.enabled ? 2 : 1) + (detailing ? 1 : 0);
g_preview.job_no = 0;
sd_set_preview_callback(preview_callback, PREVIEW_PROJ, 1, true, false, nullptr);
}
void begin_detailing() {
sd_set_preview_callback(nullptr, PREVIEW_NONE, 1, false, false, nullptr);
std::lock_guard<std::mutex> lock(g_preview.mutex);
g_preview.job_type = "adetailer";
g_preview.job_no = static_cast<int>(g_preview.job_count - 1);
g_preview.step = 0;
g_preview.total = 0;
}
~SDAPIPreviewGuard() {
sd_set_preview_callback(nullptr, PREVIEW_NONE, 1, false, false, nullptr);
std::lock_guard<std::mutex> lock(g_preview.mutex);
@@ -410,13 +619,21 @@ void register_sdapi_endpoints(httplib::Server& svr, ServerRuntime& rt) {
{
std::lock_guard<std::mutex> lock(*runtime->sd_ctx_mutex);
SDAPIPreviewGuard preview_guard(id_task, img_gen_params, img2img ? "img2img" : "txt2img");
const bool detailing = request.adetailer_enabled && !runtime->default_gen_params->ad_model_path.empty();
SDAPIPreviewGuard preview_guard(id_task, img_gen_params, img2img ? "img2img" : "txt2img", detailing);
sd_image_t* raw_results = nullptr;
if (!generate_image(runtime->sd_ctx, &img_gen_params, &raw_results, &num_results)) {
raw_results = nullptr;
num_results = 0;
}
results.adopt(raw_results, num_results);
if (detailing && !results.empty())
preview_guard.begin_detailing();
if (!results.empty() && !apply_server_adetailer(*runtime, request, img_gen_params, results)) {
res.status = 500;
res.set_content(R"({"error":"ADetailer failed"})", "application/json");
return;
}
}
if (results.empty()) {
+3 -3
View File
@@ -410,9 +410,9 @@ static json make_capabilities_json(ServerRuntime& runtime) {
result["defaults_by_mode"] = defaults_by_mode;
result["limits"] = {
{"min_width", 64},
{"max_width", 4096},
{"max_width", k_max_generation_dimension},
{"min_height", 64},
{"max_height", 4096},
{"max_height", k_max_generation_dimension},
{"max_batch_count", 8},
{"max_queue_size", manager.max_pending_jobs},
{"max_upscale_width", k_max_upscale_dimension},
@@ -457,7 +457,7 @@ static bool parse_img_gen_request(const json& body,
error_message = "invalid generation parameters";
return false;
}
return true;
return validate_server_img_gen_request(runtime, request, error_message);
}
static bool parse_vid_gen_request(const json& body,
+152
View File
@@ -3,6 +3,7 @@
#include <algorithm>
#include <cctype>
#include <chrono>
#include <cmath>
#include <cstdlib>
#include <filesystem>
#include <mutex>
@@ -18,6 +19,157 @@
namespace fs = std::filesystem;
bool validate_server_img_gen_request(const ServerRuntime& runtime,
const ImgGenJobRequest& request,
std::string& error_message) {
auto dimensions_valid = [&](double width, double height) {
if (!std::isfinite(width) || !std::isfinite(height) ||
width < 1 || height < 1 || width > k_max_generation_dimension || height > k_max_generation_dimension) {
error_message = "generation width and height must be between 1 and " + std::to_string(k_max_generation_dimension);
return false;
}
return true;
};
const auto& params = request.gen_params;
const int width = params.get_resolved_width();
const int height = params.get_resolved_height();
if (!dimensions_valid(width, height)) {
return false;
}
if (params.hires_enabled) {
const double hires_width = params.hires_width > 0 ? params.hires_width : params.hires_height > 0 ? params.hires_height
: std::round(width * params.hires_scale);
const double hires_height = params.hires_height > 0 ? params.hires_height : params.hires_width > 0 ? params.hires_width
: std::round(height * params.hires_scale);
if (!dimensions_valid(hires_width, hires_height)) {
return false;
}
}
if (!request.adetailer_enabled || runtime.default_gen_params->ad_model_path.empty()) {
return true;
}
auto pass_valid = [&](const ServerADetailerPass& pass) {
if (!dimensions_valid(pass.width, pass.height)) {
return false;
}
// Match the native key normalization, but leave full option parsing to ADetailer.
auto trim = [](const std::string& text) {
const auto first = text.find_first_not_of(" \t\r\n");
return first == std::string::npos ? std::string() : text.substr(first, text.find_last_not_of(" \t\r\n") - first + 1);
};
std::stringstream stream(pass.extra_args);
std::string item;
while (std::getline(stream, item, ',')) {
const auto equals = item.find('=');
if (equals == std::string::npos) {
continue;
}
auto key = trim(item.substr(0, equals));
std::transform(key.begin(), key.end(), key.begin(), [](unsigned char c) { return static_cast<char>(std::tolower(c)); });
if (key != "inpaint_width" && key != "inpaint_height" && key != "steps") {
continue;
}
const auto value = trim(item.substr(equals + 1));
const int minimum = key == "steps" ? 0 : 1;
const int maximum = key == "steps" ? k_max_adetailer_steps : k_max_generation_dimension;
try {
size_t used = 0;
const int parsed = std::stoi(value, &used);
if (used == value.size() && parsed >= minimum && parsed <= maximum) {
continue;
}
} catch (const std::exception&) {
}
error_message = "ADetailer " + key + " must be between " + std::to_string(minimum) + " and " + std::to_string(maximum);
return false;
}
return true;
};
if (request.adetailer_passes.empty()) {
ServerADetailerPass pass;
pass.extra_args = params.extra_ad_args;
return pass_valid(pass);
}
return std::all_of(request.adetailer_passes.begin(), request.adetailer_passes.end(), pass_valid);
}
bool apply_server_adetailer(ServerRuntime& runtime,
const ImgGenJobRequest& request,
const sd_img_gen_params_t& params,
SDImageVec& results) {
const auto& gen_params = request.gen_params;
const auto& ad_model_path = runtime.default_gen_params->ad_model_path;
if (!request.adetailer_enabled || ad_model_path.empty()) {
return true;
}
std::string error_message;
if (!validate_server_img_gen_request(runtime, request, error_message)) {
LOG_ERROR("%s", error_message.c_str());
return false;
}
std::vector<ServerADetailerPass> passes = request.adetailer_passes;
if (passes.empty()) {
ServerADetailerPass pass;
pass.prompt = gen_params.ad_prompt;
pass.negative_prompt = gen_params.ad_negative_prompt;
pass.extra_args = gen_params.extra_ad_args;
passes.push_back(std::move(pass));
}
ADetailerCtxPtr ad_ctx(new_adetailer_ctx(ad_model_path.c_str(),
runtime.ctx_params->n_threads,
runtime.ctx_params->effective_backend.c_str(),
runtime.ctx_params->effective_params_backend.c_str()));
if (ad_ctx == nullptr) {
LOG_ERROR("new_adetailer_ctx failed");
return false;
}
for (const auto& pass : passes) {
sd_adetailer_params_t ad_params{};
ad_params.prompt = pass.prompt.empty() ? nullptr : pass.prompt.c_str();
ad_params.negative_prompt = pass.negative_prompt.empty() ? nullptr : pass.negative_prompt.c_str();
ad_params.extra_ad_args = pass.extra_args.c_str();
for (int i = 0; i < results.count(); ++i) {
if (results[i].data == nullptr) {
continue;
}
sd_img_gen_params_t ad_generation_params = params;
ad_generation_params.seed = params.seed + i;
ad_generation_params.width = pass.width;
ad_generation_params.height = pass.height;
ad_generation_params.strength = pass.strength;
if (pass.clip_skip > 0) {
ad_generation_params.clip_skip = pass.clip_skip;
}
if (pass.automatic_scheduler) {
ad_generation_params.sample_params.scheduler = SCHEDULER_COUNT;
}
sd_image_t* detailed_images = nullptr;
int detailed_count = 0;
if (!adetail_image(ad_ctx.get(),
runtime.sd_ctx,
results[i],
&ad_params,
&ad_generation_params,
&detailed_images,
&detailed_count) ||
detailed_count <= 0 || detailed_images == nullptr || detailed_images[0].data == nullptr) {
free_sd_images(detailed_images, detailed_count);
LOG_ERROR("ADetailer failed for image %d", i + 1);
return false;
}
free(results[i].data);
results[i] = detailed_images[0];
detailed_images[0] = {0, 0, 0, nullptr};
free_sd_images(detailed_images, detailed_count);
}
}
return true;
}
static std::string lower_ascii(std::string value) {
std::transform(value.begin(), value.end(), value.begin(), [](unsigned char c) {
return static_cast<char>(std::tolower(c));
+24
View File
@@ -67,18 +67,38 @@ struct ServerRuntime {
ServerModels* models;
};
struct ServerADetailerPass {
std::string prompt;
std::string negative_prompt;
std::string extra_args;
int width = 512;
int height = 512;
float strength = 0.4f;
int clip_skip = -1;
bool automatic_scheduler = false;
};
struct ImgGenJobRequest {
SDGenerationParams gen_params;
std::string output_format = "png";
int output_compression = 100;
std::string preview_mode = "none";
int preview_interval = 1;
bool adetailer_enabled = true;
std::vector<ServerADetailerPass> adetailer_passes;
sd_img_gen_params_t to_sd_img_gen_params_t() {
return gen_params.to_sd_img_gen_params_t();
}
};
constexpr int k_max_generation_dimension = 4096;
constexpr int k_max_adetailer_steps = 100;
bool validate_server_img_gen_request(const ServerRuntime& runtime,
const ImgGenJobRequest& request,
std::string& error_message);
struct VidGenJobRequest {
SDGenerationParams gen_params;
std::string output_format = "webm";
@@ -111,3 +131,7 @@ void refresh_lora_cache(ServerRuntime& rt);
std::string get_lora_full_path(ServerRuntime& rt, const std::string& path);
void refresh_upscaler_cache(ServerRuntime& rt);
int64_t unix_timestamp_now_ms();
bool apply_server_adetailer(ServerRuntime& runtime,
const ImgGenJobRequest& request,
const sd_img_gen_params_t& params,
SDImageVec& results);