Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
import streamlit as st
|
2 |
-
from diffusers import
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
|
6 |
# Streamlit App Title
|
7 |
st.title("🖼️ Stable Diffusion Image Generator")
|
8 |
-
st.write("Generate images from text prompts using Stable Diffusion
|
9 |
|
10 |
# Sidebar for prompt input and button
|
11 |
st.sidebar.title("Image Generation Settings")
|
12 |
prompt = st.sidebar.text_input("Enter your prompt", "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
|
13 |
generate_button = st.sidebar.button("Generate Image")
|
14 |
|
15 |
-
# Cache the Stable Diffusion
|
16 |
@st.cache_resource
|
17 |
def load_model():
|
18 |
-
model =
|
19 |
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
20 |
return model
|
21 |
|
|
|
1 |
import streamlit as st
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
|
6 |
# Streamlit App Title
|
7 |
st.title("🖼️ Stable Diffusion Image Generator")
|
8 |
+
st.write("Generate images from text prompts using Stable Diffusion!")
|
9 |
|
10 |
# Sidebar for prompt input and button
|
11 |
st.sidebar.title("Image Generation Settings")
|
12 |
prompt = st.sidebar.text_input("Enter your prompt", "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
|
13 |
generate_button = st.sidebar.button("Generate Image")
|
14 |
|
15 |
+
# Cache the Stable Diffusion model to load it only once
|
16 |
@st.cache_resource
|
17 |
def load_model():
|
18 |
+
model = DiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5", torch_dtype=torch.float16)
|
19 |
model = model.to("cuda" if torch.cuda.is_available() else "cpu")
|
20 |
return model
|
21 |
|