Skip to content

Commit

Permalink
Merge branch 'main' into hires-fix-steps
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma authored Aug 15, 2024
2 parents fa73c3f + 6744995 commit 9ed1381
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 10 deletions.
6 changes: 2 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,9 @@ jobs:

steps:
- name: Check out
uses: actions/checkout@v3
uses: actions/checkout@v4
- name: Setup Node
uses: actions/setup-node@v3
with:
node-version: 18
uses: actions/setup-node@v4
- name: Install
run: yarn
- name: Build
Expand Down
5 changes: 4 additions & 1 deletion data/horde-models.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"ACertainThing",
"AIO Pixel Art",
"AlbedoBase XL (SDXL)",
"AMPonyXL",
"Analog Diffusion",
"Analog Madness",
"Animagine XL",
Expand All @@ -25,6 +26,8 @@
"A-Zovya RPG Inpainting",
"Babes",
"BB95 Furry Mix",
"BB95 Furry Mix v14",
"Blank Canvas XL",
"BPModel",
"BRA",
"BweshMix",
Expand Down Expand Up @@ -165,8 +168,8 @@
"stable_diffusion",
"stable_diffusion_2.1",
"stable_diffusion_inpainting",
"SwamPonyXL",
"SweetBoys 2D",
"ThisIsReal (V6.0)",
"ToonYou",
"Trinart Characters",
"Tron Legacy Diffusion",
Expand Down
13 changes: 12 additions & 1 deletion src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,15 @@ export const upscalers = [
'SwinIR 4x',
] as const

export const latentUpscalers = [
'Latent',
'Latent (antialiased)',
'Latent (bicubic)',
'Latent (bicubic antialiased)',
'Latent (nearest)',
'Latent (nearest-exact)',
]

export interface Options {
enhance: boolean
model: string
Expand Down Expand Up @@ -208,6 +217,7 @@ interface ParamConfig {
upscaler?: string
restoreFaces?: boolean
hiresFix?: boolean
hiresFixUpscaler: string
scale?: Computed<number>
textSteps?: Computed<number>
imageSteps?: Computed<number>
Expand Down Expand Up @@ -338,6 +348,7 @@ export const Config = Schema.intersect([
upscaler: Schema.union(upscalers).description('默认的放大算法。').default('Lanczos'),
restoreFaces: Schema.boolean().description('是否启用人脸修复。').default(false),
hiresFix: Schema.boolean().description('是否启用高分辨率修复。').default(false),
hiresFixUpscaler: Schema.union(latentUpscalers.concat(upscalers)).description('高分辨率修复的放大算法。').default('Latent'),
scheduler: Schema.union(scheduler.sd).description('默认的调度器。').default('Automatic'),
}),
Schema.object({
Expand Down Expand Up @@ -370,7 +381,7 @@ export const Config = Schema.intersect([
}),
Schema.union([
Schema.object({
model: Schema.const('nai-v3').required(),
model: Schema.const('nai-v3'),
sampler: sampler.createSchema(sampler.nai3),
smea: Schema.boolean().description('默认启用 SMEA。'),
smeaDyn: Schema.boolean().description('默认启用 SMEA 采样器的 DYN 变体。'),
Expand Down
9 changes: 5 additions & 4 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,7 @@ export function apply(ctx: Context, config: Config) {
restore_faces: config.restoreFaces ?? false,
enable_hr: options.hiresFix ?? config.hiresFix ?? false,
hr_second_pass_steps: options.hiresFixSteps ?? 0,
hr_upscaler: config.hiresFixUpscaler ?? 'None',
...project(parameters, {
prompt: 'prompt',
batch_size: 'n_samples',
Expand Down Expand Up @@ -420,8 +421,8 @@ export function apply(ctx: Context, config: Config) {
const body = new FormData()
const capture = /^data:([\w/.+-]+);base64,(.*)$/.exec(image.dataUrl)
const [, mime,] = capture
let name = Date.now().toString()

let name = Date.now().toString()
const ext = mime === 'image/jpeg' ? 'jpg' : mime === 'image/png' ? 'png' : ''
if (ext) name += `.${ext}`
const imageFile = new Blob([image.buffer], {type:mime})
Expand All @@ -437,7 +438,7 @@ export function apply(ctx: Context, config: Config) {
const data = res.data
let imagePath = data.name
if (data.subfolder) imagePath = data.subfolder + '/' + imagePath

for (const nodeId in prompt) {
if (prompt[nodeId].class_type === 'LoadImage') {
prompt[nodeId].inputs.image = imagePath
Expand All @@ -462,7 +463,7 @@ export function apply(ctx: Context, config: Config) {
const negativeeNodeId = prompt[nodeId].inputs.negative[0]
const latentImageNodeId = prompt[nodeId].inputs.latent_image[0]
prompt[positiveNodeId].inputs.text = parameters.prompt
prompt[negativeeNodeId].inputs.text = parameters.uc
prompt[negativeeNodeId].inputs.text = parameters.uc
prompt[latentImageNodeId].inputs.width = parameters.width
prompt[latentImageNodeId].inputs.height = parameters.height
prompt[latentImageNodeId].inputs.batch_size = parameters.n_samples
Expand Down

0 comments on commit 9ed1381

Please sign in to comment.