Serverless ComfyUI
This guide shows how to deploy a ComfyUI server on Beam using Pod
. We’ll set up a server to generate images with Flux1 Schnell, but you can easily adapt it to use other models like Stable Diffusion v1.5.
View the Code
See the code for this example on Github.
Setting Up the ComfyUI Server
-
Create the Deployment Script
Create a file named
app.py
with the following code. This script sets up a BeamPod
with ComfyUI, installs dependencies, downloads the Flux1 Schnell model, and launches the server. -
Start ComfyUI
This deploys the ComfyUI server to Beam. After deployment, you’ll see a URL (e.g.,
https://pod-12345.apps.beam.cloud
) where your server is hosted.ComfyUI takes a minute or two to start after deploying it for the first time.
-
Accessing the Server
- Open the URL from your terminal in a browser to access the ComfyUI interface.
- Use the web UI to load workflows or generate images.
Using Different Models
You can swap the Flux1 Schnell model for another, such as Stable Diffusion v1.5, by updating the model variables in app.py
. Here’s how:
-
Update the Model Variables
Define the organization, repository, weights file, and commit ID for your desired model. For example, to use Stable Diffusion v1.5:
-
Apply to the Image Commands
The rest of the script uses these variables, so no further changes are needed to the
image
section: -
Find Model Details
To use any other model:
- Visit Comfy-Org Hugging Face and find your desired model.
- Update
ORG_NAME
,REPO_NAME
,WEIGHTS_FILE
, andCOMMIT
with values from the model’s repository. Check the “Files and versions” tab for the weights file and commit hash.
Running Workflows as APIs
You can also expose ComfyUI workflows as APIs using Beam’s ASGI support. This allows you to programmatically generate images by sending requests with prompts. Below is an example of how to set this up:
-
Create the API Script
-
Prepare a Workflow File
- Create a
workflow_api.json
file in the same directory asapp.py
. This file should contain your ComfyUI workflow, which you can export from the ComfyUI web interface.
- You can also store your
workflow_api.json
file in your Volume and use it likeWORKFLOW_FILE = Path("/your_volume/workflow_api.json")
- Create a
-
Deploy the API
-
Use the API
Send a POST request to the
/generate
endpoint with a JSON payload containing aprompt
:The response will include a public URL to the generated image:
Was this page helpful?