Kvikontent commited on
Commit
c71ff3f
1 Parent(s): 00641c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -24
app.py CHANGED
@@ -1,31 +1,28 @@
1
- # Import necessary libraries
2
  import streamlit as st
3
- import torch
4
- from diffusers import StableDiffusionXLPipeline
5
 
6
- # Load the stable diffusion model
7
- pipe = StableDiffusionXLPipeline.from_pretrained(
8
- "stabilityai/stable-diffusion-xl-base-1.0", torch_dtype=torch.float16
9
- )
10
- pipe = pipe.to("cpu") # Move the model to CPU for processing
11
 
12
- # Create a Streamlit app
13
- st.title("Stable Diffusion XL Image Generation")
 
 
 
 
14
 
15
- # Add a text input for the prompt
16
- prompt = st.text_area("Enter your prompt here", "Type your prompt here...")
17
 
18
- # Add an info text to provide guidance
19
- st.markdown("This app uses Stable Diffusion XL to generate an image based on the given prompt.")
20
 
21
- # Generate the image based on the prompt
22
- if st.button("Generate"):
23
- with st.spinner("Generating..."): # Display a spinner while generating the image
24
- try:
25
- # Use the model to generate the image
26
- image = pipe(prompt).images[0]
27
 
28
- # Display the generated image
29
- st.image(image, caption="Generated Image", use_column_width=True)
30
- except Exception as e:
31
- st.error(f"An error occurred: {e}")
 
 
 
1
  import streamlit as st
2
+ from diffusers import DiffusionPipeline
3
+ import time
4
 
5
+ # Load the DiffusionPipeline model
6
+ pipeline = DiffusionPipeline.from_pretrained("stabilityai/sdxl-turbo")
 
 
 
7
 
8
+ # Function to generate and display the image
9
+ def generate_and_display_image(prompt):
10
+ # Generate an image based on the prompt
11
+ image = pipeline(prompt)
12
+ # Display the generated image
13
+ st.image(image, caption='Generated Image', use_column_width=True)
14
 
15
+ # Main app code
16
+ st.title('Real-time Image Generation App')
17
 
18
+ # User input for the prompt with a placeholder
19
+ prompt = st.text_input('Enter your prompt', value='', help='Enter your prompt here...')
20
 
21
+ # Initialize the image display
22
+ image_placeholder = st.empty()
 
 
 
 
23
 
24
+ # Continuously generate and display the image based on the prompt
25
+ while True:
26
+ generate_and_display_image(prompt)
27
+ # Sleep for a short duration to avoid excessive CPU usage
28
+ time.sleep(1)