Spaces:
Running
Running
phyloforfun
commited on
Commit
·
5717b13
1
Parent(s):
dcf04c1
file upload gallery
Browse files
app.py
CHANGED
@@ -1,5 +1,5 @@
|
|
1 |
import streamlit as st
|
2 |
-
import yaml, os, json, random, time, re, shutil
|
3 |
import matplotlib.pyplot as plt
|
4 |
import plotly.graph_objs as go
|
5 |
import numpy as np
|
@@ -557,44 +557,79 @@ 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
|
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 |
-
#
|
571 |
-
|
572 |
-
|
573 |
-
|
574 |
-
|
575 |
-
|
576 |
-
|
577 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
578 |
</div>
|
579 |
"""
|
580 |
|
581 |
-
|
582 |
-
|
583 |
|
584 |
-
#
|
585 |
-
|
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 |
|
599 |
def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
|
600 |
azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
|
|
|
1 |
import streamlit as st
|
2 |
+
import yaml, os, json, random, time, re, shutil, io
|
3 |
import matplotlib.pyplot as plt
|
4 |
import plotly.graph_objs as go
|
5 |
import numpy as np
|
|
|
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 be downsampled to 120px on the long side.
|
602 |
"""
|
603 |
# Initialize the container
|
604 |
con_image = st.empty()
|
605 |
with con_image.container():
|
606 |
+
# Start the gallery HTML with a div that will create a horizontal scrolling effect
|
607 |
+
gallery_html = "<div style='display: flex; flex-wrap: nowrap; overflow-x: auto;'>"
|
608 |
+
|
609 |
# Loop through each image in the input list
|
610 |
for image_path in st.session_state['input_list']:
|
611 |
+
# Open the image
|
612 |
+
img = Image.open(image_path)
|
613 |
+
# Downsample the image to 120px on the long side
|
614 |
+
img.thumbnail((120, 120))
|
615 |
+
|
616 |
+
# Convert the image to base64 for HTML embedding
|
617 |
+
buffered = io.BytesIO()
|
618 |
+
img.save(buffered, format="JPEG")
|
619 |
+
img_str = base64.b64encode(buffered.getvalue()).decode()
|
620 |
+
|
621 |
+
# Add each image to the gallery HTML
|
622 |
+
gallery_html += f"""
|
623 |
+
<div style='padding: 5px;'>
|
624 |
+
<img src='data:image/jpeg;base64,{img_str}' alt='Image' style='height: 120px; margin-right: 10px;'>
|
625 |
</div>
|
626 |
"""
|
627 |
|
628 |
+
# Close the gallery container div
|
629 |
+
gallery_html += "</div>"
|
630 |
|
631 |
+
# Apply the gallery HTML
|
632 |
+
st.markdown(gallery_html, unsafe_allow_html=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
633 |
|
634 |
def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
|
635 |
azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
|