Spaces:
Sleeping
Sleeping
File size: 1,071 Bytes
32e29ce 10bd232 32e29ce 228d591 ac9823f 32e29ce 162eb52 228d591 32e29ce 228d591 de28523 32e29ce 10bd232 32e29ce 228d591 10bd232 |
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 33 34 |
import streamlit as st
from diffusers import DiffusionPipeline
import torch
from PIL import Image
from huggingface_hub import login
# Optional: Log in to Hugging Face (if using private models)
# login(token="your_huggingface_token")
# Streamlit app title
st.title("Stable Diffusion Image Generator")
# Load the diffusion pipeline (make sure you have access to the model)
pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1-base", torch_dtype=torch.float32)
pipe.to("cpu") # Ensure it's using CPU
# Get user input (prompt)
prompt = st.text_input("What do you want to see?", "A beautiful landscape")
# Button to generate image
if st.button('Generate Image'):
with st.spinner('Generating...'):
try:
# Generate image
image = pipe(prompt).images[0]
# Display image in Streamlit
st.image(image, caption="Generated Image", use_column_width=True)
st.success("Image generated successfully!")
except Exception as e:
st.error(f"An error occurred: {str(e)}")
|