phyloforfun commited on
Commit
0bec306
1 Parent(s): 550800a

file upload gallery

Browse files
Files changed (1) hide show
  1. app.py +41 -3
app.py CHANGED
@@ -6,6 +6,7 @@ import numpy as np
6
  from itertools import chain
7
  from PIL import Image
8
  from io import BytesIO
 
9
  import pandas as pd
10
  from typing import Union
11
  from google.oauth2 import service_account
@@ -550,7 +551,43 @@ def delete_directory(dir_path):
550
  # except Exception as e:
551
  # with message_loc:
552
  # st.error(f"Google PaLM 2 API Key Failed:exclamation: {e}")
553
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
554
 
555
  def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
556
  azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
@@ -1106,8 +1143,9 @@ def content_tab_settings():
1106
  if st.session_state['input_list']:
1107
  st.subheader('Image Gallery')
1108
  # selected_img = image_select("Uploaded Images Ready for Transcription", st.session_state['input_list'], use_container_width=False)
1109
- st.image(st.session_state['input_list'])
1110
- st.button("Clear Staged Images",on_click=delete_directory, args=[st.session_state['dir_uploaded_images']])
 
1111
 
1112
  with col_cropped_1:
1113
  default_crops = st.session_state.config['leafmachine']['cropped_components'].get('save_cropped_annotations', ['leaf_whole'])
 
6
  from itertools import chain
7
  from PIL import Image
8
  from io import BytesIO
9
+ import base64
10
  import pandas as pd
11
  from typing import Union
12
  from google.oauth2 import service_account
 
551
  # except Exception as e:
552
  # with message_loc:
553
  # st.error(f"Google PaLM 2 API Key Failed:exclamation: {e}")
554
+ def display_image_gallery():
555
+ """
556
+ Display an image gallery from st.session_state['input_list'] in a scrollable container.
557
+ Each image will have a maximum width of 500 pixels.
558
+ """
559
+ # Initialize the container
560
+ con_image = st.empty()
561
+ with con_image.container():
562
+ # Loop through each image in the input list
563
+ for image_path in st.session_state['input_list']:
564
+ # Convert the image to base64 (assuming you have this utility function)
565
+ base64_image = image_to_base64(image_path)
566
+
567
+ # Embed the image with the determined width in the custom div
568
+ img_html = f"""
569
+ <div style='display: inline-block; padding: 10px; max-width: 50px;'>
570
+ <img src='data:image/jpeg;base64,{base64_image}' alt='Image' style='max-width: 100%; height: auto;'>
571
+ </div>
572
+ """
573
+
574
+ # Apply the image with HTML
575
+ st.markdown(img_html, unsafe_allow_html=True)
576
+
577
+ # The CSS to make the images display inline and be responsive
578
+ css = """
579
+ <style>
580
+ @media (max-width: 50px) {
581
+ .scrollable-image-container img {
582
+ max-width: 100%;
583
+ height: 300px;
584
+ height: auto;
585
+ }
586
+ }
587
+ </style>
588
+ """
589
+ # Apply the CSS
590
+ st.markdown(css, unsafe_allow_html=True)
591
 
592
  def save_changes_to_API_keys(cfg_private,openai_api_key,azure_openai_api_version,azure_openai_api_key,
593
  azure_openai_api_base,azure_openai_organization,azure_openai_api_type,google_vision,google_palm):
 
1143
  if st.session_state['input_list']:
1144
  st.subheader('Image Gallery')
1145
  # selected_img = image_select("Uploaded Images Ready for Transcription", st.session_state['input_list'], use_container_width=False)
1146
+ # st.image(st.session_state['input_list'])
1147
+ display_image_gallery()
1148
+ # st.button("Clear Staged Images",on_click=delete_directory, args=[st.session_state['dir_uploaded_images']])
1149
 
1150
  with col_cropped_1:
1151
  default_crops = st.session_state.config['leafmachine']['cropped_components'].get('save_cropped_annotations', ['leaf_whole'])