# app.py import streamlit as st from diffusers import StableDiffusionPipeline import torch from PIL import Image import io @st.cache_resource def load_model(): # Force CPU-only execution pipe = StableDiffusionPipeline.from_pretrained( "runwayml/stable-diffusion-v1-5" ) pipe.to("cpu") return pipe st.title("🧠 AI Image Generator (CPU Only)") prompt = st.text_input("Enter your prompt:", "A surreal multi-dimensional fractal landscape in vivid colors") guidance = st.slider("Guidance scale (higher = more creative)", 1.0, 20.0, 7.5) if st.button("Generate"): with st.spinner("Generating on CPU... please wait 2–5 minutes."): pipe = load_model() image = pipe(prompt, guidance_scale=guidance).images[0] st.image(image, caption="Generated Image", use_column_width=True) buf = io.BytesIO() image.save(buf, format="PNG") st.download_button("Download Image", buf.getvalue(), "generated.png", "image/png")