feat: support stable horde restore faces

This commit is contained in:
Maiko Tan 2023-01-09 19:11:14 +08:00
parent ac3b6e64fc
commit d7bde353fd
No known key found for this signature in database
GPG Key ID: 0F3B49C721E5F453
2 changed files with 12 additions and 3 deletions

View File

@ -156,7 +156,7 @@ interface ParamConfig {
textSteps?: number
imageSteps?: number
maxSteps?: number
restoreFaces?: boolean
restoreFaces?: 'CodeFormer' | 'GFPGAN' | boolean
hiresFix?: boolean
}
@ -248,6 +248,11 @@ export const Config = Schema.intersect([
type: Schema.const('stable-horde'),
sampler: sampler.createSchema(sampler.horde),
model: Schema.union(hordeModels),
restoreFaces: Schema.union([
Schema.const(false).description('禁用'),
Schema.const('CodeFormer').description('使用 CodeFormer'),
Schema.const('GFPGAN').description('使用 GFPGAN'),
]).description('是否启用人脸修复。').default(false),
}),
Schema.object({
type: Schema.const('naifu'),

View File

@ -270,7 +270,7 @@ export function apply(ctx: Context, config: Config) {
return {
sampler_index: sampler.sd[options.sampler],
init_images: image && [image.dataUrl], // sd-webui accepts data URLs with base64 encoded image
restore_faces: config.restoreFaces ?? false,
restore_faces: config.restoreFaces === true,
enable_hr: options.hiresFix ?? config.hiresFix ?? false,
...project(parameters, {
prompt: 'prompt',
@ -286,6 +286,10 @@ export function apply(ctx: Context, config: Config) {
}
}
case 'stable-horde': {
const postProcessing = []
if (typeof config.restoreFaces === 'string') {
postProcessing.push(config.restoreFaces)
}
return {
prompt: parameters.prompt,
params: {
@ -295,7 +299,7 @@ export function apply(ctx: Context, config: Config) {
seed: parameters.seed.toString(),
height: parameters.height,
width: parameters.width,
post_processing: [],
post_processing: postProcessing,
karras: options.sampler.includes('_ka'),
steps: parameters.steps,
n: 1,