Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -40,6 +40,8 @@ if "window_size" not in st.session_state:
|
|
40 |
st.session_state.window_size = 5
|
41 |
if "current_window_start" not in st.session_state:
|
42 |
st.session_state.current_window_start = 0
|
|
|
|
|
43 |
|
44 |
|
45 |
TOKEN = os.getenv("TOKEN0")
|
@@ -349,13 +351,16 @@ def main_app():
|
|
349 |
st.warning("Please enter a prompt to generate an image.")
|
350 |
|
351 |
st.header("Your Generated Images")
|
352 |
-
|
353 |
if "current_window_start" not in st.session_state:
|
354 |
st.session_state.current_window_start = 0
|
355 |
|
356 |
if "window_size" not in st.session_state:
|
357 |
st.session_state.window_size = 5 # The number of images to display at a time
|
358 |
-
|
|
|
|
|
|
|
359 |
# Create left and right arrow buttons
|
360 |
col_left, col_center, col_right = st.columns([1,8,1])
|
361 |
|
@@ -385,28 +390,34 @@ def main_app():
|
|
385 |
cols = st.columns(num_images_to_display)
|
386 |
for i, image_data in enumerate(images_for_window):
|
387 |
with cols[i]:
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
|
393 |
-
|
394 |
-
|
395 |
-
|
396 |
-
|
397 |
-
|
398 |
-
|
399 |
-
st.image(image_data['thumbnail_url'], width = 150) # display thumbnail
|
400 |
-
|
401 |
-
else:
|
402 |
-
st.image(image_data['image_url'], width = 150)
|
403 |
-
st.write(f"**Prompt:** {image_data['prompt']}")
|
404 |
-
st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
|
405 |
-
st.write(f"**Realism:** {image_data['realism']}")
|
406 |
-
st.markdown("---")
|
407 |
else:
|
408 |
st.write("No image generated yet!")
|
409 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
410 |
# Logout button
|
411 |
if st.button("Logout", on_click=logout_callback):
|
412 |
pass
|
|
|
40 |
st.session_state.window_size = 5
|
41 |
if "current_window_start" not in st.session_state:
|
42 |
st.session_state.current_window_start = 0
|
43 |
+
if "selected_image" not in st.session_state:
|
44 |
+
st.session_state.selected_image = None
|
45 |
|
46 |
|
47 |
TOKEN = os.getenv("TOKEN0")
|
|
|
351 |
st.warning("Please enter a prompt to generate an image.")
|
352 |
|
353 |
st.header("Your Generated Images")
|
354 |
+
# Initialize the current window, if it doesn't exist in session state
|
355 |
if "current_window_start" not in st.session_state:
|
356 |
st.session_state.current_window_start = 0
|
357 |
|
358 |
if "window_size" not in st.session_state:
|
359 |
st.session_state.window_size = 5 # The number of images to display at a time
|
360 |
+
|
361 |
+
if "selected_image" not in st.session_state:
|
362 |
+
st.session_state.selected_image = None
|
363 |
+
|
364 |
# Create left and right arrow buttons
|
365 |
col_left, col_center, col_right = st.columns([1,8,1])
|
366 |
|
|
|
390 |
cols = st.columns(num_images_to_display)
|
391 |
for i, image_data in enumerate(images_for_window):
|
392 |
with cols[i]:
|
393 |
+
if image_data.get('thumbnail_url') and image_data.get('image_url'):
|
394 |
+
if st.button("More", key = f"more_{i}"):
|
395 |
+
st.session_state.selected_image = image_data
|
396 |
+
|
397 |
+
st.image(image_data['thumbnail_url'], width = 150)
|
398 |
+
else:
|
399 |
+
st.image(image_data['image_url'], width = 150)
|
400 |
+
st.write(f"**Prompt:** {image_data['prompt']}")
|
401 |
+
st.write(f"**Aspect Ratio:** {image_data['aspect_ratio']}")
|
402 |
+
st.write(f"**Realism:** {image_data['realism']}")
|
403 |
+
st.markdown("---")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
404 |
else:
|
405 |
st.write("No image generated yet!")
|
406 |
|
407 |
+
|
408 |
+
# Display modal if an image is selected
|
409 |
+
if st.session_state.selected_image:
|
410 |
+
with st.container(border = True):
|
411 |
+
st.image(st.session_state.selected_image['image_url'], use_column_width=True)
|
412 |
+
st.write(f"**Prompt:** {st.session_state.selected_image['prompt']}")
|
413 |
+
st.write(f"**Aspect Ratio:** {st.session_state.selected_image['aspect_ratio']}")
|
414 |
+
st.write(f"**Realism:** {st.session_state.selected_image['realism']}")
|
415 |
+
download_path = download_image(st.session_state.selected_image['image_url'])
|
416 |
+
if download_path:
|
417 |
+
st.download_button(label="Download Image", data = open(download_path, "rb"), file_name = f"image.png")
|
418 |
+
if st.button("Close"):
|
419 |
+
st.session_state.selected_image = None # close the modal when "close" is clicked
|
420 |
+
|
421 |
# Logout button
|
422 |
if st.button("Logout", on_click=logout_callback):
|
423 |
pass
|