Dify接入SD教程:零基础实现AI绘画自由

2026-06-18阅读 0热度 0
ai 人工智能

Dify 这个平台确实很灵活,除了我们常聊的文本处理,它其实还支持接入 Stable Diffusion、DALLE 2 和 3 这类 AI 绘画模型。不过,在国内用 DALLE 总有些绕不开的麻烦,既然都折腾到这一步了,还不如一步到位用 Midjourney。但话说回来,MJ 的 API 也不是那么好拿的,所以这次咱们还是聚焦在更接地气的方案上——把 Stable Diffusion 接进来。

给 Dify 接入 SD 实现 AI 绘画自由

之前为了测试,我在自己的 Mac 上部署了一套 SD 环境(流程可以参考之前的分享)。为了试试效果,还特地从 C 站(Civitai)下了一个叫 XXMix_9realisticSDXL 的模型,生成的图片质感相当不错。

下面这两张就是我用这个模型跑出来的,效果你们可以感受一下:

prompt : (masterpiece, detailed, cyberpunk, dramatic lighting:1.3), mesmerizing xxmixgirl character, detailed feminine features, intricate facial expressions, time square background filled with neon lights and bustling crowds, cyberpunk elements subtly integrated, shadowy atmosphere enhancing the mood, lighting inspired by Bill Sienkiewicz's style, dynamic composition, vibrant colors contrasting with dark shadows, intense and dramatic ambiance, SimplepositiveXLv1 filter at 70% opacity for a touch of modernity and edge.

一个赛博朋克风格的小姐姐就此诞生,科技感拉满。

prompt : (masterpiece, surreal, dramatic lighting, detailed:1.3), enchanting xxmixgirl character silhouetted against a beautiful sunset, intricate details in the scene, surreal atmosphere created by the lighting, shadows adding depth and mystery, inspired by the styles of Brandon Woelfel and Ryan McGinley, lo-fi analog filter resembling Kodak film, warm tones enhancing the sunset, dreamlike quality to the setting, captivating and serene vibe, focusing on the beauty of the moment and the character, rich storytelling through light and shadow play.

好了,热完身,咱们正式进入主题,看看怎么把 SD 和 Dify 连起来。

接入 Stable Diffusion

第一步,打开 Dify 的工具页面,找到并设置 Stable Diffusion 的授权。

⚠️注意: 要让 SD 提供 API 服务,启动命令跟平常有点不一样。在 Mac 或 Linux 系统上,需要加上参数 ./webui.sh --api --listen;Windows 系统则是 ./webui.bat --api --listen。别忘了这个细节,否则 Dify 是找不到 SD 的。

这里有个配置要点:服务器地址怎么填?如果 SD 是部署在本地的,就填 http://host.docker.internal:7860;如果是部署在云服务器上的,那就填 “服务器IP:7860”。

Dify工具的配置界面

至于模型名称,就对应截图里红框框住的那部分。举个例子,我用的模型文件名叫 xxmix9realisticsdxl_v10.safetensors,那么在 Dify 里配置时,填 xxmix9realisticsdxl_v10 就行,后面的扩展名不用管。

设置好这些,点击保存,不出意外的话,SD 就能顺利接进来了。

在应用中使用

现在,让我们新建一个 Agent 应用,把刚才配好的 SD 工具拖进去。

新建Agent应用的界面

这样一来,我们这个 Agent 就具备了 Stable Diffusion 的绘图能力。先测试一下它的普通对话功能。

普通对话测试

对话功能没问题,接下来试试绘图。咱们继续用刚才的 prompt,看看它能不能在 Agent 里直接执行。

Prompt : (detailed, surreal, contemporary:1.2), xxmixgirl portrayed in a surreal setting with intricate details, blending gradients of contemporary artistry, immersed in nature with a touch of street-art and urban-life elements, vibrant colors and emotions captured in a photographic style, inspired by Marta Bevacqua's work, rich storytelling through portraits, lo-fi analog filter reminiscent of Kodak film, dreamlike and ethereal atmosphere, depth in character expression and surroundings, a fusion of art and photography creating a visually stunning and contemplative scene.

Agent生成的图片结果

生成的图片原始尺寸很大,为了上传方便压缩了一下,清晰度有所下降,不过整体效果还是在线的。你也可以把这个 Agent 接到微信里,体验一下在聊天窗口直接画图的快感(具体接入方法可以参考关于 Dify 接入微信的分享)。

压缩后图片细节难免会打折扣,原图的清晰度是完全没问题的。

要实现这样的“识图 + 出图”能力,使用 Agent 是必经之路。它不仅能调用绘图工具,还能挂载知识库。而对于大模型的选择,记得要选用支持多模态识图的模型,比如 GPT-4o 这类。当然,除了 Stable Diffusion,Dify 也支持授权使用 DALLE 进行绘图,可以根据实际情况灵活选择。

免责声明

本网站新闻资讯均来自公开渠道,力求准确但不保证绝对无误,内容观点仅代表作者本人,与本站无关。若涉及侵权,请联系我们处理。本站保留对声明的修改权,最终解释权归本站所有。

相关阅读

更多
欢迎回来 登录或注册后,可保存提示词和历史记录
登录后可同步收藏、历史记录和常用模板
注册即表示同意服务条款与隐私政策