Spaces:
Runtime error
Runtime error
File size: 902 Bytes
c20699f | 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 streamlit as st
from diffusers import StableDiffusionPipeline
from PIL import Image
import torch
# Function to load the model
@st.cache(allow_output_mutation=True)
def load_model():
# Replace 'your_token_here' with your actual Hugging Face token
YOUR_TOKEN = "your_token_here"
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
return pipe
# Load the model
pipe = load_model()
# Streamlit interface
st.title("Text-to-Image Generation with Stable Diffusion")
# Text input for the prompt
prompt = st.text_input("Enter your prompt:")
# Generate button
if st.button("Generate Image"):
with st.spinner('Generating image...'):
# Generate image
image = pipe(prompt).images[0]
# Convert to PIL Image to display
img = Image.fromarray(image)
st.image(img, caption="Generated Image")
|