{"id":13758868,"url":"https://github.com/hafriedlander/stable-diffusion-grpcserver","last_synced_at":"2025-07-23T02:34:06.682Z","repository":{"id":62462427,"uuid":"536107018","full_name":"hafriedlander/stable-diffusion-grpcserver","owner":"hafriedlander","description":"An implementation of a server for the Stability AI Stable Diffusion API","archived":false,"fork":false,"pushed_at":"2023-01-06T00:51:04.000Z","size":4280,"stargazers_count":173,"open_issues_count":4,"forks_count":23,"subscribers_count":7,"default_branch":"main","last_synced_at":"2025-06-20T22:06:41.135Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hafriedlander.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-09-13T12:06:17.000Z","updated_at":"2025-06-03T07:44:29.000Z","dependencies_parsed_at":"2023-02-05T01:01:01.028Z","dependency_job_id":null,"html_url":"https://github.com/hafriedlander/stable-diffusion-grpcserver","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hafriedlander/stable-diffusion-grpcserver","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hafriedlander%2Fstable-diffusion-grpcserver","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hafriedlander%2Fstable-diffusion-grpcserver/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hafriedlander%2Fstable-diffusion-grpcserver/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hafriedlander%2Fstable-diffusion-grpcserver/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hafriedlander","download_url":"https://codeload.github.com/hafriedlander/stable-diffusion-grpcserver/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hafriedlander%2Fstable-diffusion-grpcserver/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266591703,"owners_count":23953084,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-22T02:00:09.085Z","response_time":66,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-03T13:00:39.061Z","updated_at":"2025-07-23T02:34:06.656Z","avatar_url":"https://github.com/hafriedlander.png","language":"Python","readme":"An implementation of a server for the Stability AI API\n\n# Features\n\n## Standard Stable Diffusion features\n\n- Create an image from just a text prompt (txt2img)\n- Create an image from an existing image and a text prompt (img2img)\n- Fill in a hole in an image, or extend an image (inpainting)\n\n## Enhancements\n\n- Enhanced inpainting and outpainting, including Grafted Inpainting\n  - When used with the standard Stable Diffusion V1.5 model, results are more consistent to the existing image\n  - When used with a model such as Waifu Diffusion that does not have an inpaint model, can either \"graft\"\n    the model on top of the Stable Diffusion inpainting or work in an exclusive model-independant model\n- Custom CLIP guidance allows using newer CLIP models to more accurately follow prompts\n  - Faster and better results than the standard Diffusers version\n- Negative prompting and weighting of parts of a promt (send multiple `Prompt` objects with `text` and any positive or negative `weight`)\n- All K_Diffusion schedulers available, and working correctly (including DPM2, DPM2 Ancestral and Heun\n- Can load multiple pipelines, such as Stable and Waifu Diffusion, and swap between them as needed\n- Adjustable NSFW behaviour\n- Potentially lower memory requirements using a variety of model offloading techniques\n- Cancel over API (using GRPC cancel will abort the currently in progress generation)\n- Various performance optimisations\n  + XFormers support, if installed\n  + ToMe support, if nonfree code included (recommend XFormers instead where available, but ToMe doesn't have complicated dependancies)\n  \n# Installation\n\n## Colab (coming soon)\n\n## Docker (easiest if you already have Docker, and an Nvidia GPU with 4GB+ VRAM)\n\n```\ndocker run --gpus all -it -p 50051:50051 \\\n  -e HF_API_TOKEN={your huggingface token} \\\n  -e SD_LISTEN_TO_ALL=1 \\\n  -v $HOME/.cache/huggingface:/huggingface \\\n  -v `pwd`/weights:/weights \\\n  hafriedlander/stable-diffusion-grpcserver:xformers-latest\n```\n\n#### Localtunnel\n\nThe docker image has built-in support for localtunnel, which\nwill expose the GRPC-WEB endpoint on an https domain. It will\nautomatically set an access token key if you don't provide one.\nCheck your Docker log for the values to use\n\n```\n  -e SD_LOCALTUNNEL=1 \\\n```\n\n#### Volume mounts\n\nThis will share the weights and huggingface cache, but you can\nmount other folders into the volume to do other things:\n\n- You can check out the latest version of the server code and then\nmount it into the Docker image to run the very latest code (including\nany local edits you make)\n\n  ```\n    -v `pwd`/sdgrpcserver:/sdgrpcserver \\\n  ```\n\n- Or override the engines.yaml config by making a config directory,\nputting the engines.yaml in there, and mounting it to the image\n\n  ```\n   -v `pwd`/config:/config \\\n  ```\n\nAll the server arguments can be provided as environment variables, starting\nwith SD:\n\n- SD_ENGINECFG\n- SD_GRPC_PORT\n- SD_HTTP_PORT\n- SD_VRAM_OPTIMISATION_LEVEL\n- SD_NSFW_BEHAVIOUR\n- SD_WEIGHT_ROOT\n- SD_HTTP_FILE_ROOT\n- SD_ACCESS_TOKEN\n- SD_LISTEN_TO_ALL\n- SD_ENABLE_MPS\n- SD_RELOAD\n- SD_LOCALTUNNEL\n\n#### Building the image locally\n\n```\ndocker build --target main .\n```\n\nOr to build (slowly) with xformers\n\n```\ndocker build --target xformers .\n```\n\n## Locally (if you have an Nvidia GPU with 4GB+ VRAM, and prefer not to use Docker)\n\n### Option 1 (recommended):\n\nInstall Miniconda, then in a Conda console:\n\n```\ngit clone https://github.com/hafriedlander/stable-diffusion-grpcserver.git\ncd stable-diffusion-grpcserver\nconda env create -f environment.yaml\nconda activate sd-grpc-server\n```\n\nThen for Windows:\n\n```\nset PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cu116 \nflit install --pth-file\nset HF_API_TOKEN={your huggingface token}\npython ./server.py\n```\n\nOr for Linux\n\n```\nPIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cu116 flit install --pth-file\nHF_API_TOKEN={your huggingface token} python ./server.py\n```\n\n### Option 2:\n\nCreate a directory and download https://raw.githubusercontent.com/hafriedlander/stable-diffusion-grpcserver/main/engines.yaml into it, then\n\n```\nset PIP_EXTRA_INDEX_URL=https://download.pytorch.org/whl/cu116 \npip install stable-diffusion-grpcserver\nset HF_API_TOKEN={your huggingface token} \nsdgrpcserver\n```\n\n\n# Thanks to / Credits:\n\n- Seamless outpainting https://github.com/parlance-zz/g-diffuser-bot/tree/g-diffuser-bot-beta2\n- Additional schedulers https://github.com/hlky/diffusers\n- K-Diffusion integration example https://github.com/Birch-san/diffusers/blob/1472b70194ae6d7e51646c0d6787815a5bc65f75/examples/community/play.py\n\n# Roadmap\n\nCore API functions not working yet:\n\n- ChainGenerate not implemented\n\nExtra features to add\n\n- Progress reporting over the API is included but not exposed yet\n- Embedding params in png\n- Extra APIs\n  - Image resizing\n  - Aspect ratio shifting\n  - Asset management\n  - Extension negotiation so we can:\n    - Ping back progress notices\n    - Allow cancellation requests\n    - Specify negative prompts\n- Community features: \n  - Prompt calculation https://github.com/pharmapsychotic/clip-interrogator/blob/main/clip_interrogator.ipynb\n  - Prompt suggestion https://huggingface.co/spaces/Gustavosta/MagicPrompt-Stable-Diffusion\n  - Prompt compositing https://github.com/energy-based-model/Compositional-Visual-Generation-with-Composable-Diffusion-Models-PyTorch\n  - Automasking https://github.com/ThstereforeGames/txt2mask\n  - Huge seeds\n\n\n# License\n\nThe main codebase is distributed under Apache-2.0. Dependancies are all compatible with that license, except as noted here:\n\n- The nonfree directory contains code under some license that is more restrictive than Apache-2.0. Check the individual\n  projects for license details. To fully comply with the Apache-2.0 license, remove this folder before release.\n  + ToMe\n  + Codeformer\n- The Docker images contain a bunch of software under various open source licenses. The docker images tagged 'noncomm'\n  include the nonfree folder, and so cannot be used commercially.\n\n[![Stable Cabal Logo](stablecabal.png)](https://www.stablecabal.org/)\n","funding_links":[],"categories":["Community Links"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhafriedlander%2Fstable-diffusion-grpcserver","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhafriedlander%2Fstable-diffusion-grpcserver","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhafriedlander%2Fstable-diffusion-grpcserver/lists"}