phyloforfun commited on
Commit
70865fd
1 Parent(s): 026faf8

file upload gallery

Browse files
Files changed (1) hide show
  1. app.py +55 -54
app.py CHANGED
@@ -557,46 +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
- 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
@@ -608,21 +608,22 @@ def display_image_gallery():
608
  """
609
 
610
  # Loop through each image in the input list
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
 
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
 
608
  """
609
 
610
  # Loop through each image in the input list
611
+ with con_image.container():
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
+ img_html = f"""
622
+ <div style='display: flex; flex-wrap: wrap; overflow-y: auto; max-height: 400px;'>
623
+ <img src='data:image/jpeg;base64,{base64_image}' alt='Image' style='max-width: 100%; height: auto;'>
624
+ </div>
625
+ """
626
+ st.markdown(img_html, unsafe_allow_html=True)
627
 
628
 
629
  # Close the div for the image grid