phyloforfun commited on
Commit
644099c
1 Parent(s): a3d159a

file upload gallery

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