Spaces:
Runtime error
Runtime error
Commit
·
c71ff3f
1
Parent(s):
00641c3
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,31 +1,28 @@
|
|
| 1 |
-
# Import necessary libraries
|
| 2 |
import streamlit as st
|
| 3 |
-
import
|
| 4 |
-
|
| 5 |
|
| 6 |
-
# Load the
|
| 7 |
-
|
| 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 |
-
#
|
| 13 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
-
#
|
| 16 |
-
|
| 17 |
|
| 18 |
-
#
|
| 19 |
-
st.
|
| 20 |
|
| 21 |
-
#
|
| 22 |
-
|
| 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 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
|
|
|
|
|
|
|
|
| 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)
|