Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,34 @@
|
|
1 |
import streamlit as st
|
2 |
-
from diffusers import
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
import os
|
7 |
|
8 |
-
# Force CPU usage
|
9 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
10 |
|
11 |
@st.cache_resource
|
12 |
def load_model():
|
13 |
-
pipe =
|
14 |
-
"
|
15 |
-
torch_dtype=torch.float32
|
16 |
)
|
17 |
-
pipe.to("cpu")
|
18 |
return pipe
|
19 |
|
20 |
-
|
21 |
-
st.title("🎨 AI Image Generator (CPU - Hugging Face Spaces)")
|
22 |
|
23 |
prompt = st.text_input("Enter your prompt:",
|
24 |
-
"A
|
25 |
|
26 |
-
guidance = st.slider("
|
27 |
|
28 |
-
if st.button("Generate"):
|
29 |
-
with st.spinner("Generating image on CPU...
|
30 |
pipe = load_model()
|
31 |
-
|
|
|
32 |
|
33 |
st.image(image, caption="Generated Image", use_column_width=True)
|
34 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from diffusers import AutoPipelineForText2Image
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
import io
|
6 |
import os
|
7 |
|
8 |
+
# Force CPU usage
|
9 |
os.environ["CUDA_VISIBLE_DEVICES"] = ""
|
10 |
|
11 |
@st.cache_resource
|
12 |
def load_model():
|
13 |
+
pipe = AutoPipelineForText2Image.from_pretrained(
|
14 |
+
"stabilityai/sd-turbo",
|
15 |
+
torch_dtype=torch.float32 # CPU-compatible
|
16 |
)
|
17 |
+
pipe.to("cpu")
|
18 |
return pipe
|
19 |
|
20 |
+
st.title("⚡ Fast AI Image Generator (under 1 minute)")
|
|
|
21 |
|
22 |
prompt = st.text_input("Enter your prompt:",
|
23 |
+
"A glowing alien city with floating islands and neon rivers, concept art, 8K")
|
24 |
|
25 |
+
guidance = st.slider("Guidance scale (higher = more faithful to prompt)", 1.0, 10.0, 3.0)
|
26 |
|
27 |
+
if st.button("Generate Image"):
|
28 |
+
with st.spinner("Generating image (approx. 20–40 seconds on CPU)..."):
|
29 |
pipe = load_model()
|
30 |
+
result = pipe(prompt, guidance_scale=guidance, num_inference_steps=20)
|
31 |
+
image = result.images[0]
|
32 |
|
33 |
st.image(image, caption="Generated Image", use_column_width=True)
|
34 |
|