Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,29 +60,29 @@ def generate_images(prompt): #def generate_images(image_description, num_images)
|
|
| 60 |
image_url = response.data[0].url
|
| 61 |
return image_url
|
| 62 |
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
|
| 87 |
|
| 88 |
|
|
|
|
| 60 |
image_url = response.data[0].url
|
| 61 |
return image_url
|
| 62 |
|
| 63 |
+
# Use a unique key for the text area to avoid conflicts with other session_state usages
|
| 64 |
+
image_description_prompt = st.text_area("Enter a description for the image you want to generate", key="image_description")
|
| 65 |
+
|
| 66 |
+
if st.button("Generate Images"):
|
| 67 |
+
with st.spinner("Analyzing the image ..."):
|
| 68 |
+
# Generate the image and store its URL in session_state
|
| 69 |
+
st.session_state['generated_image_url'] = generate_images(image_description_prompt)
|
| 70 |
+
|
| 71 |
+
# Check if the 'generated_image_url' key exists in session_state and display the image and download button
|
| 72 |
+
if 'generated_image_url' in st.session_state and st.session_state['generated_image_url']:
|
| 73 |
+
st.image(st.session_state['generated_image_url'], caption="Generated Image")
|
| 74 |
+
|
| 75 |
+
# Fetch the image from the URL to enable downloading
|
| 76 |
+
response = requests.get(st.session_state['generated_image_url'])
|
| 77 |
+
if response.status_code == 200:
|
| 78 |
+
img_bytes = BytesIO(response.content)
|
| 79 |
+
st.download_button(
|
| 80 |
+
label="Download Image",
|
| 81 |
+
data=img_bytes,
|
| 82 |
+
file_name="generated_image.png",
|
| 83 |
+
mime="image/png"
|
| 84 |
+
)
|
| 85 |
+
st.success('Powered by MTSS GPT. AI can make mistakes. Consider checking important information.')
|
| 86 |
|
| 87 |
|
| 88 |
|