phyloforfun commited on
Commit
08a14c4
1 Parent(s): e6041df

file upload gallery

Browse files
Files changed (2) hide show
  1. app.py +25 -5
  2. vouchervision/prompt_catalog.py +4 -4
app.py CHANGED
@@ -772,6 +772,16 @@ def upload_local_prompt_to_server(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.
@@ -815,18 +825,28 @@ The desired null value is also given. Populate the field with the null value of
815
 
816
  dir_prompt = os.path.join(st.session_state.dir_home, 'custom_prompts')
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
 
772
  else:
773
  st.error("Please upload a .yaml file that you previously created using this Prompt Builder tool.")
774
 
775
+ def create_download_button(file_path, selected_yaml_file):
776
+ file_label = f"Download {selected_yaml_file}"
777
+ with open(file_path, 'rb') as f:
778
+ st.download_button(
779
+ label=file_label,
780
+ data=f,
781
+ file_name=os.path.basename(file_path),
782
+ mime='application/x-yaml'
783
+ )
784
+
785
  def build_LLM_prompt_config():
786
  st.session_state['assigned_columns'] = []
787
  st.session_state['default_instructions'] = """1. Refactor the unstructured OCR text into a dictionary based on the JSON structure outlined below.
 
825
 
826
  dir_prompt = os.path.join(st.session_state.dir_home, 'custom_prompts')
827
  yaml_files = [f for f in os.listdir(dir_prompt) if f.endswith('.yaml')]
828
+ col_upload_yaml, col_upload_btn = st.columns([8,2])
829
+ with col_upload_yaml:
830
  # Upload a prompt from your computer
831
  upload_local_prompt_to_server(dir_prompt)
832
 
833
+
834
+ with col_upload_btn:
 
835
  st.write('##')
836
  # Button to load the selected prompt
837
  st.button('Load Prompt', on_click=btn_load_prompt, args=[selected_yaml_file, dir_prompt])
838
 
839
+ col_select_yaml, col_download_btn = st.columns([8,2])
840
+ with col_select_yaml:
841
+ # Dropdown for selecting a YAML file
842
+ selected_yaml_file = st.selectbox('Select a prompt .YAML file to load:', [''] + yaml_files)
843
+
844
+ with col_download_btn:
845
+ if selected_yaml_file:
846
+ # Construct the full path to the file
847
+ download_file_path = os.path.join(dir_prompt, selected_yaml_file)
848
+ # Create the download button
849
+ create_download_button(download_file_path, selected_yaml_file)
850
 
851
 
852
  # Define the options for the dropdown
vouchervision/prompt_catalog.py CHANGED
@@ -645,7 +645,7 @@ class PromptCatalog:
645
  }
646
 
647
  # Convert the structure to a JSON string without indentation
648
- structure_json_str = json.dumps(dictionary_structure, default_flow_style=False, sort_keys=False)
649
  return structure_json_str
650
 
651
  else:
@@ -665,7 +665,7 @@ class PromptCatalog:
665
  }
666
 
667
  # Convert the structure to a JSON string without indentation
668
- structure_json_str = json.dumps(full_structure, default_flow_style=False, sort_keys=False)
669
  return structure_json_str
670
 
671
  def create_structure(self, is_palm=False):
@@ -674,7 +674,7 @@ class PromptCatalog:
674
  dictionary_structure = {key: "" for key in self.rules_list['Dictionary'].keys()}
675
 
676
  # Convert the structure to a JSON string with indentation for readability
677
- structure_json_str = json.dumps(dictionary_structure, default_flow_style=False, sort_keys=False)
678
  return structure_json_str
679
  else:
680
  # Start with an empty structure for the "Dictionary" section
@@ -690,7 +690,7 @@ class PromptCatalog:
690
  }
691
 
692
  # Convert the structure to a JSON string with indentation for readability
693
- structure_json_str = json.dumps(full_structure, default_flow_style=False, sort_keys=False)
694
  return structure_json_str
695
 
696
  def generate_xlsx_headers(self, is_palm):
 
645
  }
646
 
647
  # Convert the structure to a JSON string without indentation
648
+ structure_json_str = json.dumps(dictionary_structure, sort_keys=False)
649
  return structure_json_str
650
 
651
  else:
 
665
  }
666
 
667
  # Convert the structure to a JSON string without indentation
668
+ structure_json_str = json.dumps(full_structure, sort_keys=False)
669
  return structure_json_str
670
 
671
  def create_structure(self, is_palm=False):
 
674
  dictionary_structure = {key: "" for key in self.rules_list['Dictionary'].keys()}
675
 
676
  # Convert the structure to a JSON string with indentation for readability
677
+ structure_json_str = json.dumps(dictionary_structure, sort_keys=False)
678
  return structure_json_str
679
  else:
680
  # Start with an empty structure for the "Dictionary" section
 
690
  }
691
 
692
  # Convert the structure to a JSON string with indentation for readability
693
+ structure_json_str = json.dumps(full_structure, sort_keys=False)
694
  return structure_json_str
695
 
696
  def generate_xlsx_headers(self, is_palm):