--- title: Stable Diffusion Equation Playground emoji: 🧪 colorFrom: indigo colorTo: green sdk: gradio sdk_version: 5.22.0 python_version: "3.10" app_file: app.py pinned: false license: mit models: - stable-diffusion-v1-5/stable-diffusion-v1-5 preload_from_hub: - stable-diffusion-v1-5/stable-diffusion-v1-5 --- # Stable Diffusion Equation Playground A ZeroGPU-ready Gradio app for learning how Stable Diffusion works inside Diffusers. Instead of only calling `pipe(prompt)`, the app exposes a beginner-friendly custom denoising loop: - three prompt embeddings can be blended with simple strength sliders - the live equation shows the exact weighted embedding blend being used - a few Diffusers levers are exposed: seed, denoising steps, prompt guidance, and optional noise mixing - intermediate latent snapshots show how the image emerges across denoising steps The core idea to teach: Stable Diffusion starts from noise in VAE latent space. The prompt does not literally become half of the pixels. The prompt changes the UNet's predicted noise at every denoising step, most commonly through classifier-free guidance: ```python guided = negative_prediction + guidance_scale * (prompt_prediction - negative_prediction) ``` This app focuses on `StableDiffusionPipeline` checkpoints such as Stable Diffusion 1.5 because the embedding pathway is straightforward for students. SDXL uses two text encoders plus pooled prompt embeddings, so the same idea carries over, but the code is more complex. ## Running On Hugging Face Spaces, select ZeroGPU hardware in the Space settings. The image generation function is decorated with `@spaces.GPU`, so it requests a GPU only while a generation is running. For local development, install the requirements, use a CUDA or MPS machine, then run: ```bash python app.py ``` The default model is `stable-diffusion-v1-5/stable-diffusion-v1-5`. The first generation downloads the checkpoint from Hugging Face and may take a few minutes.