Spaces:
Runtime error
Runtime error
Commit
·
00641c3
1
Parent(s):
0a8dd47
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import torch
|
| 3 |
from diffusers import StableDiffusionXLPipeline
|
|
@@ -6,18 +7,25 @@ from diffusers import StableDiffusionXLPipeline
|
|
| 6 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 7 |
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
|
| 8 |
)
|
| 9 |
-
pipe = pipe.to("cpu") # Move the model to
|
| 10 |
|
| 11 |
# Create a Streamlit app
|
| 12 |
-
st.title("
|
| 13 |
|
| 14 |
# Add a text input for the prompt
|
| 15 |
-
prompt = st.
|
|
|
|
|
|
|
|
|
|
| 16 |
|
| 17 |
# Generate the image based on the prompt
|
| 18 |
-
if st.button("Generate
|
| 19 |
-
#
|
| 20 |
-
|
|
|
|
|
|
|
| 21 |
|
| 22 |
-
|
| 23 |
-
|
|
|
|
|
|
|
|
|
| 1 |
+
# Import necessary libraries
|
| 2 |
import streamlit as st
|
| 3 |
import torch
|
| 4 |
from diffusers import StableDiffusionXLPipeline
|
|
|
|
| 7 |
pipe = StableDiffusionXLPipeline.from_pretrained(
|
| 8 |
"stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
|
| 9 |
)
|
| 10 |
+
pipe = pipe.to("cpu") # Move the model to CPU for processing
|
| 11 |
|
| 12 |
# Create a Streamlit app
|
| 13 |
+
st.title("Stable Diffusion XL Image Generation")
|
| 14 |
|
| 15 |
# Add a text input for the prompt
|
| 16 |
+
prompt = st.text_area("Enter your prompt here", "Type your prompt here...")
|
| 17 |
+
|
| 18 |
+
# Add an info text to provide guidance
|
| 19 |
+
st.markdown("This app uses Stable Diffusion XL to generate an image based on the given prompt.")
|
| 20 |
|
| 21 |
# Generate the image based on the prompt
|
| 22 |
+
if st.button("Generate"):
|
| 23 |
+
with st.spinner("Generating..."): # Display a spinner while generating the image
|
| 24 |
+
try:
|
| 25 |
+
# Use the model to generate the image
|
| 26 |
+
image = pipe(prompt).images[0]
|
| 27 |
|
| 28 |
+
# Display the generated image
|
| 29 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
| 30 |
+
except Exception as e:
|
| 31 |
+
st.error(f"An error occurred: {e}")
|