Sign inSign up

xavierh/small-x-studio

By xavierh

•Updated 3 days ago

Image
0

32

xavierh/small-x-studio repository overview

⁠Small X Studio

Text-to-image generation that runs entirely in the browser.

Uses danyalmalik/small-sd-ONNX-WebGPU⁠ exported to ONNX, based off of segmind/small-sd⁠. The .NET app is only a static host. It serves the page, the runtime files and the model files. Everything happens locally in your browser.

On first start the host downloads the models (about 1.6 GB) into models/ from Hugging Face. The browser then caches them with the Cache API.

image

⁠Run with Docker

docker compose up --build

⁠Then open http://localhost:8080⁠. The models are downloaded into the models volume on first start, so later starts skip the download. Use localhost (or HTTPS) in the address: browsers only enable WebGPU in a secure context. TODO

  • try to load a smaller model
  • ability to create larger images without increasing time to generate
  • making sure this works under Apple M-series chips

⁠Dependencies

⁠.NET SDK (net10.0)

The project has no NuGet package references. Everything above is part of the .NET shared framework.

⁠JavaScript (browser)
DependencyVersionLicenseLocation
onnxruntime-web⁠1.29.0MITwwwroot/lib/onnxruntime-web/ (self-hosted, no CDN)

Files used from onnxruntime-web:

  • ort.webgpu.min.mjs (66 KB): the runtime ES module.
  • ort-wasm-simd-threaded.asyncify.mjs (51 KB) and .wasm (25 MB): the WebAssembly runtime, used by every backend.

There are no other JavaScript libraries, bundlers or npm install steps. The app code is plain ES modules:

  • wwwroot/js/browser-sd.js: the CLIP tokenizer, DPM-Solver++ scheduler and diffusion pipeline.
  • wwwroot/js/device-check.js: device detection, requirement checks and CPU time estimates.

The page itself is wwwroot/index.html.

⁠Model
ItemSourceSize
Text encoder (fp16 weights)danyalmalik/small-sd-ONNX-WebGPU⁠ text_encoder/model.onnx246 MB
UNet (fp16 weights)same repo, unet/model.onnx1.16 GB
VAE decoder (fp32)same repo, vae_decoder/model.onnx198 MB
Tokenizersame repo, tokenizer/vocab.json, tokenizer/merges.txt1.6 MB

To change the repository or the download folder, edit the StableDiffusion section in appsettings.json. For the model's license, see the model cards on Hugging Face.

⁠Browser features
FeatureNeeded for
WebGPU with shader-f16GPU backend (fastest)
WebNN (navigator.ml, GPU device)DirectML backend on Windows. Experimental: in Chrome, enable --enable-features=WebMachineLearningNeuralNetwork
WebAssembly SIMD + threads (SharedArrayBuffer)CPU backend. Threads need cross-origin isolation, which the host turns on with COOP/COEP headers
Web WorkersRun CPU inference off the main thread (ONNX Runtime proxy worker)
Cache API, Storage APICache the model files and check free disk space
CanvasTurn the output into PNG

The page detects which of these are available and shows whether the device meets the requirements.

Tag summary

Content type

Image

Digest

sha256:e3cc39e7e…

Size

108.3 MB

Last updated

3 days ago

docker pull xavierh/small-x-studio