Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -2,13 +2,17 @@ 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 |
|
9 |
-
# Load the diffusion pipeline
|
10 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base", torch_dtype=torch.float32)
|
11 |
-
pipe.to("cpu") #
|
12 |
|
13 |
# Get user input (prompt)
|
14 |
prompt = st.text_input("What do you want to see?", "A beautiful landscape")
|
@@ -16,10 +20,14 @@ prompt = st.text_input("What do you want to see?", "A beautiful landscape")
|
|
16 |
# Button to generate image
|
17 |
if st.button('Generate Image'):
|
18 |
with st.spinner('Generating...'):
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
st.success("Image generated successfully!")
|
|
|
2 |
from diffusers import DiffusionPipeline
|
3 |
import torch
|
4 |
from PIL import Image
|
5 |
+
from huggingface_hub import login
|
6 |
+
|
7 |
+
# Optional: Log in to Hugging Face (if using private models)
|
8 |
+
# login(token="your_huggingface_token")
|
9 |
|
10 |
# Streamlit app title
|
11 |
st.title("Stable Diffusion Image Generator")
|
12 |
|
13 |
+
# Load the diffusion pipeline (make sure you have access to the model)
|
14 |
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base", torch_dtype=torch.float32)
|
15 |
+
pipe.to("cpu") # Ensure it's using CPU
|
16 |
|
17 |
# Get user input (prompt)
|
18 |
prompt = st.text_input("What do you want to see?", "A beautiful landscape")
|
|
|
20 |
# Button to generate image
|
21 |
if st.button('Generate Image'):
|
22 |
with st.spinner('Generating...'):
|
23 |
+
try:
|
24 |
+
# Generate image
|
25 |
+
image = pipe(prompt).images[0]
|
26 |
+
|
27 |
+
# Display image in Streamlit
|
28 |
+
st.image(image, caption="Generated Image", use_column_width=True)
|
29 |
+
|
30 |
+
st.success("Image generated successfully!")
|
31 |
+
except Exception as e:
|
32 |
+
st.error(f"An error occurred: {str(e)}")
|
33 |
|
|