Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from diffusers import StableDiffusionXLPipeline
|
3 |
+
import torch
|
4 |
+
from PIL import Image
|
5 |
+
|
6 |
+
# Initialize pipeline
|
7 |
+
@st.cache_resource
|
8 |
+
def load_pipeline():
|
9 |
+
pipe = StableDiffusionXLPipeline.from_pretrained(
|
10 |
+
"segmind/SSD-1B",
|
11 |
+
torch_dtype=torch.float16,
|
12 |
+
use_safetensors=True,
|
13 |
+
variant="fp16"
|
14 |
+
)
|
15 |
+
pipe.to("cuda") # Change to "cpu" if no GPU available
|
16 |
+
return pipe
|
17 |
+
|
18 |
+
pipe = load_pipeline()
|
19 |
+
|
20 |
+
# Streamlit app interface
|
21 |
+
st.title("Stable Diffusion XL Prompt-to-Image Generator")
|
22 |
+
st.write("Enter a prompt to generate an image using the Stable Diffusion XL model.")
|
23 |
+
|
24 |
+
# User inputs
|
25 |
+
user_prompt = st.text_input("Enter your prompt:", "cute cat sitting on the chair")
|
26 |
+
negative_prompt = st.text_input("Enter a negative prompt (optional):", "ugly, blurry, poor quality")
|
27 |
+
|
28 |
+
# Generate button
|
29 |
+
if st.button("Generate Image"):
|
30 |
+
with st.spinner("Generating image..."):
|
31 |
+
# Generate image
|
32 |
+
generated_image = pipe(prompt=user_prompt, negative_prompt=negative_prompt).images[0]
|
33 |
+
st.image(generated_image, caption="Generated Image", use_column_width=True)
|