Spaces:
Sleeping
Sleeping
File size: 1,013 Bytes
8360c81 1aed7a5 8360c81 1aed7a5 8360c81 1aed7a5 ba138bc 8360c81 1aed7a5 8360c81 1aed7a5 8360c81 1aed7a5 8360c81 1aed7a5 8360c81 ba138bc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 | # 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")
|