Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import matplotlib.pyplot as plt
|
3 |
from PIL import Image
|
4 |
from diffusers import StableDiffusionPipeline
|
@@ -19,29 +20,28 @@ def generate_and_display_image(prompt_text):
|
|
19 |
image.save(image_path)
|
20 |
|
21 |
# Show success message
|
22 |
-
|
23 |
|
24 |
# Display the generated image
|
25 |
display_image(image_path)
|
26 |
|
27 |
except Exception as e:
|
28 |
# Show error message if an error occurs
|
29 |
-
|
30 |
|
31 |
# Function to display image
|
32 |
def display_image(image_path):
|
33 |
# Open the generated image
|
34 |
generated_image = Image.open(image_path)
|
35 |
-
|
36 |
-
plt.axis('off')
|
37 |
-
plt.show()
|
38 |
|
39 |
# Model parameters
|
40 |
model_id = "CompVis/stable-diffusion-v1-4"
|
41 |
device = "cuda"
|
42 |
|
43 |
-
#
|
44 |
-
prompt_text =
|
45 |
|
46 |
-
# Generate and display image
|
47 |
-
|
|
|
|
1 |
import os
|
2 |
+
import streamlit as st
|
3 |
import matplotlib.pyplot as plt
|
4 |
from PIL import Image
|
5 |
from diffusers import StableDiffusionPipeline
|
|
|
20 |
image.save(image_path)
|
21 |
|
22 |
# Show success message
|
23 |
+
st.write("Image generated successfully!")
|
24 |
|
25 |
# Display the generated image
|
26 |
display_image(image_path)
|
27 |
|
28 |
except Exception as e:
|
29 |
# Show error message if an error occurs
|
30 |
+
st.error(f"An error occurred: {str(e)}")
|
31 |
|
32 |
# Function to display image
|
33 |
def display_image(image_path):
|
34 |
# Open the generated image
|
35 |
generated_image = Image.open(image_path)
|
36 |
+
st.image(generated_image, use_column_width=True)
|
|
|
|
|
37 |
|
38 |
# Model parameters
|
39 |
model_id = "CompVis/stable-diffusion-v1-4"
|
40 |
device = "cuda"
|
41 |
|
42 |
+
# Streamlit text input for prompt
|
43 |
+
prompt_text = st.text_input("Enter the prompt:")
|
44 |
|
45 |
+
# Generate and display image if prompt is provided
|
46 |
+
if prompt_text:
|
47 |
+
generate_and_display_image(prompt_text)
|