Spaces:
Sleeping
Sleeping
add cgange
Browse files
app.py
CHANGED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import torch
|
3 |
+
from diffusers import AutoPipelineForImage2Image
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
st.title("Stable Diffusion Image-to-Image")
|
7 |
+
|
8 |
+
# Load the pipeline
|
9 |
+
pipeline = AutoPipelineForImage2Image.from_pretrained(
|
10 |
+
"stabilityai/stable-diffusion-2-1",
|
11 |
+
torch_dtype=torch.float16,
|
12 |
+
variant="fp16",
|
13 |
+
use_safetensors=True
|
14 |
+
)
|
15 |
+
pipeline.enable_model_cpu_offload()
|
16 |
+
# pipeline.enable_xformers_memory_efficient_attention() # ❌ REMOVE OR COMMENT THIS LINE
|
17 |
+
|
18 |
+
# Upload an image
|
19 |
+
uploaded_file = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
20 |
+
|
21 |
+
if uploaded_file:
|
22 |
+
init_image = Image.open(uploaded_file).convert("RGB")
|
23 |
+
st.image(init_image, caption="Uploaded Image", use_column_width=True)
|
24 |
+
|
25 |
+
prompt = st.text_input("Enter a prompt", "A futuristic city at sunset")
|
26 |
+
|
27 |
+
if st.button("Generate Image"):
|
28 |
+
with st.spinner("Generating..."):
|
29 |
+
image = pipeline(prompt, image=init_image).images[0]
|
30 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|