Spaces:
Running
Running
phyloforfun
commited on
Commit
•
ab9dab7
1
Parent(s):
b517827
file upload gallery
Browse files
app.py
CHANGED
@@ -557,80 +557,80 @@ 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 |
-
# 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 |
-
# # Convert the image to base64 (assuming you have this utility function)
|
571 |
-
# img_file = Image.open(image_path)
|
572 |
-
# base64_image = image_to_base64(img_file)
|
573 |
-
|
574 |
-
# # Embed the image with the determined width in the custom div
|
575 |
-
# img_html = f"""
|
576 |
-
# <div style='display: inline-block; padding: 10px; max-width: 100px;'>
|
577 |
-
# <img src='data:image/jpeg;base64,{base64_image}' alt='Image' style='max-width: 100%; height: auto;'>
|
578 |
-
# </div>
|
579 |
-
# """
|
580 |
-
|
581 |
-
# # Apply the image with HTML
|
582 |
-
# st.markdown(img_html, unsafe_allow_html=True)
|
583 |
-
|
584 |
-
# # The CSS to make the images display inline and be responsive
|
585 |
-
# css = """
|
586 |
-
# <style>
|
587 |
-
# @media (max-width: 100px) {
|
588 |
-
# .scrollable-image-container img {
|
589 |
-
# max-width: 100%;
|
590 |
-
# height: 400px;
|
591 |
-
# height: auto;
|
592 |
-
# }
|
593 |
-
# }
|
594 |
-
# </style>
|
595 |
-
# """
|
596 |
-
# # Apply the CSS
|
597 |
-
# st.markdown(css, unsafe_allow_html=True)
|
598 |
def display_image_gallery():
|
599 |
"""
|
600 |
Display an image gallery from st.session_state['input_list'] in a scrollable container.
|
601 |
-
Each image will
|
602 |
-
The container will be as wide as its containing Streamlit column and no more than 400px tall.
|
603 |
"""
|
604 |
# Initialize the container
|
605 |
con_image = st.empty()
|
606 |
with con_image.container():
|
607 |
-
# Start the gallery HTML with a div that will create a vertical scrolling effect
|
608 |
-
gallery_html = "<div style='display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 400px;'>"
|
609 |
-
|
610 |
# Loop through each image in the input list
|
611 |
for image_path in st.session_state['input_list']:
|
612 |
-
#
|
613 |
-
|
614 |
-
|
615 |
-
|
616 |
-
|
617 |
-
|
618 |
-
|
619 |
-
|
620 |
-
img_str = base64.b64encode(buffered.getvalue()).decode()
|
621 |
-
|
622 |
-
# Add each image to the gallery HTML
|
623 |
-
gallery_html += f"""
|
624 |
-
<div style='padding: 5px; flex: 1 0 auto;'>
|
625 |
-
<img src='data:image/jpeg;base64,{img_str}' alt='Image' style='max-height: 120px; width: auto;'>
|
626 |
</div>
|
627 |
"""
|
628 |
|
629 |
-
|
630 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
631 |
|
632 |
-
|
633 |
-
|
634 |
|
635 |
def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
|
636 |
azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
|
|
|
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 |
+
# Convert the image to base64 (assuming you have this utility function)
|
571 |
+
img_file = Image.open(image_path).thumbnail((120, 120), Image.Resampling.LANCZOS)
|
572 |
+
base64_image = image_to_base64(img_file)
|
573 |
+
|
574 |
+
# Embed the image with the determined width in the custom div
|
575 |
+
img_html = f"""
|
576 |
+
<div style='display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 400px;'>
|
577 |
+
<img src='data:image/jpeg;base64,{base64_image}' alt='Image' style='max-width: 100%; height: auto;'>
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
</div>
|
579 |
"""
|
580 |
|
581 |
+
# Apply the image with HTML
|
582 |
+
st.markdown(img_html, unsafe_allow_html=True)
|
583 |
+
|
584 |
+
# The CSS to make the images display inline and be responsive
|
585 |
+
css = """
|
586 |
+
<style>
|
587 |
+
@media (max-width: 120px) {
|
588 |
+
.scrollable-image-container img {
|
589 |
+
max-width: 100%;
|
590 |
+
height: 400px;
|
591 |
+
height: auto;
|
592 |
+
}
|
593 |
+
}
|
594 |
+
</style>
|
595 |
+
"""
|
596 |
+
# Apply the CSS
|
597 |
+
st.markdown(css, unsafe_allow_html=True)
|
598 |
+
# def display_image_gallery():
|
599 |
+
# """
|
600 |
+
# Display an image gallery from st.session_state['input_list'] in a scrollable container.
|
601 |
+
# Each image will be downsampled to 120px on the long side.
|
602 |
+
# The container will be as wide as its containing Streamlit column and no more than 400px tall.
|
603 |
+
# """
|
604 |
+
# # Initialize the container
|
605 |
+
# con_image = st.empty()
|
606 |
+
# with con_image.container():
|
607 |
+
# # Start the gallery HTML with a div that will create a vertical scrolling effect
|
608 |
+
# gallery_html = "<div style='display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 400px;'>"
|
609 |
+
|
610 |
+
# # Loop through each image in the input list
|
611 |
+
# for image_path in st.session_state['input_list']:
|
612 |
+
# # Open the image
|
613 |
+
# img = Image.open(image_path)
|
614 |
+
# # Downsample the image to 120px on the long side
|
615 |
+
# img.thumbnail((120, 120), Image.Resampling.LANCZOS)
|
616 |
+
|
617 |
+
# # Convert the image to base64 for HTML embedding
|
618 |
+
# buffered = io.BytesIO()
|
619 |
+
# img.save(buffered, format="JPEG")
|
620 |
+
# img_str = base64.b64encode(buffered.getvalue()).decode()
|
621 |
+
|
622 |
+
# # Add each image to the gallery HTML
|
623 |
+
# gallery_html += f"""
|
624 |
+
# <div style='padding: 5px; flex: 1 0 auto;'>
|
625 |
+
# <img src='data:image/jpeg;base64,{img_str}' alt='Image' style='max-height: 120px; width: auto;'>
|
626 |
+
# </div>
|
627 |
+
# """
|
628 |
+
|
629 |
+
# # Close the gallery container div
|
630 |
+
# gallery_html += "</div>"
|
631 |
|
632 |
+
# # Apply the gallery HTML
|
633 |
+
# st.markdown(gallery_html, unsafe_allow_html=True)
|
634 |
|
635 |
def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
|
636 |
azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
|