| import streamlit as st |
| from diffusers import StableDiffusionPipeline |
| import torch |
|
|
| |
| st.title("Stable Diffusion Image Generator") |
| st.write("Enter a description, and AI will generate an image for you!") |
|
|
| |
| @st.cache_resource |
| def load_model(): |
| st.write("Loading the model... Please wait.") |
| device = "cuda" if torch.cuda.is_available() else "cpu" |
| pipe = StableDiffusionPipeline.from_pretrained("runwayml/stable-diffusion-v1-5").to(device) |
| return pipe |
|
|
| pipe = load_model() |
|
|
| |
| prompt = st.text_input("Enter your text prompt:") |
|
|
| |
| if st.button("Generate Image"): |
| if prompt: |
| with st.spinner("Generating image... Please wait."): |
| image = pipe(prompt).images[0] |
| st.image(image, caption="Generated Image", use_column_width=True) |
| else: |
| st.error("Please enter a prompt to generate an image.") |
|
|