Spaces:
Running
Running
ZainFaisal
commited on
Upload app.py
Browse files
app.py
CHANGED
@@ -3,23 +3,22 @@ import torch
|
|
3 |
from diffusers import StableDiffusionXLPipeline
|
4 |
from PIL import Image
|
5 |
|
6 |
-
# Load the model
|
7 |
@st.cache_resource()
|
8 |
def load_model():
|
9 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
10 |
"cagliostrolab/animagine-xl-4.0",
|
11 |
-
torch_dtype=torch.
|
12 |
use_safetensors=True,
|
13 |
custom_pipeline="lpw_stable_diffusion_xl",
|
14 |
add_watermarker=False
|
15 |
)
|
16 |
-
#
|
17 |
-
return pipe
|
18 |
|
19 |
pipe = load_model()
|
20 |
|
21 |
# Streamlit UI
|
22 |
-
st.title("Text-to-Image Generator")
|
23 |
|
24 |
# User input
|
25 |
prompt = st.text_area("Enter your prompt:", "1girl, arima kana, oshi no ko, looking at viewer, smile")
|
@@ -29,20 +28,23 @@ guidance_scale = st.slider("Guidance Scale", 1.0, 10.0, 6.0, step=0.5)
|
|
29 |
inference_steps = st.slider("Inference Steps", 10, 50, 25, step=5)
|
30 |
|
31 |
if st.button("Generate Image"):
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
|
|
|
|
42 |
image_path = "generated_image.png"
|
43 |
image.save(image_path)
|
44 |
-
|
45 |
-
|
46 |
-
# Provide download option
|
47 |
with open(image_path, "rb") as file:
|
48 |
st.download_button(label="Download Image", data=file, file_name="generated_image.png", mime="image/png")
|
|
|
|
|
|
|
|
3 |
from diffusers import StableDiffusionXLPipeline
|
4 |
from PIL import Image
|
5 |
|
6 |
+
# Load the model (CPU version)
|
7 |
@st.cache_resource()
|
8 |
def load_model():
|
9 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
10 |
"cagliostrolab/animagine-xl-4.0",
|
11 |
+
torch_dtype=torch.float32, # Change to float32 for CPU
|
12 |
use_safetensors=True,
|
13 |
custom_pipeline="lpw_stable_diffusion_xl",
|
14 |
add_watermarker=False
|
15 |
)
|
16 |
+
return pipe # Do NOT move to CUDA
|
|
|
17 |
|
18 |
pipe = load_model()
|
19 |
|
20 |
# Streamlit UI
|
21 |
+
st.title("Text-to-Image Generator (CPU)")
|
22 |
|
23 |
# User input
|
24 |
prompt = st.text_area("Enter your prompt:", "1girl, arima kana, oshi no ko, looking at viewer, smile")
|
|
|
28 |
inference_steps = st.slider("Inference Steps", 10, 50, 25, step=5)
|
29 |
|
30 |
if st.button("Generate Image"):
|
31 |
+
try:
|
32 |
+
with st.spinner("Generating image..."):
|
33 |
+
image = pipe(
|
34 |
+
prompt,
|
35 |
+
width=width,
|
36 |
+
height=height,
|
37 |
+
guidance_scale=guidance_scale,
|
38 |
+
num_inference_steps=inference_steps
|
39 |
+
).images[0]
|
40 |
+
|
41 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
42 |
+
|
43 |
image_path = "generated_image.png"
|
44 |
image.save(image_path)
|
45 |
+
|
|
|
|
|
46 |
with open(image_path, "rb") as file:
|
47 |
st.download_button(label="Download Image", data=file, file_name="generated_image.png", mime="image/png")
|
48 |
+
|
49 |
+
except Exception as e:
|
50 |
+
st.error(f"Error generating image: {e}")
|