phyloforfun commited on
Commit
5ee1861
1 Parent(s): 6a78dda

file upload gallery

Browse files
Files changed (1) hide show
  1. app.py +25 -5
app.py CHANGED
@@ -24,6 +24,8 @@ COLORS_EXPENSE_REPORT = {
24
  'GPT_3_5': '#006400', # Dark Green
25
  'PALM2': '#66a8ff' # blue
26
  }
 
 
27
 
28
  class ProgressReport:
29
  def __init__(self, overall_bar, batch_bar, text_overall, text_batch):
@@ -755,6 +757,21 @@ def btn_load_prompt(selected_yaml_file, dir_prompt):
755
  'LLM': st.session_state['LLM']
756
  }
757
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
758
  def build_LLM_prompt_config():
759
  st.session_state['assigned_columns'] = []
760
  st.session_state['default_instructions'] = """1. Refactor the unstructured OCR text into a dictionary based on the JSON structure outlined below.
@@ -800,13 +817,16 @@ The desired null value is also given. Populate the field with the null value of
800
  yaml_files = [f for f in os.listdir(dir_prompt) if f.endswith('.yaml')]
801
  col_load_text, col_load_btn = st.columns([8,2])
802
  with col_load_text:
803
- # Dropdown for selecting a YAML file
 
 
 
804
  selected_yaml_file = st.selectbox('Select a prompt YAML file to load:', [''] + yaml_files)
805
  with col_load_btn:
806
  st.write('##')
807
  # Button to load the selected prompt
808
  st.button('Load Prompt', on_click=btn_load_prompt, args=[selected_yaml_file, dir_prompt])
809
-
810
 
811
 
812
  # Define the options for the dropdown
@@ -1211,7 +1231,7 @@ def content_tab_settings():
1211
  st.session_state['input_list'].append(file_path)
1212
 
1213
  img = Image.open(file_path)
1214
- img.thumbnail((64, 64), Image.Resampling.LANCZOS)
1215
  file_path_small = save_uploaded_file(st.session_state['dir_uploaded_images_small'], uploaded_file, img)
1216
  st.session_state['input_list_small'].append(file_path_small)
1217
  print(uploaded_file.name)
@@ -1219,9 +1239,9 @@ def content_tab_settings():
1219
  with col_local_2:
1220
  if st.session_state['input_list_small']:
1221
  st.subheader('Image Gallery')
1222
- if len(st.session_state['input_list_small']) > 100:
1223
  # Only take the first 100 images from the list
1224
- images_to_display = st.session_state['input_list_small'][:100]
1225
  else:
1226
  # If there are less than 100 images, take them all
1227
  images_to_display = st.session_state['input_list_small']
 
24
  'GPT_3_5': '#006400', # Dark Green
25
  'PALM2': '#66a8ff' # blue
26
  }
27
+ MAX_GALLERY_IMAGES = 50
28
+ GALLERY_IMAGE_SIZE = 128
29
 
30
  class ProgressReport:
31
  def __init__(self, overall_bar, batch_bar, text_overall, text_batch):
 
757
  'LLM': st.session_state['LLM']
758
  }
759
 
760
+ def upload_local_prompt_to_server(dir_prompt):
761
+ uploaded_file = st.file_uploader("Upload a custom prompt file", type=['yaml'])
762
+ if uploaded_file is not None:
763
+ # Check the file extension
764
+ file_name = uploaded_file.name
765
+ if file_name.endswith('.yaml'):
766
+ file_path = os.path.join(dir_prompt, file_name)
767
+
768
+ # Save the file
769
+ with open(file_path, 'wb') as f:
770
+ f.write(uploaded_file.getbuffer())
771
+ st.success(f"Saved file {file_name} in {dir_prompt}")
772
+ else:
773
+ st.error("Please upload a .yaml file that you previously created using this Prompt Builder tool.")
774
+
775
  def build_LLM_prompt_config():
776
  st.session_state['assigned_columns'] = []
777
  st.session_state['default_instructions'] = """1. Refactor the unstructured OCR text into a dictionary based on the JSON structure outlined below.
 
817
  yaml_files = [f for f in os.listdir(dir_prompt) if f.endswith('.yaml')]
818
  col_load_text, col_load_btn = st.columns([8,2])
819
  with col_load_text:
820
+ # Upload a prompt from your computer
821
+ upload_local_prompt_to_server(dir_prompt)
822
+
823
+ # Dropdown for selecting a YAML file
824
  selected_yaml_file = st.selectbox('Select a prompt YAML file to load:', [''] + yaml_files)
825
  with col_load_btn:
826
  st.write('##')
827
  # Button to load the selected prompt
828
  st.button('Load Prompt', on_click=btn_load_prompt, args=[selected_yaml_file, dir_prompt])
829
+
830
 
831
 
832
  # Define the options for the dropdown
 
1231
  st.session_state['input_list'].append(file_path)
1232
 
1233
  img = Image.open(file_path)
1234
+ img.thumbnail((GALLERY_IMAGE_SIZE, GALLERY_IMAGE_SIZE), Image.Resampling.LANCZOS)
1235
  file_path_small = save_uploaded_file(st.session_state['dir_uploaded_images_small'], uploaded_file, img)
1236
  st.session_state['input_list_small'].append(file_path_small)
1237
  print(uploaded_file.name)
 
1239
  with col_local_2:
1240
  if st.session_state['input_list_small']:
1241
  st.subheader('Image Gallery')
1242
+ if len(st.session_state['input_list_small']) > MAX_GALLERY_IMAGES:
1243
  # Only take the first 100 images from the list
1244
+ images_to_display = st.session_state['input_list_small'][:MAX_GALLERY_IMAGES]
1245
  else:
1246
  # If there are less than 100 images, take them all
1247
  images_to_display = st.session_state['input_list_small']