Spaces:
Running
Running
phyloforfun
commited on
Commit
·
70865fd
1
Parent(s):
026faf8
file upload gallery
Browse files
app.py
CHANGED
@@ -557,46 +557,46 @@ def image_to_base64(img):
|
|
557 |
img.save(buffered, format="JPEG")
|
558 |
return base64.b64encode(buffered.getvalue()).decode()
|
559 |
|
560 |
-
def display_image_gallery():
|
561 |
-
|
562 |
-
|
563 |
-
|
564 |
-
|
565 |
-
|
566 |
-
|
567 |
-
|
568 |
-
|
569 |
-
|
570 |
-
|
571 |
-
|
572 |
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
578 |
-
|
579 |
-
|
580 |
-
|
581 |
-
|
582 |
-
|
583 |
-
|
584 |
-
|
585 |
-
|
586 |
-
|
587 |
-
|
588 |
-
|
589 |
-
|
590 |
-
|
591 |
-
|
592 |
-
|
593 |
-
|
594 |
-
|
595 |
-
|
596 |
-
|
597 |
-
|
598 |
-
|
599 |
-
|
600 |
|
601 |
def display_image_gallery():
|
602 |
# Initialize the container
|
@@ -608,21 +608,22 @@ def display_image_gallery():
|
|
608 |
"""
|
609 |
|
610 |
# Loop through each image in the input list
|
611 |
-
|
612 |
-
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
|
621 |
-
|
622 |
-
<
|
623 |
-
|
624 |
-
|
625 |
-
|
|
|
626 |
|
627 |
|
628 |
# Close the div for the image grid
|
|
|
557 |
img.save(buffered, format="JPEG")
|
558 |
return base64.b64encode(buffered.getvalue()).decode()
|
559 |
|
560 |
+
# def display_image_gallery():
|
561 |
+
# """
|
562 |
+
# Display an image gallery from st.session_state['input_list'] in a scrollable container.
|
563 |
+
# Each image will have a maximum width of 500 pixels.
|
564 |
+
# """
|
565 |
+
# # Initialize the container
|
566 |
+
# con_image = st.empty()
|
567 |
+
# with con_image.container():
|
568 |
+
# # Loop through each image in the input list
|
569 |
+
# for image_path in st.session_state['input_list']:
|
570 |
+
# img = Image.open(image_path)
|
571 |
+
# img.thumbnail((120, 120), Image.Resampling.LANCZOS)
|
572 |
|
573 |
+
# # Convert the image to base64
|
574 |
+
# base64_image = image_to_base64(img)
|
575 |
+
|
576 |
+
# # Embed the image with the determined width in the custom div
|
577 |
+
# img_html = f"""
|
578 |
+
# <div style='display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 400px;'>
|
579 |
+
# <img src='data:image/jpeg;base64,{base64_image}' alt='Image' style='max-width: 100%; height: auto;'>
|
580 |
+
# </div>
|
581 |
+
# """
|
582 |
+
|
583 |
+
# # Apply the image with HTML
|
584 |
+
# st.markdown(img_html, unsafe_allow_html=True)
|
585 |
+
|
586 |
+
# # The CSS to make the images display inline and be responsive
|
587 |
+
# css = """
|
588 |
+
# <style>
|
589 |
+
# @media (max-width: 120px) {
|
590 |
+
# .scrollable-image-container img {
|
591 |
+
# max-width: 100%;
|
592 |
+
# height: 400px;
|
593 |
+
# height: auto;
|
594 |
+
# }
|
595 |
+
# }
|
596 |
+
# </style>
|
597 |
+
# """
|
598 |
+
# # Apply the CSS
|
599 |
+
# st.markdown(css, unsafe_allow_html=True)
|
600 |
|
601 |
def display_image_gallery():
|
602 |
# Initialize the container
|
|
|
608 |
"""
|
609 |
|
610 |
# Loop through each image in the input list
|
611 |
+
with con_image.container():
|
612 |
+
for image_path in st.session_state['input_list']:
|
613 |
+
# Open the image and create a thumbnail
|
614 |
+
img = Image.open(image_path)
|
615 |
+
img.thumbnail((120, 120), Image.Resampling.LANCZOS)
|
616 |
+
|
617 |
+
# Convert the image to base64
|
618 |
+
base64_image = image_to_base64(img)
|
619 |
+
|
620 |
+
# Append the image to the grid HTML
|
621 |
+
img_html = f"""
|
622 |
+
<div style='display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 400px;'>
|
623 |
+
<img src='data:image/jpeg;base64,{base64_image}' alt='Image' style='max-width: 100%; height: auto;'>
|
624 |
+
</div>
|
625 |
+
"""
|
626 |
+
st.markdown(img_html, unsafe_allow_html=True)
|
627 |
|
628 |
|
629 |
# Close the div for the image grid
|