赞
踩
近来Stable diffusion扩散网络大热,跟上时代,简单的文生图,图生图,其实可以满足绝大多数设计师的应用,但是有什么是赛博画手无法做到的呢? 那就是他们使用到的stable diffusion的插件开发,他们并不清楚stable diffusino的代码结构,如果遇到一些代码层面的报错问题,他们将无法简单解决。
我们想要开发出我想要的stable diffusion插件。那么我们首先要去学习一些gradio的基础知识。
1.想要了解stable diffusion的插件的形式,插件基本都是放在extension文件夹里面。 启动器提供通过git下载对应的内容。 其实就是通过直接copy github里面的代码来实现插件的。
2.以一个简单ffmpeg嵌入倒放视频的功能为例吧
启动的时候需要安装一些库,需要准备install.py文件会自动运行代码
import launch
if not launch.is_installed("ffmpeg-python"):
launch.run_pip("install ffmpeg-python", "requirements for TemporalKit extension")
if not launch.is_installed("moviepy"):
launch.run_pip("install moviepy", "requirements for TemporalKit extension")
if not launch.is_installed("imageio_ffmpeg"):
launch.run_pip("install imageio_ffmpeg", "requirements for TemporalKit extension")
requirement.txt最好也准备一些你需要的库
ffmpeg-python
moviepy
3.一个启动简单的启动代码,看不懂的可以看注释,这个例子简单包含按钮,滑动条,视频展示等容器。如果需要查看更多的容器,需要去看gradio api
import gradio as gr from modules import scripts, script_callbacks import os import ffmpeg # base_dir = scripts.basedir() #ffmpeg倒放命令 def convert_video(input_file: str, output_directory: str, speed: int, reverse: bool): #ffmpeg -i G:\1\c6cfb2d13929eb4967417e0bd81c314c.mp4 -vf reverse -y reverse.mp4 fileName = os.path.basename(input_file) outputFile = os.path.join(output_directory, fileName) ffm = ffmpeg.input(input_file) if speed != 1 : ffm = ffm.filter('setpts', f'PTS/{speed}') if reverse : ffm = ffm.filter("reverse") ffm.output(outputFile).run() return outputFile def on_ui_tabs(): with gr.Blocks(analytics_enabled=False) as ffmpeg_kit_ui: with gr.Row(): with gr.Column(variant="panel"): with gr.Column(): video_file = gr.Textbox( label="Video File", placeholder="Wrire your video file address", value="", interactive=True, ) org_video = gr.Video( interactive=True, mirror_webcam=False ) def fn_upload_org_video(video): return video org_video.upload(fn_upload_org_video, org_video, video_file) gr.HTML(value="<p style='margin-bottom: 1.2em'>\ If you have trouble entering the video path manually, you can also use drag and drop.For large videos, please enter the path manually. \ </p>") with gr.Column(): output_directory = gr.Textbox( label="Video Output Directory", placeholder="Directory containing your output files", value="", interactive=True, ) with gr.Column(): with gr.Row(): speed_slider = gr.Slider( label="Video Speed", minimum=0, maximum=8, step=0.1, value=1 ) with gr.Row(): reverse_checkbox = gr.Checkbox( label="Video need reverse", value=False ) with gr.Column(variant="panel"): with gr.Row(): convert_video_btn = gr.Button( "Convert Video", label="Convert Video", variant="primary" ) with gr.Row(): dst_video = gr.Video( interactive=True, mirror_webcam=False ) #生成按钮 convert_video_btn.click( convert_video, inputs=[ video_file, output_directory, speed_slider, reverse_checkbox ], outputs=dst_video ) gr.HTML(value="<p>Converts video in a folder</p>") #ui布局 扩展模块名 return (ffmpeg_kit_ui, "FFmpeg Kit", "ffmpeg_kit_ui"), #启动的时候,script_callback加载到扩展模块当中 script_callbacks.on_ui_tabs(on_ui_tabs) print("FFmpeg kit init")
这里只是一个ffmpeg的功能嵌入,并没有包含原来一些文生图,图生图的功能。
4.下一个介绍如何嵌入功能到文生图或者图生图的脚本功能
#加载到文生图或者图生图的应用过程当中 class FFmpegKitScript(scripts.Script): def __init__(self) -> None: super().__init__() # 功能块名 def title(self): return "FFmpeg Kit" #是否默认显示 def show(self, is_img2img): return scripts.AlwaysVisible #ui显示 def ui(self, is_img2img): video_file = gr.Textbox( label="Video File", placeholder="Wrire your video file address", value="", interactive=True, ) output_directory = gr.Textbox( label="Video Output Directory", placeholder="Directory containing your output files", value="", interactive=True, ) generateBtn = gr.Button("Generate", label="Generate", variant="primary") generateBtn.click( convert_video, inputs=[ video_file, output_directory ], outputs=[] ) return [ video_file, output_directory, generateBtn, ] #运行的时候嵌入运行 def run(self, video_file, output_directory, generateBtn): return
4.添加到设定页面里面 这里需要调用script_callbacks.on_ui_settings方法 shared.opts.add_optioin是添加公共的设置,Shared.OptionsInfo里面是对应的布局,对应都是return对象。 实在不知道怎么写的同学可以参照infinite_zoom这个插件。
def on_ui_settings(): section = ("infinite-zoom", "Infinite Zoom") shared.opts.add_option( "infzoom_outpath", shared.OptionInfo( "outputs", "Path where to store your infinite video. Default is Outputs", gr.Textbox, {"interactive": True}, section=section, ), ) shared.opts.add_option( "infzoom_outSUBpath", shared.OptionInfo( "infinite-zooms", "Which subfolder name to be created in the outpath. Default is 'infinite-zooms'", gr.Textbox, {"interactive": True}, section=section, ), ) script_callbacks.on_ui_settings方法 shared.opts.add_optioin是添加公共的设置,Shared.OptionsInfo里面(on_ui_settings)
需要拿出设置里面的数据,可以拿shared.opts.data.get的方法来实现
output_path = shared.opts.data.get("infzoom_outpath", "outputs")
这里简单介绍了,stable diffusion的插件功能的方法,一些深入的定制需要会在接下来的文章中介绍一些深入应用。
这是一位SD资深大神整理的,100款Stable Diffusion超实用插件,涵盖目前几乎所有的,主流插件需求。
我把它们整理成更适合大家下载安装的【压缩包】,无需梯子,并根据具体的内容,拆解成一二级目录,以方便大家查阅使用。
想要原版100款插件整合包的小伙伴,可以添加下方直接免费获取!
在我们出图的时候,最头疼的就是出的图哪有满意,就是手部经常崩坏。只要放到 ControlNet 里面再修复。
现在我们只需要在出图的时候启动 Adetailer 就可以很大程度上修复脸部和手部的崩坏问题
换脸插件,只需要提供一张照片,就可以将一张脸替换到另一个人物上,这在娱乐和创作中非常受欢迎。
这个插件可以轻松的创建、组织和共享模型预设。有了这个功能,就不再需要记住每个模型的最佳 cfg_scale、实现卡通或现实风格的特定触发词,或者为特定图像类型产生令人印象深刻的结果的设置!
已经被赞爆的现代化 Web UI 主题。相比传统的 Web UI 体验性大大加强。
使用这个插件可以直接输入中文,调取对应的英文提示词。并且能够根据未写完的英文提示词提供补全选项,在键盘上按↓箭头选择,按 enter 键选中
这个插件提供双语翻译功能,使得界面可以支持两种语言,对于双语用户来说是一个很有用的功能。
提供提示词功能,可能帮助用户更好地指导图像生成的方向。
上千个提示词,无需英文基础快速输入提示词,该词库还在不断更新。
以后再也不担心英文写出不卡住思路了!
由于篇幅原因,有需要完整版Stable Diffusion插件库的小伙伴,点击下方添加即可免费领取!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。