Spaces:
Runtime error
Runtime error
Commit ·
8101a25
1
Parent(s): d818383
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
from diffusers import StableDiffusionPipeline
|
| 3 |
+
from PIL import Image
|
| 4 |
+
import torch
|
| 5 |
+
|
| 6 |
+
# Function to load the model
|
| 7 |
+
@st.cache(allow_output_mutation=True)
|
| 8 |
+
def load_model():
|
| 9 |
+
# Replace 'your_token_here' with your actual Hugging Face token
|
| 10 |
+
YOUR_TOKEN = ""
|
| 11 |
+
pipe = StableDiffusionPipeline.from_pretrained("CompVis/stable-diffusion-v1-4", use_auth_token=YOUR_TOKEN)
|
| 12 |
+
pipe = pipe.to("cuda")
|
| 13 |
+
return pipe
|
| 14 |
+
|
| 15 |
+
# Load the model
|
| 16 |
+
pipe = load_model()
|
| 17 |
+
|
| 18 |
+
# Streamlit interface
|
| 19 |
+
st.title("Text-to-Image Generation with Stable Diffusion")
|
| 20 |
+
|
| 21 |
+
# Text input for the prompt
|
| 22 |
+
prompt = st.text_input("Enter your prompt:")
|
| 23 |
+
|
| 24 |
+
# Generate button
|
| 25 |
+
if st.button("Generate Image"):
|
| 26 |
+
with st.spinner('Generating image...'):
|
| 27 |
+
# Generate image
|
| 28 |
+
image = pipe(prompt).images[0]
|
| 29 |
+
|
| 30 |
+
# Convert to PIL Image to display
|
| 31 |
+
img = Image.fromarray(image)
|
| 32 |
+
st.image(img, caption="Generated Image")
|