From 24852b5e686e0c3902cf99ba1a6b0c144a98bf5f Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Tue, 31 Oct 2023 14:43:12 +0100 Subject: [PATCH 01/17] Display values of variables used in a prompt - extract jinja variables from a prompt, - new text area with values of variables from a prompt. --- prompterator/main.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/prompterator/main.py b/prompterator/main.py index ab92703..c7f419d 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -12,6 +12,8 @@ import prompterator.models as m import prompterator.utils as u +from jinja2 import meta + # needed to use the simple custom component # from apps.scripts.components_callbacks import register_callback # from components.rate_buttons import rate_buttons @@ -450,13 +452,34 @@ def _get_coloured_patch(patch): def set_up_ui_labelling(): col1, col2 = st.columns([1, 1]) text_orig_length = len(st.session_state.get("text_orig", "")) - col1.text_area( + orig_text_container = col1.container() + orig_text_container.text_area( label=f"Original text ({text_orig_length} chars)", key="text_orig", disabled=True, height=c.DATA_POINT_TEXT_AREA_HEIGHT, ) - labelling_container = col2.container() + + env = u.jinja_env() + parsed_content = env.parse(st.session_state.system_prompt) + vars = meta.find_undeclared_variables(parsed_content) + + if len(vars) > 1: + # create text of used prompt's variables and their values + vars_values = "" + for var in vars: + if var != c.TEXT_ORIG_COL: + vars_values = vars_values + var + ":\n" + " " + st.session_state.row[var] + "\n" + + orig_text_container.text_area( + label=f"Attributes used in a prompt", + key="attributes", + value=vars_values, + disabled=True, + height=c.DATA_POINT_TEXT_AREA_HEIGHT, + ) + + generated_text_area = col2.container() text_generated_length = len(st.session_state.get("text_generated", "")) length_change_percentage = (text_generated_length - text_orig_length) / text_orig_length * 100 length_change_percentage_str = ( @@ -467,7 +490,7 @@ def set_up_ui_labelling(): ) if not st.session_state.get("show_diff", False): - labelling_container.text_area( + generated_text_area.text_area( label=generated_text_label, key="text_generated", value=st.session_state.get("text_generated", ""), @@ -475,10 +498,12 @@ def set_up_ui_labelling(): height=c.DATA_POINT_TEXT_AREA_HEIGHT, ) else: - labelling_container.markdown( + generated_text_area.markdown( create_diff_viewer(generated_text_label), unsafe_allow_html=True ) + empty_col, labeling_col = st.columns([1, 1]) + labelling_container = labeling_col.container() col1, col2, col3, col4, col5, col6, col7 = labelling_container.columns([1, 1, 5, 1, 1, 1, 2]) col1.button( "👍", From 9d958f9394348101d79ddd7458e9469217870e04 Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Tue, 31 Oct 2023 14:50:29 +0100 Subject: [PATCH 02/17] Run `isort` to fix imports order --- prompterator/main.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/prompterator/main.py b/prompterator/main.py index c7f419d..83968f1 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -7,13 +7,12 @@ import streamlit as st import streamlit_toggle as tog from diff_match_patch import diff_match_patch +from jinja2 import meta import prompterator.constants as c import prompterator.models as m import prompterator.utils as u -from jinja2 import meta - # needed to use the simple custom component # from apps.scripts.components_callbacks import register_callback # from components.rate_buttons import rate_buttons From 8282d03d6d8b9760944d4e991fac889137fef7dc Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Fri, 3 Nov 2023 10:20:33 +0100 Subject: [PATCH 03/17] Reorder Labeling area --- prompterator/constants.py | 2 +- prompterator/main.py | 54 ++++++++++++++++++++++++--------------- 2 files changed, 34 insertions(+), 22 deletions(-) diff --git a/prompterator/constants.py b/prompterator/constants.py index 8f4a6dd..fe1a02a 100644 --- a/prompterator/constants.py +++ b/prompterator/constants.py @@ -102,7 +102,7 @@ def call(self, input, **kwargs): TEXT_DIFF_COLOURS = {"add": "#56E7AB", "delete": "#FE8080"} DEFAULT_ROW_NO = 0 -DATA_POINT_TEXT_AREA_HEIGHT = 130 +DATA_POINT_TEXT_AREA_HEIGHT = 180 PROMPT_TEXT_AREA_HEIGHT = 300 DATAFILE_FILTER_ALL = "all" diff --git a/prompterator/main.py b/prompterator/main.py index 83968f1..9034fbd 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -449,10 +449,10 @@ def _get_coloured_patch(patch): def set_up_ui_labelling(): - col1, col2 = st.columns([1, 1]) + col1_orig, col2_orig = st.columns([1, 1]) text_orig_length = len(st.session_state.get("text_orig", "")) - orig_text_container = col1.container() - orig_text_container.text_area( + # orig_text_container = col1_orig.container() + col1_orig.text_area( label=f"Original text ({text_orig_length} chars)", key="text_orig", disabled=True, @@ -470,7 +470,7 @@ def set_up_ui_labelling(): if var != c.TEXT_ORIG_COL: vars_values = vars_values + var + ":\n" + " " + st.session_state.row[var] + "\n" - orig_text_container.text_area( + col2_orig.text_area( label=f"Attributes used in a prompt", key="attributes", value=vars_values, @@ -478,7 +478,15 @@ def set_up_ui_labelling(): height=c.DATA_POINT_TEXT_AREA_HEIGHT, ) - generated_text_area = col2.container() + # labeling_area = st.markdown("""
""", unsafe_allow_html=True) + st.markdown("""""", unsafe_allow_html=True) + # labeling_area = st.container() + col1_label, col2_label = st.columns([1, 1]) + generated_text_area = col1_label.container() text_generated_length = len(st.session_state.get("text_generated", "")) length_change_percentage = (text_generated_length - text_orig_length) / text_orig_length * 100 length_change_percentage_str = ( @@ -501,9 +509,21 @@ def set_up_ui_labelling(): create_diff_viewer(generated_text_label), unsafe_allow_html=True ) - empty_col, labeling_col = st.columns([1, 1]) - labelling_container = labeling_col.container() - col1, col2, col3, col4, col5, col6, col7 = labelling_container.columns([1, 1, 5, 1, 1, 1, 2]) + # empty_col, labeling_col = st.columns([1, 1]) + with generated_text_area: + tog.st_toggle_switch( + label="show diff", + key="show_diff", + default_value=False, + label_after=False, + inactive_color="#D3D3D3", + active_color="#11567f", + track_color="#29B5E8", + ) + + labelling_container = col2_label.container() + labelling_container.markdown('##') + col1, col2, col3 = labelling_container.columns([1, 1, 10]) col1.button( "👍", key="mark_good", @@ -521,21 +541,13 @@ def set_up_ui_labelling(): else 0, text=f"{st.session_state.n_checked}/{len(st.session_state.df)} checked", ) + col4, col5, col6, col_empty = labelling_container.columns([1, 1, 2, 8]) col4.button("⬅️", key="prev_data_point", on_click=show_prev_row) - col5.write(f"#{st.session_state.row_number + 1}: {st.session_state.current_row_label}") - col6.button("➡️", key="next_data_point", on_click=show_next_row) - col7.button("Save ⤵️", key="save_labelled_data", on_click=u.save_labelled_data, type="primary") + col5.button("➡️", key="next_data_point", on_click=show_next_row) + col6.write(f"#{st.session_state.row_number + 1}: {st.session_state.current_row_label}") + labelling_container.button("Save ⤵️", key="save_labelled_data", on_click=u.save_labelled_data, type="primary") + - with labelling_container: - tog.st_toggle_switch( - label="show diff", - key="show_diff", - default_value=False, - label_after=False, - inactive_color="#D3D3D3", - active_color="#11567f", - track_color="#29B5E8", - ) def show_col_selection(): From a3525813eb5b8dd0fc8df9104e95b0309f80ef8b Mon Sep 17 00:00:00 2001 From: samsucik Date: Mon, 6 Nov 2023 10:45:07 +0100 Subject: [PATCH 04/17] upgrade streamlit --- poetry.lock | 68 ++++++++++++++++++++++------------------------------- 1 file changed, 28 insertions(+), 40 deletions(-) diff --git a/poetry.lock b/poetry.lock index 6692863..0ebb3cd 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1175,17 +1175,6 @@ files = [ [package.extras] plugins = ["importlib-metadata"] -[[package]] -name = "pympler" -version = "1.0.1" -description = "A development tool to measure, monitor and analyze the memory behavior of Python objects." -optional = false -python-versions = ">=3.6" -files = [ - {file = "Pympler-1.0.1-py3-none-any.whl", hash = "sha256:d260dda9ae781e1eab6ea15bacb84015849833ba5555f141d2d9b7b7473b307d"}, - {file = "Pympler-1.0.1.tar.gz", hash = "sha256:993f1a3599ca3f4fcd7160c7545ad06310c9e12f70174ae7ae8d4e25f6c5d3fa"}, -] - [[package]] name = "pyrsistent" version = "0.19.3" @@ -1310,43 +1299,42 @@ files = [ [[package]] name = "streamlit" -version = "1.22.0" +version = "1.28.1" description = "A faster way to build and share data apps" optional = false -python-versions = ">=3.7, !=3.9.7" +python-versions = ">=3.8, !=3.9.7" files = [ - {file = "streamlit-1.22.0-py2.py3-none-any.whl", hash = "sha256:520dd9b9e6efb559b5a9a22feadb48b1e6f0340ec83da3514810059fdecd4167"}, - {file = "streamlit-1.22.0.tar.gz", hash = "sha256:5bef9bf8deef32814d9565c9df48331e6357eb0b90dabc3ec4f53c44fb34fc73"}, + {file = "streamlit-1.28.1-py2.py3-none-any.whl", hash = "sha256:f41c4e590299279a910c6a874aabc1428eda074c5f9d944403d2e192fce2ebb0"}, + {file = "streamlit-1.28.1.tar.gz", hash = "sha256:cca04f6d95b14b7bc37f0cabaf27504b86af6b4e1af98d73acc80ecdcfbcc492"}, ] [package.dependencies] -altair = ">=3.2.0,<5" -blinker = ">=1.0.0" -cachetools = ">=4.0" -click = ">=7.0" -gitpython = "!=3.1.19" -importlib-metadata = ">=1.4" -numpy = "*" -packaging = ">=14.1" -pandas = ">=0.25,<3" -pillow = ">=6.2.0" -protobuf = ">=3.12,<4" -pyarrow = ">=4.0" -pydeck = ">=0.1.dev5" -pympler = ">=0.9" -python-dateutil = "*" -requests = ">=2.4" -rich = ">=10.11.0" -tenacity = ">=8.0.0,<9" -toml = "*" -tornado = ">=6.0.3" -typing-extensions = ">=3.10.0.0" -tzlocal = ">=1.1" -validators = ">=0.2" -watchdog = {version = "*", markers = "platform_system != \"Darwin\""} +altair = ">=4.0,<6" +blinker = ">=1.0.0,<2" +cachetools = ">=4.0,<6" +click = ">=7.0,<9" +gitpython = ">=3.0.7,<3.1.19 || >3.1.19,<4" +importlib-metadata = ">=1.4,<7" +numpy = ">=1.19.3,<2" +packaging = ">=16.8,<24" +pandas = ">=1.3.0,<3" +pillow = ">=7.1.0,<11" +protobuf = ">=3.20,<5" +pyarrow = ">=6.0" +pydeck = ">=0.8.0b4,<1" +python-dateutil = ">=2.7.3,<3" +requests = ">=2.27,<3" +rich = ">=10.14.0,<14" +tenacity = ">=8.1.0,<9" +toml = ">=0.10.1,<2" +tornado = ">=6.0.3,<7" +typing-extensions = ">=4.3.0,<5" +tzlocal = ">=1.1,<6" +validators = ">=0.2,<1" +watchdog = {version = ">=2.1.5", markers = "platform_system != \"Darwin\""} [package.extras] -snowflake = ["snowflake-snowpark-python"] +snowflake = ["snowflake-connector-python (>=2.8.0)", "snowflake-snowpark-python (>=0.9.0)"] [[package]] name = "streamlit-toggle-switch" From 9dcb3850ff6d43f1da7c9992a9993c99450f3ab6 Mon Sep 17 00:00:00 2001 From: samsucik Date: Mon, 6 Nov 2023 10:45:57 +0100 Subject: [PATCH 05/17] style the labelling UI more elegantly --- prompterator/main.py | 63 ++++++++++++++++++++++++++++---------------- 1 file changed, 41 insertions(+), 22 deletions(-) diff --git a/prompterator/main.py b/prompterator/main.py index 9034fbd..4c749f4 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -478,14 +478,32 @@ def set_up_ui_labelling(): height=c.DATA_POINT_TEXT_AREA_HEIGHT, ) - # labeling_area = st.markdown("""
""", unsafe_allow_html=True) - st.markdown("""""", unsafe_allow_html=True) - # labeling_area = st.container() - col1_label, col2_label = st.columns([1, 1]) + labeling_area = st.container() + + # create a helper element to help us target the labeling-area container + with labeling_area: + st.markdown("""
""", unsafe_allow_html=True) + + st.markdown( + """ + + """, + unsafe_allow_html=True, + ) + col1_label, col2_label = labeling_area.columns([1, 1]) generated_text_area = col1_label.container() text_generated_length = len(st.session_state.get("text_generated", "")) length_change_percentage = (text_generated_length - text_orig_length) / text_orig_length * 100 @@ -509,20 +527,11 @@ def set_up_ui_labelling(): create_diff_viewer(generated_text_label), unsafe_allow_html=True ) - # empty_col, labeling_col = st.columns([1, 1]) with generated_text_area: - tog.st_toggle_switch( - label="show diff", - key="show_diff", - default_value=False, - label_after=False, - inactive_color="#D3D3D3", - active_color="#11567f", - track_color="#29B5E8", - ) + st.toggle(label="show diff", value=False, key="show_diff") labelling_container = col2_label.container() - labelling_container.markdown('##') + labelling_container.markdown("##") col1, col2, col3 = labelling_container.columns([1, 1, 10]) col1.button( "👍", @@ -545,9 +554,9 @@ def set_up_ui_labelling(): col4.button("⬅️", key="prev_data_point", on_click=show_prev_row) col5.button("➡️", key="next_data_point", on_click=show_next_row) col6.write(f"#{st.session_state.row_number + 1}: {st.session_state.current_row_label}") - labelling_container.button("Save ⤵️", key="save_labelled_data", on_click=u.save_labelled_data, type="primary") - - + labelling_container.button( + "Save ⤵️", key="save_labelled_data", on_click=u.save_labelled_data, type="primary" + ) def show_col_selection(): @@ -610,6 +619,16 @@ def process_uploaded_file(): on_change=process_uploaded_file, ) +# create a helper element to later help us target the main UI area in CSS selectors +st.markdown("""
""", unsafe_allow_html=True) +st.markdown( + """""", + unsafe_allow_html=True, +) u.ensure_datafiles_directory_exists() load_datafiles_into_session() From 4525bf24160779854462bf11358c1e05915a8e73 Mon Sep 17 00:00:00 2001 From: samsucik Date: Mon, 6 Nov 2023 10:47:28 +0100 Subject: [PATCH 06/17] remove a custom toggle component that is no longer needed because streamlit has its native toggle now --- poetry.lock | 16 +--------------- pyproject.toml | 1 - 2 files changed, 1 insertion(+), 16 deletions(-) diff --git a/poetry.lock b/poetry.lock index 0ebb3cd..2127196 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1336,20 +1336,6 @@ watchdog = {version = ">=2.1.5", markers = "platform_system != \"Darwin\""} [package.extras] snowflake = ["snowflake-connector-python (>=2.8.0)", "snowflake-snowpark-python (>=0.9.0)"] -[[package]] -name = "streamlit-toggle-switch" -version = "1.0.2" -description = "Creates a customizable toggle" -optional = false -python-versions = ">=3.6" -files = [ - {file = "streamlit_toggle_switch-1.0.2-py3-none-any.whl", hash = "sha256:0081212d80d178bda337acf2432425e2016d757f57834b18645d4c5b928d4c0f"}, - {file = "streamlit_toggle_switch-1.0.2.tar.gz", hash = "sha256:991b103cd3448b0f6507f8051777b996a17b4630956d5b6fa13344175b20e572"}, -] - -[package.dependencies] -streamlit = ">=0.63" - [[package]] name = "tenacity" version = "8.2.2" @@ -1653,4 +1639,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "44fa7c7a9fb28bb20cdda80d87ce5bc61d0a79f7df82a8746f17ef84683ec1a2" +content-hash = "8b98959594dae0e32e4759fb05a76a656f74ed9f174f8df7808aa298c4d79e8b" diff --git a/pyproject.toml b/pyproject.toml index dbc27fb..e0cde93 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -11,7 +11,6 @@ python = "^3.10" pydantic = "^1.10.7" openai = "^0.27.6" streamlit = "^1.22.0" -streamlit-toggle-switch = "^1.0.2" diff-match-patch = "^20230430" jinja2 = "^3.1.2" From 2c07adafbcffcaf0b0c4e9149af326970d9adb63 Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Mon, 6 Nov 2023 11:56:56 +0100 Subject: [PATCH 07/17] Replace background by border --- prompterator/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompterator/main.py b/prompterator/main.py index 4c749f4..6e5f896 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -495,9 +495,9 @@ def set_up_ui_labelling(): /* use the helper elements of the main UI area and of the labeling area */ /* to create a relatively nice selector */ [data-testid="stVerticalBlock"]:has(div#main-ui-area-marker) [data-testid="stVerticalBlock"]:has(div#labeling-area-marker) { - background: rgba(10, 199, 120, 0.15); padding: 10px; border-radius: 10px; + border: 4px solid rgba(10, 199, 120, 0.68); } """, From a3f455b5af50d379f035423238e1878420410fbf Mon Sep 17 00:00:00 2001 From: samsucik Date: Mon, 6 Nov 2023 17:04:31 +0100 Subject: [PATCH 08/17] update poetry version in pyproject --- poetry.lock | 2 +- pyproject.toml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/poetry.lock b/poetry.lock index 2127196..f13e734 100644 --- a/poetry.lock +++ b/poetry.lock @@ -1639,4 +1639,4 @@ testing = ["big-O", "flake8 (<5)", "jaraco.functools", "jaraco.itertools", "more [metadata] lock-version = "2.0" python-versions = "^3.10" -content-hash = "8b98959594dae0e32e4759fb05a76a656f74ed9f174f8df7808aa298c4d79e8b" +content-hash = "de0c6af8f531cfa1355583ad33452f0892313d1ff3bfce20708c1890f846cfb5" diff --git a/pyproject.toml b/pyproject.toml index e0cde93..eb7e551 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -10,7 +10,7 @@ packages = [{include = "prompterator"}] python = "^3.10" pydantic = "^1.10.7" openai = "^0.27.6" -streamlit = "^1.22.0" +streamlit = "^1.28.0" diff-match-patch = "^20230430" jinja2 = "^3.1.2" From a105cb8045a93ae8c4370c696ca6b41eae4efb34 Mon Sep 17 00:00:00 2001 From: samsucik Date: Mon, 6 Nov 2023 17:09:02 +0100 Subject: [PATCH 09/17] refactor dirty styling hacks --- prompterator/main.py | 27 ++++++--------------------- prompterator/utils.py | 25 +++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 21 deletions(-) diff --git a/prompterator/main.py b/prompterator/main.py index 4c749f4..044f2a1 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -5,7 +5,6 @@ import pandas as pd import streamlit as st -import streamlit_toggle as tog from diff_match_patch import diff_match_patch from jinja2 import meta @@ -451,7 +450,6 @@ def _get_coloured_patch(patch): def set_up_ui_labelling(): col1_orig, col2_orig = st.columns([1, 1]) text_orig_length = len(st.session_state.get("text_orig", "")) - # orig_text_container = col1_orig.container() col1_orig.text_area( label=f"Original text ({text_orig_length} chars)", key="text_orig", @@ -479,19 +477,13 @@ def set_up_ui_labelling(): ) labeling_area = st.container() - - # create a helper element to help us target the labeling-area container - with labeling_area: - st.markdown("""
""", unsafe_allow_html=True) + u.insert_hidden_html_marker( + helper_element_id="labeling-area-marker", target_streamlit_element=labeling_area + ) st.markdown( """ """, - unsafe_allow_html=True, -) +# create a helper element at the top of the main UI section to later help us target the area in +# selectors +u.insert_hidden_html_marker(helper_element_id="main-ui-area-marker") u.ensure_datafiles_directory_exists() load_datafiles_into_session() diff --git a/prompterator/utils.py b/prompterator/utils.py index 58328e1..b8ad861 100644 --- a/prompterator/utils.py +++ b/prompterator/utils.py @@ -286,3 +286,28 @@ def get_dummy_dataframe(): assert set(df.columns) == set(c.DUMMY_DATA_COLS) return df + + +def insert_hidden_html_marker(helper_element_id, target_streamlit_element=None): + """ + Because targeting streamlit elements (e.g. to style them) is hard, we use a trick. + + We create a dummy child elements with a known ID that we can easily target. + """ + if target_streamlit_element: + with target_streamlit_element: + st.markdown(f"""
""", unsafe_allow_html=True) + else: + st.markdown(f"""
""", unsafe_allow_html=True) + + st.markdown( + f""" + + """, + unsafe_allow_html=True, + ) From a019273ff2d0f7e0ced8758c89085312246b68ce Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Mon, 13 Nov 2023 09:39:05 +0100 Subject: [PATCH 10/17] Move creation of the prompt's attributes area to separate function --- prompterator/main.py | 25 ++++++++++++++----------- 1 file changed, 14 insertions(+), 11 deletions(-) diff --git a/prompterator/main.py b/prompterator/main.py index 4200ab7..928cb44 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -447,16 +447,7 @@ def _get_coloured_patch(patch): ) -def set_up_ui_labelling(): - col1_orig, col2_orig = st.columns([1, 1]) - text_orig_length = len(st.session_state.get("text_orig", "")) - col1_orig.text_area( - label=f"Original text ({text_orig_length} chars)", - key="text_orig", - disabled=True, - height=c.DATA_POINT_TEXT_AREA_HEIGHT, - ) - +def set_up_prompt_atrs_area(col): env = u.jinja_env() parsed_content = env.parse(st.session_state.system_prompt) vars = meta.find_undeclared_variables(parsed_content) @@ -468,7 +459,7 @@ def set_up_ui_labelling(): if var != c.TEXT_ORIG_COL: vars_values = vars_values + var + ":\n" + " " + st.session_state.row[var] + "\n" - col2_orig.text_area( + col.text_area( label=f"Attributes used in a prompt", key="attributes", value=vars_values, @@ -476,6 +467,18 @@ def set_up_ui_labelling(): height=c.DATA_POINT_TEXT_AREA_HEIGHT, ) +def set_up_ui_labelling(): + col1_orig, col2_orig = st.columns([1, 1]) + text_orig_length = len(st.session_state.get("text_orig", "")) + # orig_text_container = col1_orig.container() + col1_orig.text_area( + label=f"Original text ({text_orig_length} chars)", + key="text_orig", + disabled=True, + height=c.DATA_POINT_TEXT_AREA_HEIGHT, + ) + set_up_prompt_atrs_area(col2_orig) + labeling_area = st.container() u.insert_hidden_html_marker( helper_element_id="labeling-area-marker", target_streamlit_element=labeling_area From 41630a1dd4bd9f46127d5984a6a6383d75599f80 Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Mon, 13 Nov 2023 10:12:53 +0100 Subject: [PATCH 11/17] Fix black --- prompterator/main.py | 1 + 1 file changed, 1 insertion(+) diff --git a/prompterator/main.py b/prompterator/main.py index 928cb44..51b7650 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -467,6 +467,7 @@ def set_up_prompt_atrs_area(col): height=c.DATA_POINT_TEXT_AREA_HEIGHT, ) + def set_up_ui_labelling(): col1_orig, col2_orig = st.columns([1, 1]) text_orig_length = len(st.session_state.get("text_orig", "")) From 1626425a7e57f3eaf8dc0d6bb5e5574aa050746f Mon Sep 17 00:00:00 2001 From: danielajass <91727831+danielajass@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:54:12 +0100 Subject: [PATCH 12/17] Update prompterator/main.py Co-authored-by: Sam Sucik --- prompterator/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompterator/main.py b/prompterator/main.py index 51b7650..3f9accb 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -447,7 +447,7 @@ def _get_coloured_patch(patch): ) -def set_up_prompt_atrs_area(col): +def set_up_prompt_attrs_area(col): env = u.jinja_env() parsed_content = env.parse(st.session_state.system_prompt) vars = meta.find_undeclared_variables(parsed_content) From e319c0943e7c5fa8b6783b20b7bfe40bf2dfed8e Mon Sep 17 00:00:00 2001 From: danielajass <91727831+danielajass@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:57:35 +0100 Subject: [PATCH 13/17] Update prompterator/main.py Co-authored-by: Sam Sucik --- prompterator/main.py | 1 - 1 file changed, 1 deletion(-) diff --git a/prompterator/main.py b/prompterator/main.py index 3f9accb..2a75b31 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -471,7 +471,6 @@ def set_up_prompt_attrs_area(col): def set_up_ui_labelling(): col1_orig, col2_orig = st.columns([1, 1]) text_orig_length = len(st.session_state.get("text_orig", "")) - # orig_text_container = col1_orig.container() col1_orig.text_area( label=f"Original text ({text_orig_length} chars)", key="text_orig", From 150515c1ec9dcba5e066be11c9863070d97e007d Mon Sep 17 00:00:00 2001 From: danielajass <91727831+danielajass@users.noreply.github.com> Date: Tue, 14 Nov 2023 11:57:42 +0100 Subject: [PATCH 14/17] Update prompterator/main.py Co-authored-by: Sam Sucik --- prompterator/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompterator/main.py b/prompterator/main.py index 2a75b31..056bdd8 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -477,7 +477,7 @@ def set_up_ui_labelling(): disabled=True, height=c.DATA_POINT_TEXT_AREA_HEIGHT, ) - set_up_prompt_atrs_area(col2_orig) + set_up_prompt_attrs_area(col2_orig) labeling_area = st.container() u.insert_hidden_html_marker( From fbd16208d8775a008bb25946aa3807d23459d015 Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Tue, 14 Nov 2023 12:02:21 +0100 Subject: [PATCH 15/17] Rename the function attribute. --- prompterator/main.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/prompterator/main.py b/prompterator/main.py index 056bdd8..e3cd368 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -447,7 +447,7 @@ def _get_coloured_patch(patch): ) -def set_up_prompt_attrs_area(col): +def set_up_prompt_attrs_area(st_container): env = u.jinja_env() parsed_content = env.parse(st.session_state.system_prompt) vars = meta.find_undeclared_variables(parsed_content) @@ -459,7 +459,7 @@ def set_up_prompt_attrs_area(col): if var != c.TEXT_ORIG_COL: vars_values = vars_values + var + ":\n" + " " + st.session_state.row[var] + "\n" - col.text_area( + st_container.text_area( label=f"Attributes used in a prompt", key="attributes", value=vars_values, From 5380d8bef4a29c6adc183c1277dbb50ed771fc76 Mon Sep 17 00:00:00 2001 From: danielajass <91727831+danielajass@users.noreply.github.com> Date: Tue, 14 Nov 2023 12:17:25 +0100 Subject: [PATCH 16/17] Update prompterator/main.py Co-authored-by: Sam Sucik --- prompterator/main.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/prompterator/main.py b/prompterator/main.py index e3cd368..81afd55 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -457,7 +457,7 @@ def set_up_prompt_attrs_area(st_container): vars_values = "" for var in vars: if var != c.TEXT_ORIG_COL: - vars_values = vars_values + var + ":\n" + " " + st.session_state.row[var] + "\n" + vars_values += var + ":\n " + st.session_state.row.get(var, "none") + "\n" st_container.text_area( label=f"Attributes used in a prompt", From a1777a14bdf403ed3e806121c708f4b1008eb006 Mon Sep 17 00:00:00 2001 From: Daniela Ovadova Date: Tue, 14 Nov 2023 13:09:22 +0100 Subject: [PATCH 17/17] Change the way how to handle `text` for attributes area --- prompterator/main.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/prompterator/main.py b/prompterator/main.py index 81afd55..f091814 100644 --- a/prompterator/main.py +++ b/prompterator/main.py @@ -452,12 +452,14 @@ def set_up_prompt_attrs_area(st_container): parsed_content = env.parse(st.session_state.system_prompt) vars = meta.find_undeclared_variables(parsed_content) - if len(vars) > 1: + if c.TEXT_ORIG_COL in vars: + vars.remove(c.TEXT_ORIG_COL) + + if len(vars) > 0: # create text of used prompt's variables and their values vars_values = "" for var in vars: - if var != c.TEXT_ORIG_COL: - vars_values += var + ":\n " + st.session_state.row.get(var, "none") + "\n" + vars_values += var + ":\n " + st.session_state.row.get(var, "none") + "\n" st_container.text_area( label=f"Attributes used in a prompt",