Dua Rajper commited on
Commit
ddf9887
·
verified ·
1 Parent(s): 9bc222d

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from diffusers import DiffusionPipeline
3
+ import torch
4
+
5
+ # Load the pre-trained model
6
+ @st.cache_resource
7
+ def load_model():
8
+ # Load the Stable Diffusion model from Hugging Face
9
+ pipe = DiffusionPipeline.from_pretrained("stabilityai/stable-diffusion-2-1", torch_dtype=torch.float16)
10
+ pipe.to("cuda") # Make sure to move the model to GPU if available
11
+ return pipe
12
+
13
+ # Initialize the model
14
+ pipe = load_model()
15
+
16
+ # Streamlit Interface
17
+ st.title("Text to Image Generator using Stable Diffusion 2.1")
18
+ st.write("Enter a description below, and the model will generate an image based on it.")
19
+
20
+ # Text input field for user to enter prompt
21
+ user_input = st.text_area("Enter the text prompt", "Astronaut in a jungle, cold color palette, muted colors, detailed, 8k")
22
+
23
+ if st.button("Generate Image"):
24
+ if user_input:
25
+ with st.spinner("Generating image..."):
26
+ # Generate image based on user input
27
+ generated_image = pipe(user_input).images