Stable Diffusion server built with FastAPI
Project description
Stable Diffusion Google Colab FastAPI Server
Note: This is a pretty hacky server / client interface for generic Stable Diffusion pipelines using diffusers. It's not made for production use and hasn't really been optimized completely.
Installation
From pip:
pip install sd-server
From source:
git clone git@github.com:shyamsn97/stable-diffusion-server.git
cd stable-diffusion-server/
python setup.py install
Stable Diffusion Server + Client Interface -- Simple Usage
Here we create a simple server hosting the standard StableDiffusionPipeline. The client takes in **kwargs that should be the arguments passed into the __call__ function from the pipeline. For instance, the StableDiffusionPipeline __call__ method can be found: https://github.com/huggingface/diffusers/blob/main/src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py#L185. host and port can be specified in the start method for generic hosting.
from sd_server import DiffusersServer, DiffusersClient
from diffusers import StableDiffusionPipeline
STABLE_DIFFUSION_PATH = "runwayml/stable-diffusion-v1-5" # this can be a local path
pipeline_kwargs = {
"revision":"fp16",
"torch_dtype":torch.float16
}
device = torch.device('cuda')
server = DiffusersServer.create(
pretrained_path = STABLE_DIFFUSION_PATH,
pipeline_cls = StableDiffusionPipeline,
pipeline_kwargs = pipeline_kwargs,
enable_attention_slicing = True,
device = device
)
url = server.start(host="127.0.0.1", port=8000) # url -- either remote or local
# on another host / terminal
client = DiffusersClient(url)
responses = client(prompt='a photo of an astronaut riding a horse on mars', num_images_per_prompt=4) # this should return a list of images
Serving from Google Colab
Using the server in Google Colab requires an ngrok account, and needs your ngrok auth token https://dashboard.ngrok.com/get-started/your-authtoken to be passed to the server. Note: Ngrok basically opens a tunnel from a dev machine to the cloud, which means its not really that secure, and should be used at your own risk. Read more here: https://stackoverflow.com/questions/36552950/is-ngrok-safe-to-use-or-can-it-be-compromised
NGROK_AUTH_KEY = "your auth key from https://dashboard.ngrok.com/get-started/your-authtoken"
... # imports from above
server = DiffusersServer.create(
pretrained_path = STABLE_DIFFUSION_PATH,
pipeline_cls = StableDiffusionPipeline,
pipeline_kwargs = pipeline_kwargs,
enable_attention_slicing = True,
device = device
)
url = server.start(ngrok_auth_token=NGROK_AUTH_KEY)
# on another host
client = DiffusersClient(url)
responses = client(prompt='a photo of an astronaut riding a horse on mars', num_images_per_prompt=4) # this should return a list of images
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sd-server-0.1.0.tar.gz.
File metadata
- Download URL: sd-server-0.1.0.tar.gz
- Upload date:
- Size: 5.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d6a62d204249268f1b123a8a3b9b14bc90e67d92afe6ba1e5c180d21beb4b48a
|
|
| MD5 |
c99fc4e4a1de0a1d6c765208016301cc
|
|
| BLAKE2b-256 |
b4961ecf459dfc020301594a916f36c2aa486a8a655018734b51ea94f0cf478b
|
File details
Details for the file sd_server-0.1.0-py3.9.egg.
File metadata
- Download URL: sd_server-0.1.0-py3.9.egg
- Upload date:
- Size: 9.0 kB
- Tags: Egg
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3de39ee01a7e04863485488b3d865e9a458c88f4e17bfefea4e1139dc92df8c5
|
|
| MD5 |
d6e7f0feaf6dbd4d9677c403756619ed
|
|
| BLAKE2b-256 |
7f5b377339ff5ceafd40b77bc699bf3b3dc285c7fb6c455edd0b753e99ccbb96
|
File details
Details for the file sd_server-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sd_server-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.9.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fdc8780177c2292a6660a592656d386cde19ad112510e05a29c5a02f5806c707
|
|
| MD5 |
3ea2510179b1543b5d2dac5aa9a0d751
|
|
| BLAKE2b-256 |
26109def98289c355a69fa8d7a4ceac153df60b1290886776136d4e6ebef06d6
|