Spaces:
Running
Running
Commit
·
026faf8
1
Parent(s):
644099c
file upload gallery
Browse files
app.py
CHANGED
|
@@ -557,47 +557,46 @@ def image_to_base64(img):
|
|
| 557 |
img.save(buffered, format="JPEG")
|
| 558 |
return base64.b64encode(buffered.getvalue()).decode()
|
| 559 |
|
| 560 |
-
|
| 561 |
-
|
| 562 |
-
|
| 563 |
-
|
| 564 |
-
|
| 565 |
-
#
|
| 566 |
-
|
| 567 |
-
|
| 568 |
-
#
|
| 569 |
-
|
| 570 |
-
|
| 571 |
-
|
| 572 |
-
# img.thumbnail((120, 120), Image.Resampling.LANCZOS) # This modifies 'img' in place
|
| 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 |
|
| 602 |
def display_image_gallery():
|
| 603 |
# Initialize the container
|
|
@@ -612,15 +611,19 @@ def display_image_gallery():
|
|
| 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 |
-
|
| 622 |
-
<
|
| 623 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 624 |
|
| 625 |
# Close the div for the image grid
|
| 626 |
img_grid_html += "</div>"
|
|
|
|
| 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
|
|
|
|
| 611 |
for image_path in st.session_state['input_list']:
|
| 612 |
# Open the image and create a thumbnail
|
| 613 |
img = Image.open(image_path)
|
| 614 |
+
img.thumbnail((120, 120), Image.Resampling.LANCZOS)
|
| 615 |
|
| 616 |
# Convert the image to base64
|
| 617 |
base64_image = image_to_base64(img)
|
| 618 |
|
| 619 |
# Append the image to the grid HTML
|
| 620 |
+
img_html = f"""
|
| 621 |
+
<div style='display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 400px;'>
|
| 622 |
+
<img src='data:image/jpeg;base64,{base64_image}' alt='Image' style='max-width: 100%; height: auto;'>
|
| 623 |
+
</div>
|
| 624 |
+
"""
|
| 625 |
+
st.markdown(img_html, unsafe_allow_html=True)
|
| 626 |
+
|
| 627 |
|
| 628 |
# Close the div for the image grid
|
| 629 |
img_grid_html += "</div>"
|