MirrorCY / sd-extra

Upsample images by SD-WebUI | 基于 SD-WebUI 的超分辨率插件
MIT License
5 stars 1 forks source link

放大较大图片时,会不进行放大直接发送结果出来,且结果图片为原图或缩小版本。 #6

Open Neptune1990 opened 8 months ago

Neptune1990 commented 8 months ago

放大较大图片时,会不进行放大直接发送结果出来,且结果图片为原图或缩小版本。

无相关日志信息

System: OS: Windows 10 10.0.19045 CPU: (20) x64 12th Gen Intel(R) Core(TM) i7-12700

Binaries: Node: 20.3.1 Yarn: 4.0.1

Koishi: Core: 4.16.7 Console: 5.26.6 Koishi Desktop: 1.0.0

MirrorCY commented 8 months ago

我已经忘记这是一个 feature or bug 了,我记得当初过大的图会卡很久

MirrorCY commented 8 months ago

不如去使用 Novelai 插件吧(

Neptune1990 commented 8 months ago

刚刚尝试一张950X950的图片,他直接还给我了[流泪],记得之前一个老版本在onebot的下面正常的,在red下面也这样。

Neptune1990 commented 8 months ago

不如去使用 Novelai 插件吧(

叹气,novelai好久不更新了,而且自定义放大算法挺麻烦。

MirrorCY commented 8 months ago

@MaikoTan 出来挨骂(x

Neptune1990 commented 8 months ago

@MaikoTan 出来挨骂(x

啊这,流泪猫猫头

MirrorCY commented 8 months ago

我们商量一下,看看怎么实现。 我倾向于完善那边,这边要做的话,我就直接重构了

Neptune1990 commented 8 months ago

我们商量一下,看看怎么实现。 我倾向于完善那边,这边要做的话,我就直接重构了

是的,从一出来就在用nai,现在热度下去了,挺喜欢用的。之前也提了可不可以有高清修复有独立的放大算法、重绘幅度和步数,放大算法可以和sd-extra一样自定义之类的。

MirrorCY commented 8 months ago

现在那边的放大 你觉得有哪些不足

Neptune1990 commented 8 months ago

现在那边的放大 你觉得有哪些不足

啊这,目前没法使用,novelai.upscale带图,会返回请输入图片。直接novelai.upscale会回复发生未知错误。 附图 image 其实sd-extra这样就挺好,可以自定义默认倍率,算法等,然后直接放大+图或者放大回复我请发送图片。

MirrorCY commented 8 months ago

那我重写一下吧

Neptune1990 commented 8 months ago

image

MirrorCY commented 8 months ago

你可以试一试能不能用,这几天有个项目 ddl 快到了,先闭关一阵)

糊了一个,没测试,急用的话,自己修一修 ``` import { Context, Schema, h, trimSlash } from 'koishi' export const name = 'sd-extra2' export interface Config { endpoint?: string upscaler?: string } export const Config: Schema = Schema.object({ endpoint: Schema.string().default('http://127.0.0.1:7860').description('sd-webui 的地址'), upscaler: Schema.string().default('SwinIR_4x').description('默认采样器'), }) export function apply(ctx: Context, config: Config) { // write your plugin here const endpoint = trimSlash(config.endpoint) const toDataUrl = (buffer: ArrayBuffer) => { return `data:image/png;base64,${Buffer.from(buffer).toString('base64')}` } const resize = (value: string) => { const num = parseInt(value) if (isNaN(num) || num < 1 || num > 4) { throw Error('放大倍数必须是 1-4 的整数') } return num } const getUpscalers = async () => { const res = await ctx.http.get(endpoint + '/sdapi/v1/upscalers') return res.map(item => item.name) } ctx.command(name, '放大图片') .alias('放大') .option('resize', '-r 放大倍数', { type: resize }) .option('upscaler', '-u 手动选择采样器') .option('switch', '-x 切换默认采样器') .option('show', '-s 显示可用采样器') .action(async ({ session, options }) => { if (options.show) return `当前可用的采样器有:\n${(await getUpscalers()).join('\n')}` if (options.switch) { if (!(await getUpscalers()).includes(options.switch)) { return `似乎不存在名为 ${options.switch} 的采样器` } config.upscaler = options.switch ctx.scope.update(config, false) return `已将默认采样器切换为 ${options.switch}` } const resize = options.resize ?? 2 const upscaler = options.upscaler ?? config.upscaler const imgUrl = h.select(session.elements, 'img')[0]?.attrs.src if (!imgUrl) return session.execute(`help ${name}`) const img = await ctx.http.get(imgUrl, { responseType: 'arraybuffer' }) const dataUrl = toDataUrl(img) const res = await ctx.http.post(endpoint + '/sdapi/v1/extra-single-image', { image: dataUrl, upscaling_resize: resize, upscaler_1: upscaler, }, { responseType: 'arraybuffer' }) const resData = toDataUrl(res) return h.image(resData) }) } ```
MaikoTan commented 7 months ago

Hmmm.... Yeah, I admit that it has been a long time since we touched the NovelAI plugin, I personally will make it compatible with the Koishi v4.17.0 version and then investigate these features.