Spaces:
Sleeping
Sleeping
Update app.py (#2)
Browse files- Update app.py (6e20d0d4101667b89f3bd80a80ee26a7d55a4d36)
app.py
CHANGED
@@ -6,35 +6,33 @@ import torch
|
|
6 |
from PIL import Image
|
7 |
import io
|
8 |
|
9 |
-
# Load model on CPU
|
10 |
@st.cache_resource
|
11 |
def load_model():
|
12 |
pipe = StableDiffusionPipeline.from_pretrained(
|
13 |
-
"runwayml/stable-diffusion-v1-5",
|
14 |
-
torch_dtype=torch.float32
|
|
|
15 |
)
|
16 |
-
|
|
|
17 |
|
18 |
-
#
|
19 |
-
st.title("
|
20 |
-
st.markdown("
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
"A multi-dimensional alien city with glowing fractals, floating geometry, cosmic lighting, 8K resolution")
|
25 |
|
26 |
-
guidance = st.slider("Creativity (Guidance Scale)", 1.0, 20.0,
|
27 |
|
28 |
-
# Generate button
|
29 |
if st.button("Generate Image"):
|
30 |
-
with st.spinner("Generating image
|
31 |
pipe = load_model()
|
32 |
image = pipe(prompt, guidance_scale=guidance).images[0]
|
33 |
|
34 |
st.image(image, caption="Generated Image", use_column_width=True)
|
35 |
|
36 |
-
# Save for download
|
37 |
buf = io.BytesIO()
|
38 |
image.save(buf, format="PNG")
|
39 |
-
|
40 |
-
st.download_button("Download Image", byte_im, "generated.png", "image/png")
|
|
|
6 |
from PIL import Image
|
7 |
import io
|
8 |
|
9 |
+
# Load model on CPU only
|
10 |
@st.cache_resource
|
11 |
def load_model():
|
12 |
pipe = StableDiffusionPipeline.from_pretrained(
|
13 |
+
"runwayml/stable-diffusion-v1-5",
|
14 |
+
torch_dtype=torch.float32, # CPU needs float32
|
15 |
+
use_auth_token=True # If needed for private models
|
16 |
)
|
17 |
+
pipe.to("cpu") # Ensure it's forced to CPU
|
18 |
+
return pipe
|
19 |
|
20 |
+
# UI
|
21 |
+
st.title("🎨 AI Image Generator (CPU Compatible)")
|
22 |
+
st.markdown("No GPU? No problem. This app runs Stable Diffusion entirely on your CPU.")
|
23 |
|
24 |
+
prompt = st.text_area("Enter your prompt:",
|
25 |
+
"A surreal multi-dimensional alien forest with glowing trees and floating rocks, 8K")
|
|
|
26 |
|
27 |
+
guidance = st.slider("Creativity (Guidance Scale)", 1.0, 20.0, 7.5)
|
28 |
|
|
|
29 |
if st.button("Generate Image"):
|
30 |
+
with st.spinner("Generating image on CPU... this may take 2-5 minutes."):
|
31 |
pipe = load_model()
|
32 |
image = pipe(prompt, guidance_scale=guidance).images[0]
|
33 |
|
34 |
st.image(image, caption="Generated Image", use_column_width=True)
|
35 |
|
|
|
36 |
buf = io.BytesIO()
|
37 |
image.save(buf, format="PNG")
|
38 |
+
st.download_button("Download Image", buf.getvalue(), "generated.png", "image/png")
|
|