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

file upload gallery

Browse files
Files changed (1) hide show
  1. app.py +47 -44
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
- # 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
@@ -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) # 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>"
 
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>"