点击下方卡片,关注「魔方AI空间」公众号
写在前面
本文介绍了Black Forest Labs开发的文生图模型FLUX.1及其社区生态,基于FLUX.1-LoRA/IP-adapter与ComfyUI结合使用的实战教程,旨在介绍如何使用AI技术生成「黑神话:悟空」的图像!
「黑神话:悟空」的热度毋庸置疑。作为中国第一个「考出村」的3A状元,从游戏本身来看,《黑神话:悟空》的火爆彰显了数字内容创作的巨大商业价值,更是数字经济和科技领域的一大进步,它让我们看到了国产游戏在国际舞台上的潜力和可能性。
FLUX.1项目主页:https://blackforestlabs.ai/announcing-black-forest-labs/
FLUX1-超写实逼真黑悟空LoRA模型地址:https://www.liblib.art/modelinfo/5e4a4cc0e3674818a9f8454a63cc0115
ComfyUI地址:https://github.com/comfyanonymous/ComfyUI
本文参考自魔搭社区,文章地址:https://mp.weixin.qq.com/s/7NavuJUzR7DwTZn45QfdPw
最佳实践
环境配置
python 3.10及以上版本
pytorch 1.12及以上版本,推荐2.0及以上版本
建议使用CUDA 11.4及以上
快速体验
选择硬件环境
这里选择魔塔社区免费提供的GPU算力,可快速体验!!
魔搭社区地址:https://modelscope.cn/
下载和部署ComfyUI
❝相关资源地址:
https://github.com/comfyanonymous/ComfyUI https://github.com/ltdrdata/ComfyUI-Manager https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes.git
在jupyter notebook中执行以下命令,可快速安装和部署ComfyUI!!
# #@title Environment Setup
from pathlib import Path
OPTIONS = {}
UPDATE_COMFY_UI = True #@param {type:"boolean"}
INSTALL_COMFYUI_MANAGER = True #@param {type:"boolean"}
INSTALL_CUSTOM_NODES_DEPENDENCIES = True #@param {type:"boolean"}
INSTALL_ComfyUI_Comfyroll_CustomNodes = True #@param {type:"boolean"}
INSTALL_x_flux_comfyui = True #@param {type:"boolean"}
OPTIONS['UPDATE_COMFY_UI'] = UPDATE_COMFY_UI
OPTIONS['INSTALL_COMFYUI_MANAGER'] = INSTALL_COMFYUI_MANAGER
OPTIONS['INSTALL_CUSTOM_NODES_DEPENDENCIES'] = INSTALL_CUSTOM_NODES_DEPENDENCIES
OPTIONS['INSTALL_ComfyUI_Comfyroll_CustomNodes'] = INSTALL_ComfyUI_Comfyroll_CustomNodes
OPTIONS['INSTALL_x_flux_comfyui'] = INSTALL_x_flux_comfyui
current_dir = !pwd
WORKSPACE = f"{current_dir[0]}/ComfyUI"
%cd /mnt/workspace/
![ ! -d $WORKSPACE ] && echo -= Initial setup ComfyUI =- && git clone https://github.com/comfyanonymous/ComfyUI
%cd $WORKSPACE
if OPTIONS['UPDATE_COMFY_UI']:
!echo "-= Updating ComfyUI =-"
!git pull
if OPTIONS['INSTALL_COMFYUI_MANAGER']:
%cd custom_nodes
![ ! -d ComfyUI-Manager ] && echo -= Initial setup ComfyUI-Manager =- && git clone https://github.com/ltdrdata/ComfyUI-Manager
%cd ComfyUI-Manager
!git pull
if OPTIONS['INSTALL_ComfyUI_Comfyroll_CustomNodes']:
%cd ..
!echo -= Initial setup ComfyUI_Comfyroll_CustomNodes =- && git clone https://github.com/Suzie1/ComfyUI_Comfyroll_CustomNodes.git
if OPTIONS['INSTALL_x_flux_comfyui']:
!echo -= Initial setup x-flux-comfyui =- && git clone https://github.com/XLabs-AI/x-flux-comfyui.git
if OPTIONS['INSTALL_CUSTOM_NODES_DEPENDENCIES']:
!pwd
!echo "-= Install custom nodes dependencies =-"
![ -f "custom_nodes/ComfyUI-Manager/scripts/colab-dependencies.py" ] && python "custom_nodes/ComfyUI-Manager/scripts/colab-dependencies.py"
!pip install spandrel
下载模型
❝模型链接https://www.liblib.art/modelinfo/5e4a4cc0e3674818a9f8454a63cc0115 https://huggingface.co/wanghaofan/Black-Myth-Wukong-FLUX-LoRA
在jupyter notebook中执行以下命令,可快速下载相关所需要的模型,包含Flux.1基础模型,Lora,Controlnet,IP-adapter等,并存放到models目录的相关子目录下。
#@markdown ###Download standard resources
%cd /mnt/workspace/ComfyUI
### FLUX1-DEV
!modelscope download --model=AI-ModelScope/flux-fp8 --local_dir ./models/unet/flux1-dev-fp8.safetensors
### clip
!modelscope download --model=AI-ModelScope/flux_text_encoders --local_dir ./models/clip/clip_l.safetensors
!modelscope download --model=AI-ModelScope/flux_text_encoders --local_dir ./models/clip/t5xxl_fp8_e4m3fn.safetensors
### vae
!modelscope download --model=AI-ModelScope/FLUX.1-dev --local_dir ./models/vae/ae.safetensors
### lora
!modelscope download --model=FluxLora/flux-koda --local_dir ./models/loras/araminta_k_flux_koda.safetensors
!modelscope download --model=FluxLora/Black-Myth-Wukong-FLUX-LoRA --local_dir ./models/loras/pytorch_lora_weights.safetensors
!modelscope download --model=FluxLora/FLUX1_wukong_lora --local_dir ./models/loras/FLUX1_wukong_lora.safetensors
### ip-adapter
!modelscope download --model=FluxLora/flux-ip-adapter --local_dir ./models/xlabs/ipadapters/flux-ip-adapter.safetensors
!modelscope download --model=FluxLora/flux-ip-adapter --local_dir ./models/clip_vision/clip_vision_l.safetensors
使用cloudflared运行ComfyUI
在jupyter notebook中执行以下命令,可快速运行ComfyUI!!
!wget "https://modelscope.oss-cn-beijing.aliyuncs.com/resource/cloudflared-linux-amd64.deb"
!dpkg -i cloudflared-linux-amd64.deb
%cd /mnt/workspace/ComfyUI
import subprocess
import threading
import time
import socket
import urllib.request
def iframe_thread(port):
while True:
time.sleep(0.5)
sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
result = sock.connect_ex(('127.0.0.1', port))
if result == 0:
break
sock.close()
print("\nComfyUI finished loading, trying to launch cloudflared (if it gets stuck here cloudflared is having issues)\n")
p = subprocess.Popen(["cloudflared", "tunnel", "--url", "http://127.0.0.1:{}".format(port)], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
for line in p.stderr:
l = line.decode()
if "trycloudflare.com " in l:
print("This is the URL to access ComfyUI:", l[l.find("http"):], end='')
#print(l, end='')
threading.Thread(target=iframe_thread, daemon=True, args=(8188,)).start()
!python main.py --dont-print-server
加载准备好的ComfyUI工作流:
❝工作流地址:
https://modelscope.oss-cn-beijing.aliyuncs.com/resource/workflow-flux-lora-simple.json
点击Queue Prompt即可快速生图!
作品分享
技术交流
加入「AIGCmagic社区」群聊,一起交流讨论,涉及 AI视频、AI绘画、Sora技术拆解、数字人、多模态、大模型、传统深度学习、自动驾驶等多个不同方向,可私信或添加微信号:【m_aigc2022】,备注不同方向邀请入群!!
往期文章
• 开源实操 | DiffIR2VR-Zero:模糊视频8K高清修复技术
• 太强了!快手的LivePortrait:肖像动画框架 | 可精准控制眼睛和嘴唇动作
• 商汤重磅推出Vimi——亮相WAIC,成为“镇馆之宝” | 2024世界人工智能大会
• FoleyCrafter:自动为视频配音 | 开源AI配音技术 | AI视频有声时代真的来了
• AI视频进入有声时代 | 谷歌 DeepMind 发布V2A:轻松给AI视频配音
• 变天啦!?| Luma 发布视频生成模型 Dream Machine,直逼电影级效果!
• UniAnimate:可控人体视频生成新框架,跳舞视频生成技术再添一员
• MOFA-Video:图像到视频的可控生成框架,可本地一键部署
• AIGC |「视频生成」系列之Hunyuan-DiT:基于DiT架构的最佳中文实践
• 「文生一切」大模型Lumina-T2X:一个框架整合图像、视频、音频和3D生成(附体验地址)