Spaces:
Sleeping
Sleeping
CaioXapelaum
commited on
Commit
•
f025a7e
1
Parent(s):
c445d10
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
from diffusers import DiffusionPipeline
|
3 |
+
import torch
|
4 |
+
from PIL import Image
|
5 |
+
from io import BytesIO
|
6 |
+
|
7 |
+
# Load the diffusion pipeline
|
8 |
+
@st.cache_resource
|
9 |
+
def load_pipeline():
|
10 |
+
return DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-xl-base-1.0").to("cuda" if torch.cuda.is_available() else "cpu")
|
11 |
+
|
12 |
+
pipeline = load_pipeline()
|
13 |
+
|
14 |
+
def generate_image(prompt):
|
15 |
+
# Generate image
|
16 |
+
with torch.no_grad():
|
17 |
+
result = pipeline(prompt).images[0]
|
18 |
+
return result
|
19 |
+
|
20 |
+
def main():
|
21 |
+
st.title("Stable Diffusion Image Generator")
|
22 |
+
|
23 |
+
# Get user input
|
24 |
+
prompt = st.text_input("Enter a prompt for image generation:")
|
25 |
+
|
26 |
+
if st.button("Generate Image"):
|
27 |
+
if prompt:
|
28 |
+
# Generate and display the image
|
29 |
+
image = generate_image(prompt)
|
30 |
+
st.image(image, caption="Generated Image")
|
31 |
+
else:
|
32 |
+
st.warning("Please enter a prompt.")
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
main()
|