File size: 1,119 Bytes
00641c3
a38a82a
ba0ed52
a38a82a
cf2baf5
a38a82a
 
 
 
00641c3
cf2baf5
a38a82a
00641c3
ba0ed52
a38a82a
00641c3
 
 
 
ba0ed52
a38a82a
00641c3
 
 
 
 
ba0ed52
00641c3
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Import necessary libraries
import streamlit as st
import torch
from diffusers import StableDiffusionXLPipeline

# Load the stable diffusion model
pipe = StableDiffusionXLPipeline.from_pretrained(
    "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
)
pipe = pipe.to("cpu")  # Move the model to CPU for processing

# Create a Streamlit app
st.title("Stable Diffusion XL Image Generation")

# Add a text input for the prompt
prompt = st.text_area("Enter your prompt here", "Type your prompt here...")

# Add an info text to provide guidance
st.markdown("This app uses Stable Diffusion XL to generate an image based on the given prompt.")

# Generate the image based on the prompt
if st.button("Generate"):
    with st.spinner("Generating..."):  # Display a spinner while generating the image
        try:
            # Use the model to generate the image
            image = pipe(prompt).images[0]

            # Display the generated image
            st.image(image, caption="Generated Image", use_column_width=True)
        except Exception as e:
            st.error(f"An error occurred: {e}")