当前位置: 首页 > news >正文

Stable Diffusion Fooocus批量绘图脚本

当当当挡~,流动传热数值计算之余发布点AIGC相关文章,希望大家能喜欢~

1 Stable Diffusion各种UI分析对比

提示:此部分主要是对SD各种界面的简要介绍和对比,只关注Fooocus批量绘图的读者可直接跳到第二部分。

Stable Diffusion WebUIForgeUIComfyUIFooocusUI 都是基于 Stable Diffusion(稳定扩散技术)的开源图像生成UI。它们各有特色,满足了不同用户在生成 AI 图像时的需求。

  • WebUI:类 Web 应用的用户界面,适合普通用户,是目前最受欢迎和使用最广泛的SD UI。生态非常丰富,有大量插件和脚本支持,但插件与WebUI版本间的冲突有时令人头秃。WebUI入门相对相对简单,但生成高质量图片的操作流程较为复杂,需要用户在插件、Lora、controlnet方面花费较多心思。
  • ComfyUI:类Blender 的节点编辑器,用户可通过节点自定义工作流,适合工作流程超复杂的专业用户。与WebUI相比,ComfyUI对计算资源的要求低得多,是低显存用户的福音。ComfyUI支持节点工作流导入,这极大避免了繁复的工作流搭建过程。用户熟悉ComfyUI的基本功能后,直接去社区寻求搭建好的典型工作流后直接开抄,实现高质量出图。另外,可图、混元、Flux等新秀大模型发布后,ComfyUI通常是率先响应。因此,对于喜欢尝鲜的用户,ComfyUI将是首选。
  • ForgeUI:保留了WebUI的类Web 应用操作逻辑的同时,还具有不输于ComfyUI计算效率的特点。用户若会使用WebUI,Forge自然也就会了。Forge插件生态较差,WebUI的很多插件都不支持,但好在支持adetailer,提示词自动补全,openpose editor,wd14 tagger,StyleSelectorXL等常用插件,基本不影响使用。另外,Flux大模型,图片转视频的Deforum等插件对Forge来说也是手拿把掐,这些对WebUI用户还比较遥远。
  • FooocusUI:只接受预训练模型,专注于高质量图像的快速生成和性能优化,是一个简单高效的UI,适合追求快速高质量生图的用户(在快速出美图方面,估计也就Midjourney能碰一碰)。Fooocus具备WebUI的部分外表,但DNA里却是ComfyUI的节点工作流基因,而行为上又与Midjourney比较亲近。Fooocus的不足之处在于对插件的支持缺少到了将近匮乏的地步,对图片细节的把控能力也不够。但无论怎么讲,Fooocus仍不失为一款非常优秀的UI。最后推荐一个超棒的Fooocus分支作品——SimpleSDXL2(点此下载,需上网技巧),该分支与ComfyUI一样支持了SD3, Flux, 可图,混元等新晋大模型,若用户选择国产大模型,那么该UI还支持全中文提示词,特别适合中国人体质。

2 FooocusUI生厂力工具——批量绘图脚本

Fooocus擅长快速生成高质量图片,故其在AIGC领域有重要用武之地。依据用户输入的系列关键词批量生成符合要求的图片是SD生产效率的重要指标。截止目前(2024.9.17),WebUI/Forge以及ComfyUI已通过脚本或插件等方式具备了相关能力,但Fooocus的作者似乎并不打算在这方面所有突破。在Fooocus高质高效出图且官方批量绘图模块遥遥无期的背景下,我开始尝试在国内外论坛寻找相关问题的解决方案,没想到还真找到了两种(不然我都打算自己造轮子了,难顶)。

2.1 Chrome/Edge油猴脚本

声明:该脚本非原创,本人仅针对博主AidecLi发布的代码进行了一些可能有益的修改(传送门:Fooocus批次執行任務功能(使用tampermonkey實現),此链接在PC端似乎有渲染问题,在手机端能正常查看,但需上网技巧),该博主也在某视频网站发布了脚本教程,大家可观看学习(传送门:Fooocus批次執行任務功能,需上网技巧)。

该方案已被证实可行,并且至少可支持Fooocus2.4.3-2.5.5版本(最新的Fooocus2.5.5版本可在https://github.com/lllyasviel/Fooocus.git下载安装),如果FooocusUI不发生重大改变,那么该脚本应该也会自动适配后续版本(SimpleSDXL2作者对FooocusUI进行了魔改,本脚本暂不支持)。

2.1.1 Javascript脚本

请务必注意:代码开头两个“// ==UserScript==”间的代码(预设代码)不完全是注释,绝不能删除,有些部分会在代码中生效!!!

预设中的最重要代码为"// @match        http://192.0.0.1:7865/*",该预设限制脚本只能在 IP 为192.0.0.1(即本地地址),端口为7865以及其后所有路径的网页上运行。大家要使用的话必须将这段代码修改为与用户IP和端口匹配的地址(就是打开Fooocus后浏览器网址栏显示的地址),否则脚本不会生效!!!

特别地,"// @match        http://192.0.0.1:7865/*"中的“*”表示通配符,如果用户使用秋叶启动或自定义主题,浏览器网址栏除了IP和端口外还有如“?__theme=dark”这种主题信息。若不使用通配符,一旦用户更换了主题,则必须重新更新脚本中的网址信息,否则脚本将失效。

别的部分则没什么好说的,大家配合注释应该能明白。

// ==UserScript==
// @name         Fooocus批量绘图
// @namespace    https://blog.aidec.tw/ || https://blog.csdn.net/liuqihang11?type=blog
// @version      2024-09-17
// @description  输入以句号结尾的多行提示词实现Fooocus批量绘图,提示词格式:一行为一组,末尾用英文句号隔开。
// @author       AidecLi Create || Syphomn Modify
// @match        http://192.0.0.1:7865/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=0.1
// @grant        none
// ==/UserScript==
(function() {'use strict';let isProcessing = false;let stopRequested = false;let promptInputTextarea, processedTextarea, startButton, stopButton, clearButton, progressBar, statusDiv;// 添加UI元素function addUI() {const targetElement = document.querySelector('#component-3');if (!targetElement) {console.error('目标元素 #component-3 未找到');return;}const container = document.createElement('div');container.style.marginTop = '20px';container.style.display = 'flex';container.style.flexDirection = 'column';container.style.gap = '10px';// 待处理文本框promptInputTextarea = document.createElement('textarea');promptInputTextarea.id = 'promptList';promptInputTextarea.rows = 5;promptInputTextarea.style.width = '100%';promptInputTextarea.style.color = 'red'; // 设置文字为红色promptInputTextarea.placeholder = 'Unprocessed Prompts';// 已处理文本框processedTextarea = document.createElement('textarea');processedTextarea.id = 'processedList';processedTextarea.rows = 5;processedTextarea.style.width = '100%';processedTextarea.style.color = 'green'; // 设置文字为绿色processedTextarea.placeholder = 'Processed Prompts';processedTextarea.readOnly = true;// 开始批次处理按钮startButton = document.createElement('button');startButton.textContent = 'Start Batch-Drawing';startButton.onclick = processPrompts;startButton.style.padding = '5px 10px';startButton.style.cursor = 'pointer';startButton.className = 'lg secondary type_row svelte-cmf5ev';// 停止批次处理按钮stopButton = document.createElement('button');stopButton.textContent = 'Stop Batch-Drawing';stopButton.onclick = stopProcessing;stopButton.style.padding = '5px 10px';stopButton.style.cursor = 'pointer';stopButton.className = 'lg secondary type_row svelte-cmf5ev';// 清除已处理文本框按钮clearButton = document.createElement('button');clearButton.textContent = 'Clear Processed-Text';clearButton.onclick = clearProcessed;clearButton.style.padding = '5px 10px';clearButton.style.cursor = 'pointer';clearButton.className = 'lg secondary type_row svelte-cmf5ev';clearButton.disabled = true; // 初始化为不可用状态// 进度条progressBar = document.createElement('progress');progressBar.id = 'progressBar';progressBar.value = 0;progressBar.max = 100;progressBar.style.width = '100%';// 状态显示statusDiv = document.createElement('div');statusDiv.id = 'statusDiv';statusDiv.textContent = 'Enter Multiple Lines of Prompts Separated by a Period';statusDiv.style.fontWeight = 'bold';// 将UI元素添加到容器中container.appendChild(statusDiv);container.appendChild(promptInputTextarea);container.appendChild(processedTextarea);container.appendChild(startButton);container.appendChild(stopButton);container.appendChild(clearButton);container.appendChild(progressBar);targetElement.appendChild(container);}// 处理批次提示词async function processPrompts() {if (isProcessing) return;isProcessing = true;stopRequested = false;disableUI();// 重新读取未处理文本框中的内容const promptList = promptInputTextarea.value.split('\n').filter(p => p.trim() !== '');const totalPrompts = promptList.length;const positivePromptTextarea = document.querySelector('#positive_prompt textarea');const generateButton = document.querySelector('#generate_button');let i = 0;for (const prompt of promptList) {if (stopRequested) break;statusDiv.textContent = `正在处理第 ${i + 1} 组,共 ${totalPrompts} 组提示词: ${prompt}`;positivePromptTextarea.value = prompt;positivePromptTextarea.dispatchEvent(new Event('input', { bubbles: true }));console.log('开始绘制' + prompt);await new Promise(resolve => setTimeout(resolve, 500));generateButton.click();await new Promise(resolve => setTimeout(resolve, 500));await waitForGeneration(generateButton);if (stopRequested) break;console.log('结束绘制' + prompt);// 将已处理的移到已处理区processedTextarea.value += prompt + '\n';// 从待处理区移除已处理的提示词promptInputTextarea.value = promptList.slice(i + 1).join('\n');// 更新进度条progressBar.value = ((i + 1) / totalPrompts) * 100;// 等待2秒再继续下一个提示词statusDiv.textContent = `第 ${i + 1} 组已处理完毕,即将进入下一组。`;await new Promise(resolve => setTimeout(resolve, 1000));i++;}if (stopRequested) {statusDiv.textContent = '批量绘图已停止';} else {statusDiv.textContent = '所有提示词均处理完毕';clearButton.disabled = false; // 处理完毕后启用清除按钮}isProcessing = false;enableUI();}// 停止处理function stopProcessing() {stopRequested = true;isProcessing = false;enableUI();// 也停止本轮正在运作的生图const stopButton = document.querySelector('#stop_button');stopButton.click();// 启用清除按钮clearButton.disabled = false;}// 清除已处理文本框的内容function clearProcessed() {processedTextarea.value = '';clearButton.disabled = true; // 清除后禁用清除按钮}// 禁用UI元素function disableUI() {promptInputTextarea.disabled = true;startButton.disabled = true;startButton.textContent = 'Processing...';}// 启用UI元素function enableUI() {promptInputTextarea.disabled = false;startButton.disabled = false;startButton.textContent = 'Start Batch-Drawing';}// 等待生成过程function waitForGeneration(button) {return new Promise(resolve => {const observer = new MutationObserver(() => {if (!button.disabled && !button.hidden) {// 等待按钮setTimeout(() => {observer.disconnect();resolve();}, 500);}});observer.observe(button, { attributes: true, attributeFilter: ['disabled', 'hidden'] });if (stopRequested) resolve();// 如果按钮可用且没有hidden,则继续if (!button.disabled && !button.hidden) {observer.disconnect();resolve();}});}// 将自定义UI添加到页面上function initScript() {const maxAttempts = 10;let attempts = 0;function tryAddUI() {if (document.querySelector('#component-3')) {addUI();} else if (attempts < maxAttempts) {attempts++;setTimeout(tryAddUI, 1000); // 等待1秒重新尝试} else {console.error('在 ' + maxAttempts + ' 次尝试后未能找到 #component-3');}}tryAddUI();}// 页面完成加载UI到页面if (document.readyState === 'loading') {window.addEventListener('DOMContentLoaded', initScript);} else {initScript();}
})();

2.1.2 What's New

​相比于博主AidecLi的版本,本文提供代码在以下方面做了一些工作:

  • 修改了提示词文本框中的文字显示颜色以解决在Fooocus深色背景下文字显示不清的问题;
  • 添加了已绘提示词清除按钮以使用户能一键清除已使用提示词;
  • 修改了停止按钮的作用,修改前,停止绘图按钮的作用是中断绘图,并且已处理文本框中的文字被清空,未处理文本框中的文字将被初始化,修改后,停止绘图按钮的作用是中断绘图,但对文本框的内容不做任何处理,用户可在停止绘图后重新输入提示词文本并开始绘图,也可在断点处继续绘图。

2.1.3 使用方法

  • 安装油猴插件,Edge用户可在Edge插件商店安装,Chrome用户可在Chrome插件商店(需要上网技巧)。
  • 在插件管理处打开开发人员模式, Edge用户的插件管理在这里edge://extensions/,Chrome用户的插件管理在这里chrome://extensions/。

Edge:

Chrome:

  •  在油猴中添加新脚本,将2.1.1节的代码复制到代码框中;
  • // @match        http://192.0.0.1:7865/*行的网址修改为自己Fooocus的实际网址;

  • 正常启动Fooocus(2.5.5版本)后界面应该是这样 :
  • 用户的提示词应该遵循以下格式
1girl.
2girls.
3girls.
  •  设置fooocus出图参数后,将批量提示词(也可手动输入)复制粘贴到“Unprocessed Prompts”文本框,点击“Start Batch-Drawing”开始批量绘图,第一个文本框显示了未处理提示词,第二个文本框显示了已处理提示词;
  • 点击“Stop Batch-Drawing”按钮以中断绘图,之后用户可在该断点处继续绘图,也可修改提示词后重新开始绘图;
  • “Clear Processed-Text”的作用是在用户停止绘图或所有提示词绘图完毕后清空已处理文本框的文字内容。

OK了各位,Hope you all enjoy it!

2.2 接管Fooocus接口

这是SD各种UI实现批量绘图的通法,也是第三方软件调用SD绘图的常用做法。该方法需要对SD源代码有基本了解,至少需要掌握SD大模型、lora、高清放大等接口的调用格式(我一开始本来打算采用这种方法,但苦于无法找到详细的Fooocus接口说明文档,就一直没搞成),好在CSDN上的桥呗博主已发布了相关代码供大家学习使用(传送门:fooocus读取批量prompts进行批量生成图像方法)。

该方法是非UI界面绘图,有一定使用门槛,且有效性我没有验证,大家可以自行实践。

3 写在最后

本文提供了一个用于Fooocus批量绘图的简易脚本,能够基本满足用户需要,希望能帮到大家。

文章已提供源代码,代码1.0版本由博主AidecLi无偿提供,本文对其功能进行了增改,更新到了2.0版本。

AIGC领域的发展需要大家共同努力,欢迎各位对我提供的脚本二次开发,修复Bug,完善功能。

严正声明:

  • 脚本源代码为免费提供,严禁任何人(除博主AidecLi及其授权人员外)直接利用源代码本身盈利(但这不包括本脚本的二次开发产品及其衍生品),否则将严肃追责!
  • 若本文尤其是本声明侵犯了博主AidecLi您的任何权益,请联系我商讨善后事宜。

最后再来几张AIGC美图:

(masterpiece, top quality, best quality, official art, beautiful and aesthetic:1.2),(1girl),extreme detailed,(fractal art:1.3),colorful,highest detailed,
Negative prompt: (worst quality, low quality:2),monochrome,zombie,overexposure,watermark,text,bad anatomy,bad hand,extra hands,extra fingers,too many fingers,fused fingers,bad arm,distorted arm,extra arms,fused arms,extra legs,missing leg,disembodied leg,extra nipples,detached arm,liquid hand,inverted hand,disembodied limb,small breasts,loli,oversized head,extra body,completely nude,extra navel,EasyNegative,(hair between eyes),sketch,duplicate,ugly,huge eyes,text,logo,worst face,(bad and mutated hands:1.3),(blurry:2),horror,geometry,bad_prompt,(bad hands),(missing fingers),multiple limbs,bad anatomy,(interlocked fingers:1.2),Ugly Fingers,(extra digit and hands and fingers and legs and arms:1.4),((2girl)),(deformed fingers:1.2),(long fingers:1.2),(bad-artist-anime),bad-artist,bad hand,extra legs,(ng_deepnegative_v1_75t),
Steps: 30, Sampler: DPM++ 2M Karras, CFG scale: 6, Seed: 1015468391, Size: 512x768, Model hash: e3edb8a26f, Model: GhostMix鬼混_V2.0, Denoising strength: 0.5, Clip skip: 2, Hires upscale: 2, Hires upscaler: R-ESRGAN 4x+ Anime6B, Version: f0.0.17v1.8.0rc-latest-277-g0af28699

modern,masterpiece,best quality,8k,intricate details,hyperdetailed,hyper quality,anime,CG,1girl,modern,
Negative prompt: NSFW,watermark,third-party watermark,character watermark,sharp,(worst quality, low quality:1.4),cropped,poorly drawn,low resolution,logo,text,blurry,bad anatomy,lowres,monochrome,grayscale,(signature:1.4),bad proportions,username,poorly drawn face,malformed hands,skin blemishes,skin spots,bad body,acnes,missing fingers,long body,missing limb,fused fingers,too many fingers,long neck,floating limbs,extra legs,disconnected limbs,bad feet,mutated,cross-eyed,extra arms,ugly,mutated hands,disfigured,poorly drawn hands,(deformed iris, deformed pupils:1.3),(deformed, distorted, disfigured:1.3),out of frame,extra limb,cloned face,amputation,blurry,jpeg artifacts,
Steps: 20, Sampler: DPM++ 2M Karras, CFG scale: 7, Seed: 3081904287, Size: 768x512, Model hash: d6301c47f5, Model: 小说推文大模型-通用, VAE hash: 735e4c3a44, VAE: vae-ft-mse-840000-ema-pruned.safetensors, Denoising strength: 0.7, Hires upscale: 2, Hires upscaler: R-ESRGAN 4x+ Anime6B, Version: f0.0.17v1.8.0rc-latest-277-g0af28699

相关文章:

  • 北京网站建设多少钱?
  • 辽宁网页制作哪家好_网站建设
  • 高端品牌网站建设_汉中网站制作
  • 地平线秋招2025
  • GPT撰写开题报告教程——课题确定及文献调研
  • 基于jupyter notebook + joint-spider爬虫数据的成都二手房数据可视化分析项目源代码+详细使用说明
  • a,b,c中的最大值
  • Github 2024-09-17 Python开源项目日报 Top10
  • WGAN算法
  • ZooKeeper远程连接超时排查与解决
  • 【bug】通过lora方式微调sdxl inpainting踩坑
  • 后门账号从入门到应急响应
  • 9.17 DFS中等 200 Number of Islands
  • 【系统架构设计师】虚拟机架构风格
  • 使用Mockito进行单元测试
  • 【Linux】查看操作系统开机时初始化的驱动模块列表的一个方法
  • AI教你学Python 第10天 :参数与返回值
  • HarmonyOS 速记
  • canvas 五子棋游戏
  • Centos6.8 使用rpm安装mysql5.7
  • css属性的继承、初识值、计算值、当前值、应用值
  •  D - 粉碎叛乱F - 其他起义
  • flask接收请求并推入栈
  • HashMap剖析之内部结构
  • JAVA并发编程--1.基础概念
  • Java超时控制的实现
  • js面向对象
  • Laravel 中的一个后期静态绑定
  • LeetCode541. Reverse String II -- 按步长反转字符串
  • Mac 鼠须管 Rime 输入法 安装五笔输入法 教程
  • PHP的类修饰符与访问修饰符
  • Python十分钟制作属于你自己的个性logo
  • ⭐ Unity 开发bug —— 打包后shader失效或者bug (我这里用Shader做两张图片的合并发现了问题)
  • windows下使用nginx调试简介
  • XForms - 更强大的Form
  • 初识MongoDB分片
  • 简单实现一个textarea自适应高度
  • 如何选择开源的机器学习框架?
  • 网页视频流m3u8/ts视频下载
  • 想写好前端,先练好内功
  • 正则表达式
  • [地铁译]使用SSD缓存应用数据——Moneta项目: 低成本优化的下一代EVCache ...
  • "无招胜有招"nbsp;史上最全的互…
  • #1014 : Trie树
  • $emit传递多个参数_PPC和MIPS指令集下二进制代码中函数参数个数的识别方法
  • (10)STL算法之搜索(二) 二分查找
  • (3)Dubbo启动时qos-server can not bind localhost22222错误解决
  • (4)事件处理——(7)简单事件(Simple events)
  • (ISPRS,2021)具有遥感知识图谱的鲁棒深度对齐网络用于零样本和广义零样本遥感图像场景分类
  • (poj1.3.2)1791(构造法模拟)
  • (pt可视化)利用torch的make_grid进行张量可视化
  • (Qt) 默认QtWidget应用包含什么?
  • (八)Flask之app.route装饰器函数的参数
  • (办公)springboot配置aop处理请求.
  • (附源码)spring boot火车票售卖系统 毕业设计 211004
  • (附源码)流浪动物保护平台的设计与实现 毕业设计 161154
  • (简单) HDU 2612 Find a way,BFS。
  • (十五)使用Nexus创建Maven私服