/SDCN-Stable-Diffusion-Computing-Network

SDCN is an infrastructure that allows people to share and use Stable Diffusion computing power easily.

Primary LanguageTypeScriptMIT LicenseMIT

DAN logo

License PRs Welcome GitHub Contributors Last Commit

Website | Playground | API Docs

Overview

DAN is an infrastructure for sharing Stable Diffusion computing power

  • Decentralization: By running the DAN node program, users can register their idle computing resources with the DAN network
  • Trustlessness: DAN abstracts the capabilities of Stable Diffusion into a set of atomic interface calls and hides the computing process from application developers
  • Powerful: Application developers can quickly develop their own applications based on the Stable Diffusion related capabilities provided by DAN, without worrying about how these interfaces are implemented or how computing power is provided

DAN structure

  • DAN Node
    • Executes image generation tasks
    • Use Stable Diffusion WebUI with API mode directly
  • DAN Server
    • Manage and route image generation tasks to DAN Nodes
    • Hide the image generating details and expose a standard interface to application developers
    • Implement DAN server with openresty
  • API
    • txt2img
    • img2img
    • integrate
    • more APIs under developing

Why DAN?

  • Everyone should have the ability to use AI freely, AI will be a public good
  • For the public, the cost of trying various ways of stable diffusion is too high
    • It's difficult to set up a stable diffusion runtime environment on your own
    • Computer performance may not support it
    • Downloading code from GitHub and running Stable Diffusion WebUI is beyond the ability of most non-programmers(even programmers)
    • Learning about models and prompt knowledge requires high learning costs
  • More application developers should be supported in popularizing AI capabilities to the public
  • For application developers, the cost of building a publicly available image generation service is too high
    • Application developers should focus on implementing business requirements
  • The utilization of GPU computing power for home and cloud procurement is very low, leading to significant wastage

Getting Started

Try out DAN functionalities in DAN website.

๐ŸŽˆFeel free to file tickets for bugs or feature requests.


๐Ÿ“ฑ How-to: try out DAN API

DAN provide SaaS-like API from https://api.opendan.ai

Using dan_run.py script

Try the sample code in example folder.

You can modify the example/params-xxx.json to experiment with different parameter combinations.

python3 dan_run.py txt2img params-txt2img.json OUTPUT_IMAGE.png
python3 dan_run.py img2img params-img2img.json ORIGINAL_IMAGE.png OUTPUT_IMAGE.png

Using curl

  1. Install curl and jq
brew install curl jq
  1. Enter example folder and execute
cd example
cat params-txt2img.json \
| curl --location --request POST 'https://api.opendan.ai/api/sd/txt2img' \
--header 'Content-Type: application/json' -d @- \
| jq '.data.images[0]' |tr -d '\"' | tr -d '\\' | base64 -d > out.png

๐Ÿ‘‰ DAN API refer to API Docs


๐ŸŒ How-to: contribute computing power to opendan.ai

  1. Register a donor account on opendan.ai
  2. Install lastest Stable Diffusion WebUI on your PC or Server
  3. Install the following models & loras::
  1. Startup Stable Diffusion WebUI with --listen --api --share argument
bash webui.sh --listen --api --share

You will get a public URL like https://f00bfa54-7b3c-476b.gradio.live

  1. Login donor account on opendan.ai and register the public URL to global node list

๐Ÿ”จ How-to: run dan-server locally in Docker

  1. Install lastest Stable Diffusion WebUI and Docker on your PC or Server

  2. Install the following models & loras:

  1. Startup Stable Diffusion WebUI with --listen --api argument
bash webui.sh --listen --api
  1. Register a new github OAuth Application set callback url: http://localhost:6006/api/user/connect/github. Get the github client ID and SECRET:, then set in the docker-compose.yml.

  2. Start dan-server locally in docker with Docker Compose:

docker-compose up -d 

Now your dan-server is available on "http://127.0.0.1:6006"

  1. Register your Stable Diffusion WebUI instance as a DAN node:
  • Login your account using DAN's web page: http://127.0.0.1:6006;
  • Navigate to Nodes -> Donate Node
  • Enter your worker node's address
  • Click Donate

โš ๏ธ Please note that you must use non-loopback IP address in your node's address! You cannot use 127.0.0.1 or 'localhost' since our docker container's hostnet is not enabled.

  1. Config SERVICE_PREFIX in example/dan_run.py to "http://127.0.0.1:6006".
SERVICE_PREFIX = 'http://127.0.0.1:6006'
  1. Execute the example with your local dan-server:
python3 dan_run.py txt2img params-txt2img.json OUTPUT_IMAGE.png

Roadmap

  • Rename project to DAN
  • Management GUI for computing power donors
    • Add login to the DAN website
    • CRUD management of computing power provided by donors
  • Workload ranking page
    • Node-based workload ranking
    • Donor-based workload ranking
    • Model-based workload ranking
    • API-based workload ranking
  • Basic DAN functional interfaces
    • Scale interface
    • Inpaint interface
    • Support for controlnet
  • Enrich examples in the playground
    • 2D to 3D style conversion
    • 3D to 2D style conversion
  • One-click installation of Stable Diffusion WebUI as an DAN node (Windows & Linux supported)
    • Customize Stable Diffusion WebUI installer
    • Automatically download necessary model files
    • Customize DAN node daemon as intermediary for communication between Stable Diffusion WebUI and DAN server
  • Image Stream (user generated by the DAN tool and share to opendan.ai)
    • Sharing mechanisms for images generated through API or playground
    • A page to display shared images in a waterfall flow
  • Constraints for the use of computing resources
    • API-Key mechanism
    • honor(credit) system
  • Task scheduling mechanism
    • Schedule to nodes with required models already loaded
    • Global load balancing

License

This project is licensed under the MIT license


Credits