启动前必须先构建前端,否则页面不可用;首次运行会从 Hugging Face 下载模型权重,可用 HF_HOME 挂载缓存复用;Docker 方式需要 NVIDIA Container Toolkit,且默认 pipeline 为 controlnet;本地用 Mobile Safari 测试需配置 HTTPS 证书。
Real-Time-Latent-Consistency-Model
radamesApache-2.0长期未更新基于 Diffusers 的实时扩散模型演示应用,用潜在一致性模型把文生图做到近乎即时的出图,并通过 MJPEG 推流展示生成过程。
App showcasing multiple real-time diffusion models pipelines with Diffusers
uv venv --python=3.10 && source .venv/bin/activate && uv pip install -r server/requirements.txt && cd frontend && npm install && npm run build && cd .. && python server/main.py --reload --pipeline img2imgSDTurbo需要 CUDA 和 Python 3.10,或使用 M1/M2/M3 芯片的 Mac、Intel Arc GPU;Hugging Face 配置建议 a10g-small,README 未给出具体显存数值。
用 Diffusers 跑实时扩散模型的 MJPEG 流式 Web 演示,支持摄像头图生图与文生图
基于 Diffusers 的实时扩散模型演示应用,用潜在一致性模型把文生图做到近乎即时的出图,并通过 MJPEG 推流展示生成过程。
核心能力
- 通过 MJPEG 流服务器实时推送扩散生成画面
- 内置 img2img、txt2img、ControlNet Canny 等多种 pipeline
- 支持 LCM-LoRA,4 步即可完成推理
- 覆盖 SD15、SDXL Turbo、SD Turbo、Segmind-Vega 等模型
- 可用 --torch-compile、--use-taesd 等参数优化推理
容易踩的坑
暂无 release 数据(可能没有发版,或尚未同步)。
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
title: Real-Time Latent Consistency Model Image-to-Image ControlNet emoji: 🖼️🖼️ colorFrom: gray colorTo: indigo sdk: docker pinned: false suggested_hardware: a10g-small disable_embedding: true
Real-Time Latent Consistency Model
This demo showcases Latent Consistency Model (LCM) using Diffusers with a MJPEG stream server. You can read more about LCM + LoRAs with diffusers here.
You need a webcam to run this demo. 🤗
See a collecting with live demos here
Running Locally
You need CUDA and Python 3.10, Node > 19, Mac with an M1/M2/M3 chip or Intel Arc GPU
Install
uv venv --python=3.10
source .venv/bin/activate
uv pip install -r server/requirements.txt
cd frontend && npm install && npm run build && cd ..
python server/main.py --reload --pipeline img2imgSDTurbo
Don't forget to fuild the frontend!!!
cd frontend && npm install && npm run build && cd ..
Pipelines
You can build your own pipeline following examples here here,
LCM
Image to Image
python server/main.py --reload --pipeline img2img
LCM
Text to Image
python server/main.py --reload --pipeline txt2img
Image to Image ControlNet Canny
python server/main.py --reload --pipeline controlnet
LCM + LoRa
Using LCM-LoRA, giving it the super power of doing inference in as little as 4 steps. Learn more here or technical report
Image to Image ControlNet Canny LoRa
python server/main.py --reload --pipeline controlnetLoraSD15
or SDXL, note that SDXL is slower than SD15 since the inference runs on 1024x1024 images
python server/main.py --reload --pipeline controlnetLoraSDXL
Text to Image
python server/main.py --reload --pipeline txt2imgLora
python server/main.py --reload --pipeline txt2imgLoraSDXL
Available Pipelines
LCM
img2img
txt2img
controlnet
txt2imgLora
controlnetLoraSD15
SD15
controlnetLoraSDXL
txt2imgLoraSDXL
SDXL Turbo
img2imgSDXLTurbo
controlnetSDXLTurbo
SDTurbo
img2imgSDTurbo
controlnetSDTurbo
Segmind-Vega
controlnetSegmindVegaRT
img2imgSegmindVegaRT
Setting environment variables
--host: Host address (default: 0.0.0.0)--port: Port number (default: 7860)--reload: Reload code on change--max-queue-size: Maximum queue size (optional)--timeout: Timeout period (optional)--safety-checker: Enable Safety Checker (optional)--torch-compile: Use Torch Compile--use-taesd/--no-taesd: Use Tiny Autoencoder--pipeline: Pipeline to use (default: "txt2img")--ssl-certfile: SSL Certificate File (optional)--ssl-keyfile: SSL Key File (optional)--debug: Print Inference time--compel: Compel option--pruna: Enable Pruna
If you run using bash build-run.sh you can set PIPELINE variables to choose the pipeline you want to run
PIPELINE=txt2imgLoraSDXL bash build-run.sh
and setting environment variables
TIMEOUT=120 SAFETY_CHECKER=True MAX_QUEUE_SIZE=4 python server/main.py --reload --pipeline txt2imgLoraSDXL
If you're running locally and want to test it on Mobile Safari, the webserver needs to be served over HTTPS, or follow this instruction on my comment
openssl req -newkey rsa:4096 -nodes -keyout key.pem -x509 -days 365 -out certificate.pem
python server/main.py --reload --ssl-certfile=certificate.pem --ssl-keyfile=key.pem
Docker
You need NVIDIA Container Toolkit for Docker, defaults to `controlnet``
docker build -t lcm-live .
docker run -ti -p 7860:7860 --gpus all lcm-live
reuse models data from host to avoid downloading them again, you can change ~/.cache/huggingface to any other directory, but if you use hugingface-cli locally, you can share the same cache
docker run -ti -p 7860:7860 -e HF_HOME=/data -v ~/.cache/huggingface:/data --gpus all lcm-live
or with environment variables
docker run -ti -e PIPELINE=txt2imgLoraSDXL -p 7860:7860 --gpus all lcm-live