Generate AI images using Stable Diffusion models directly in your browser with WebGPU acceleration. All processing happens locally on your GPU - no server required!
- π¨ Text-to-Image Generation - Create images from text descriptions
- π WebGPU Acceleration - Uses your GPU via browser WebGPU API
- π Multiple Models - Choose from SD 1.5, SD 2.1, SDXL, SD Turbo, and SDXL Turbo
- π 100% Private - All processing happens locally, nothing is sent to servers
- πΎ Model Caching - Models are cached in browser after first download
- βοΈ Advanced Controls - Adjust steps, guidance scale, negative prompts, and seeds
- π Dark Mode - Beautiful UI with dark mode support
- π± Responsive - Works on desktop and tablet devices
WebGPU is required to run this application. Supported browsers:
| Browser | Minimum Version | Notes |
|---|---|---|
| Chrome | 113+ | β Recommended, WebGPU enabled by default |
| Edge | 113+ | β WebGPU enabled by default |
| Opera | 99+ | β WebGPU enabled by default |
| Firefox | Nightly | |
| Safari | Tech Preview |
To check if your browser supports WebGPU:
- Open the developer console (F12)
- Type:
navigator.gpu - If it returns an object, WebGPU is available
- Node.js 16+ and npm
- A WebGPU-compatible browser (see requirements above)
- A GPU with at least 4GB VRAM
- Clone the repository:
git clone <repository-url>
cd stable-diffusion-webgpu- Install dependencies:
npm install- Start the development server:
npm run dev- Open your browser and navigate to
http://localhost:3000
npm run buildThe built files will be in the dist directory. You can serve them with any static file server.
- Check Status - Ensure WebGPU is supported (green checkmark in Status panel)
- Select Model - Choose a Stable Diffusion model from the dropdown
- Wait for Loading - First time loading a model will download ~2-8GB (cached afterwards)
- Enter Prompt - Describe the image you want to generate
- Generate - Click "Generate Image" or press Ctrl+Enter
- Download - Save your generated image using the Download button
Click "Advanced Options" in the Prompt Input section to access:
- Negative Prompt - Describe what you don't want in the image
- Steps - Number of denoising steps (more = better quality, slower)
- Guidance Scale - How closely to follow the prompt (7-8 is typical)
- Seed - Set to -1 for random, or use a specific number for reproducible results
Ctrl + Enter- Generate image from prompt- Click dark/light mode icon in header to toggle theme
| Model | Resolution | VRAM | Speed | Quality | Best For |
|---|---|---|---|---|---|
| SD 1.5 | 512x512 | ~4GB | Fast | Good | Most compatible, great for testing |
| SD 2.1 | 768x768 | ~5GB | Medium | Better | Improved quality and resolution |
| SDXL | 1024x1024 | ~8GB | Slow | Excellent | Highest quality, detailed images |
| SD Turbo | 512x512 | ~4GB | Very Fast | Good | Rapid iteration, 1-4 steps |
| SDXL Turbo | 1024x1024 | ~8GB | Fast | Excellent | Best of both worlds |
- First Load - Model download can take 5-15 minutes depending on your connection
- Close Other Apps - Close GPU-intensive applications for best performance
- Browser Memory - Large models may use 4-8GB of RAM in addition to VRAM
- Generation Time - First generation is slower, subsequent ones are faster
- Steps - Use fewer steps (15-20) for faster results while testing
- Turbo Models - Use Turbo variants for rapid iteration
Problem: "WebGPU is not supported" error
Solutions:
- Update to the latest version of Chrome, Edge, or Opera
- Ensure your GPU drivers are up to date
- On Linux, you may need to enable GPU acceleration in browser flags
- Check if hardware acceleration is enabled:
chrome://settings/?search=hardware
Problem: Model fails to load or download
Solutions:
- Check your internet connection
- Clear browser cache and try again
- Ensure you have enough disk space (models are 2-8GB each)
- Try a different model (start with SD 1.5)
Problem: Browser crashes or shows out of memory errors
Solutions:
- Choose a smaller model (SD 1.5 instead of SDXL)
- Close other browser tabs and applications
- Reduce the number of steps
- Check available VRAM: smaller GPUs may not support larger models
Problem: Image generation takes too long
Solutions:
- Use Turbo models for faster generation
- Reduce the number of steps (try 15-25)
- Ensure no other GPU-intensive apps are running
- First generation is always slower - subsequent ones improve
stable-diffusion-webgpu/
βββ index.html # Entry point
βββ package.json # Dependencies
βββ vite.config.js # Vite configuration
βββ tailwind.config.js # Tailwind CSS config
βββ src/
βββ main.jsx # React entry point
βββ App.jsx # Main application component
βββ index.css # Global styles
βββ components/ # React components
β βββ ModelSelector.jsx
β βββ PromptInput.jsx
β βββ ImageDisplay.jsx
β βββ StatusPanel.jsx
βββ services/ # Business logic
β βββ stableDiffusion.js
βββ utils/ # Utilities
β βββ webgpuCheck.js
βββ config/ # Configuration
βββ models.js
The application uses a service-based architecture:
- React Components - UI layer
- Stable Diffusion Service - Handles model loading and inference
- WebGPU Utils - Browser capability detection
- Model Config - Model definitions and parameters
This project is designed to work with WebGPU-based Stable Diffusion implementations. The current code provides a complete interface and placeholder implementation. To use actual Stable Diffusion inference, you need to:
- Install a WebGPU-compatible SD library (e.g., web-txt2img, ONNX Runtime Web)
- Update
src/services/stableDiffusion.jswith the library's API - Verify model IDs in
src/config/models.jsmatch available models
- React 18 - UI framework
- Vite - Build tool and dev server
- Tailwind CSS - Styling
- WebGPU API - GPU acceleration
- Browser Support - WebGPU is still relatively new and not universally supported
- Model Size - Large downloads required for first use
- Memory Usage - Requires significant RAM and VRAM
- Mobile - Not recommended for mobile devices due to resource requirements
- Library Integration - Actual SD inference requires additional WebGPU library integration
- Image-to-image transformation
- Inpainting support
- ControlNet integration
- Multiple image generation (batch mode)
- Generation history/gallery
- Prompt templates and examples
- Settings persistence
- Progressive image preview during generation
Contributions are welcome! Please feel free to submit issues or pull requests.
This project is provided as-is for educational and research purposes.
- Stable Diffusion by Stability AI
- WebGPU specification by W3C
- React and Vite communities
- Tailwind CSS team
For issues and questions:
- Check the Troubleshooting section above
- Open an issue on GitHub
- Check browser WebGPU compatibility at https://caniuse.com/webgpu
Note: This application requires actual WebGPU Stable Diffusion library integration to perform real image generation. The current implementation includes placeholder generation for demonstration purposes.