Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,23 +4,17 @@ from diffusers import AutoPipelineForImage2Image
|
|
4 |
from diffusers.utils import load_image
|
5 |
from PIL import Image
|
6 |
|
7 |
-
|
8 |
-
st.title("Stable Diffusion Image-to-Image Generation")
|
9 |
|
10 |
-
# Load the pipeline
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
pipeline.enable_model_cpu_offload()
|
20 |
-
pipeline.enable_xformers_memory_efficient_attention()
|
21 |
-
return pipeline
|
22 |
-
|
23 |
-
pipeline = load_pipeline()
|
24 |
|
25 |
# Upload an image
|
26 |
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
@@ -29,11 +23,9 @@ if uploaded_file:
|
|
29 |
init_image = Image.open(uploaded_file).convert("RGB")
|
30 |
st.image(init_image, caption="Uploaded Image", use_column_width=True)
|
31 |
|
32 |
-
# Prompt input
|
33 |
prompt = st.text_input("Enter a prompt", "A futuristic city at sunset")
|
34 |
|
35 |
-
# Generate button
|
36 |
if st.button("Generate Image"):
|
37 |
with st.spinner("Generating..."):
|
38 |
image = pipeline(prompt, image=init_image).images[0]
|
39 |
-
st.image(image, caption="Generated Image", use_column_width=True)
|
|
|
4 |
from diffusers.utils import load_image
|
5 |
from PIL import Image
|
6 |
|
7 |
+
st.title("Stable Diffusion Image-to-Image")
|
|
|
8 |
|
9 |
+
# Load the pipeline (no caching)
|
10 |
+
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
11 |
+
"stabilityai/stable-diffusion-2-1",
|
12 |
+
torch_dtype=torch.float16,
|
13 |
+
variant="fp16",
|
14 |
+
use_safetensors=True
|
15 |
+
)
|
16 |
+
pipeline.enable_model_cpu_offload()
|
17 |
+
pipeline.enable_xformers_memory_efficient_attention()
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
# Upload an image
|
20 |
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
|
|
23 |
init_image = Image.open(uploaded_file).convert("RGB")
|
24 |
st.image(init_image, caption="Uploaded Image", use_column_width=True)
|
25 |
|
|
|
26 |
prompt = st.text_input("Enter a prompt", "A futuristic city at sunset")
|
27 |
|
|
|
28 |
if st.button("Generate Image"):
|
29 |
with st.spinner("Generating..."):
|
30 |
image = pipeline(prompt, image=init_image).images[0]
|
31 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|