Spaces:
Running
Running
Commit
·
3b75f1a
1
Parent(s):
cc9202c
file upload gallery
Browse files
app.py
CHANGED
|
@@ -688,7 +688,7 @@ def load_prompt_yaml(filename):
|
|
| 688 |
# Placeholder:
|
| 689 |
st.session_state['assigned_columns'] = list(chain.from_iterable(st.session_state['mapping'].values()))
|
| 690 |
|
| 691 |
-
def save_prompt_yaml(filename):
|
| 692 |
yaml_content = {
|
| 693 |
'instructions': st.session_state['instructions'],
|
| 694 |
'json_formatting_instructions': st.session_state['json_formatting_instructions'],
|
|
@@ -705,6 +705,9 @@ def save_prompt_yaml(filename):
|
|
| 705 |
|
| 706 |
st.success(f"Prompt saved as '{filename}.yaml'.")
|
| 707 |
|
|
|
|
|
|
|
|
|
|
| 708 |
def check_unique_mapping_assignments():
|
| 709 |
if len(st.session_state['assigned_columns']) != len(set(st.session_state['assigned_columns'])):
|
| 710 |
st.error("Each column name must be assigned to only one category.")
|
|
@@ -829,33 +832,34 @@ The desired null value is also given. Populate the field with the null value of
|
|
| 829 |
|
| 830 |
dir_prompt = os.path.join(st.session_state.dir_home, 'custom_prompts')
|
| 831 |
yaml_files = [f for f in os.listdir(dir_prompt) if f.endswith('.yaml')]
|
| 832 |
-
col_upload_yaml,
|
| 833 |
with col_upload_yaml:
|
| 834 |
# Upload a prompt from your computer
|
| 835 |
upload_local_prompt_to_server(dir_prompt)
|
| 836 |
|
| 837 |
-
|
| 838 |
-
st.write('##')
|
| 839 |
-
# Button to load the selected prompt
|
| 840 |
-
st.button('Load Prompt into Builder', on_click=btn_load_prompt, args=[st.session_state['selected_yaml_file'] , dir_prompt])
|
| 841 |
-
|
| 842 |
-
col_select_yaml, col_download_btn = st.columns([8,2])
|
| 843 |
with col_select_yaml:
|
| 844 |
# Dropdown for selecting a YAML file
|
| 845 |
st.session_state['selected_yaml_file'] = st.selectbox('Select a prompt .YAML file to load:', [''] + yaml_files)
|
| 846 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 847 |
with col_download_btn:
|
| 848 |
if st.session_state['selected_yaml_file']:
|
| 849 |
# Construct the full path to the file
|
| 850 |
download_file_path = os.path.join(dir_prompt, st.session_state['selected_yaml_file'] )
|
| 851 |
# Create the download button
|
|
|
|
| 852 |
create_download_button(download_file_path, st.session_state['selected_yaml_file'] )
|
| 853 |
|
| 854 |
|
| 855 |
# Define the options for the dropdown
|
| 856 |
llm_options = ['gpt', 'palm']
|
| 857 |
# Create the dropdown and set the value to session_state['LLM']
|
| 858 |
-
st.session_state['LLM'] = st.selectbox('Set LLM:', llm_options, index=llm_options.index(st.session_state.get('LLM', 'gpt')))
|
| 859 |
|
| 860 |
|
| 861 |
|
|
@@ -1048,7 +1052,11 @@ The desired null value is also given. Populate the field with the null value of
|
|
| 1048 |
st.json(st.session_state['mapping'])
|
| 1049 |
|
| 1050 |
|
| 1051 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1052 |
with col_left_save:
|
| 1053 |
# Input for new file name
|
| 1054 |
new_filename = st.text_input("Enter filename to save your prompt as a configuration YAML:",placeholder='my_prompt_name')
|
|
@@ -1057,7 +1065,7 @@ The desired null value is also given. Populate the field with the null value of
|
|
| 1057 |
if new_filename:
|
| 1058 |
if check_unique_mapping_assignments():
|
| 1059 |
if check_prompt_yaml_filename(new_filename):
|
| 1060 |
-
save_prompt_yaml(new_filename)
|
| 1061 |
else:
|
| 1062 |
st.error("File name can only contain letters, numbers, underscores, and dashes. Cannot contain spaces.")
|
| 1063 |
else:
|
|
@@ -1065,10 +1073,13 @@ The desired null value is also given. Populate the field with the null value of
|
|
| 1065 |
else:
|
| 1066 |
st.error("Please enter a filename.")
|
| 1067 |
|
| 1068 |
-
|
| 1069 |
-
|
| 1070 |
-
|
| 1071 |
-
|
|
|
|
|
|
|
|
|
|
| 1072 |
with col_prompt_main_right:
|
| 1073 |
st.subheader('All Prompt Components')
|
| 1074 |
st.session_state['prompt_info'] = {
|
|
@@ -1518,6 +1529,7 @@ def main():
|
|
| 1518 |
if st.button("Build Custom LLM Prompt"):
|
| 1519 |
st.session_state.proceed_to_build_llm_prompt = True
|
| 1520 |
st.rerun()
|
|
|
|
| 1521 |
|
| 1522 |
with tab_component:
|
| 1523 |
content_tab_component()
|
|
|
|
| 688 |
# Placeholder:
|
| 689 |
st.session_state['assigned_columns'] = list(chain.from_iterable(st.session_state['mapping'].values()))
|
| 690 |
|
| 691 |
+
def save_prompt_yaml(filename, col_right_save):
|
| 692 |
yaml_content = {
|
| 693 |
'instructions': st.session_state['instructions'],
|
| 694 |
'json_formatting_instructions': st.session_state['json_formatting_instructions'],
|
|
|
|
| 705 |
|
| 706 |
st.success(f"Prompt saved as '{filename}.yaml'.")
|
| 707 |
|
| 708 |
+
with col_right_save:
|
| 709 |
+
create_download_button(filepath, filename)
|
| 710 |
+
|
| 711 |
def check_unique_mapping_assignments():
|
| 712 |
if len(st.session_state['assigned_columns']) != len(set(st.session_state['assigned_columns'])):
|
| 713 |
st.error("Each column name must be assigned to only one category.")
|
|
|
|
| 832 |
|
| 833 |
dir_prompt = os.path.join(st.session_state.dir_home, 'custom_prompts')
|
| 834 |
yaml_files = [f for f in os.listdir(dir_prompt) if f.endswith('.yaml')]
|
| 835 |
+
col_upload_yaml, col_upload_yaml_2 = st.columns([4,4])
|
| 836 |
with col_upload_yaml:
|
| 837 |
# Upload a prompt from your computer
|
| 838 |
upload_local_prompt_to_server(dir_prompt)
|
| 839 |
|
| 840 |
+
col_select_yaml, col_upload_btn, col_download_btn = st.columns([6,2,2])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 841 |
with col_select_yaml:
|
| 842 |
# Dropdown for selecting a YAML file
|
| 843 |
st.session_state['selected_yaml_file'] = st.selectbox('Select a prompt .YAML file to load:', [''] + yaml_files)
|
| 844 |
|
| 845 |
+
with col_upload_btn:
|
| 846 |
+
st.write('##')
|
| 847 |
+
# Button to load the selected prompt
|
| 848 |
+
st.button('Load Selected Prompt into Builder', on_click=btn_load_prompt, args=[st.session_state['selected_yaml_file'] , dir_prompt])
|
| 849 |
+
|
| 850 |
with col_download_btn:
|
| 851 |
if st.session_state['selected_yaml_file']:
|
| 852 |
# Construct the full path to the file
|
| 853 |
download_file_path = os.path.join(dir_prompt, st.session_state['selected_yaml_file'] )
|
| 854 |
# Create the download button
|
| 855 |
+
st.write('##')
|
| 856 |
create_download_button(download_file_path, st.session_state['selected_yaml_file'] )
|
| 857 |
|
| 858 |
|
| 859 |
# Define the options for the dropdown
|
| 860 |
llm_options = ['gpt', 'palm']
|
| 861 |
# Create the dropdown and set the value to session_state['LLM']
|
| 862 |
+
st.session_state['LLM'] = st.selectbox('Set LLM type:', llm_options, index=llm_options.index(st.session_state.get('LLM', 'gpt')))
|
| 863 |
|
| 864 |
|
| 865 |
|
|
|
|
| 1052 |
st.json(st.session_state['mapping'])
|
| 1053 |
|
| 1054 |
|
| 1055 |
+
st.write('---')
|
| 1056 |
+
st.header("Save and Download Custom Prompt")
|
| 1057 |
+
st.write('Provide a name for your custom prompt. It can only conatin letters, numbers, and underscores.')
|
| 1058 |
+
st.write('Once you click save, validation checks will verify the formatting and then a download button will appear so that you can ***save a local copy of your custom prompt.***')
|
| 1059 |
+
col_left_save, col_right_save, _ = st.columns([2,2,8])
|
| 1060 |
with col_left_save:
|
| 1061 |
# Input for new file name
|
| 1062 |
new_filename = st.text_input("Enter filename to save your prompt as a configuration YAML:",placeholder='my_prompt_name')
|
|
|
|
| 1065 |
if new_filename:
|
| 1066 |
if check_unique_mapping_assignments():
|
| 1067 |
if check_prompt_yaml_filename(new_filename):
|
| 1068 |
+
save_prompt_yaml(new_filename, col_right_save)
|
| 1069 |
else:
|
| 1070 |
st.error("File name can only contain letters, numbers, underscores, and dashes. Cannot contain spaces.")
|
| 1071 |
else:
|
|
|
|
| 1073 |
else:
|
| 1074 |
st.error("Please enter a filename.")
|
| 1075 |
|
| 1076 |
+
st.write('---')
|
| 1077 |
+
st.header("Return to VoucherVision")
|
| 1078 |
+
if st.button('Exit'):
|
| 1079 |
+
st.session_state.proceed_to_build_llm_prompt = False
|
| 1080 |
+
st.session_state.proceed_to_main = True
|
| 1081 |
+
st.rerun()
|
| 1082 |
+
|
| 1083 |
with col_prompt_main_right:
|
| 1084 |
st.subheader('All Prompt Components')
|
| 1085 |
st.session_state['prompt_info'] = {
|
|
|
|
| 1529 |
if st.button("Build Custom LLM Prompt"):
|
| 1530 |
st.session_state.proceed_to_build_llm_prompt = True
|
| 1531 |
st.rerun()
|
| 1532 |
+
st.write('When opening the Prompt Builder, it take a moment for the page to refresh.')
|
| 1533 |
|
| 1534 |
with tab_component:
|
| 1535 |
content_tab_component()
|