PRENT/PRENT-Codebook
0
1import os2import sys3 4import streamlit as st5from st_aggrid import AgGrid, DataReturnMode6 7current = os.path.dirname(os.path.realpath(__file__))8parent = os.path.dirname(current)9sys.path.append(parent)10from helpers import apply_style, get_idx_column, read_csv_from_web, read_json_from_web11 12apply_style()13 14codebook = {}15 16st.markdown(17 """18 # Codebook Creation/Edition Tool based on the PR-ENT Approach.19 ### *Rethinking the Event Coding Pipeline with Prompt Entailment*20 ### Author: Anonymized for submission21 ##### Version: 1.022"""23)24st.markdown("***********")25 26st.markdown(27 """28## Data Loading29"""30)31 32 33st.markdown(34 """35 ### Upload a CSV of event descriptions.36"""37)38uploaded_file = st.file_uploader("Upload a csv file containing event descriptions")39if uploaded_file is not None:40 st.session_state.data = read_csv_from_web(uploaded_file)41 42 43if "data" in st.session_state:44 # Filter will be reset if the page is left and then used again45 loading_df = st.text("Loading data display...")46 st.write(47 """48 The below display of the data can be used to filter the data. Click on the *3 bars logo* when hovering over a column name and the filtering49 tool will appear. Filters are kept in memory on the whole dashboard as long as the `Reset Filters` button is not clicked.50 51 Current limitation: If a filter is set and the user change page. Then it can not be modified anymore and needs to be reset.52 """53 )54 if "filtered_df" not in st.session_state:55 st.session_state.filtered_df = st.session_state.data56 if st.button("Reset Filters"):57 st.session_state.filtered_df = st.session_state.data58 59 st.session_state.filtered_df = AgGrid(60 st.session_state.filtered_df,61 height=400,62 data_return_mode=DataReturnMode.FILTERED,63 update_mode="MANUAL",64 )["data"]65 66 if "text_column_design_perm" not in st.session_state:67 st.session_state[68 "text_column_design_perm"69 ] = st.session_state.filtered_df.columns[0]70 71 def callback_function(mod, key):72 st.session_state[mod] = st.session_state[key]73 74 st.write("Select the column which contains the event descriptions.")75 st.selectbox(76 "Select the event description column:",77 st.session_state.filtered_df.columns,78 key="text_column_design",79 on_change=callback_function,80 args=("text_column_design_perm", "text_column_design"),81 index=get_idx_column(82 st.session_state["text_column_design_perm"],83 list(st.session_state.filtered_df.columns),84 ),85 )86 loading_df.text("")87 88 # Remove NaN Texts89 if st.button("Remove Empty Event Descriptions"):90 st.session_state.filtered_df = st.session_state.filtered_df.dropna(91 subset=[st.session_state["text_column_design_perm"]]92 )93 94 95st.write("********")96st.markdown("## Optional Upload")97 98 99st.markdown(100 """101 ### Upload a codebook if available. It needs to be in the format used in this dashboard.102"""103)104uploaded_codebook = st.file_uploader("Upload a codebook if available (OPTIONAL)")105if uploaded_codebook is not None:106 codebook = read_json_from_web(uploaded_codebook)107 st.session_state.codebook = codebook108 109st.markdown(110 """111 ### Upload a validated dataset (accept, reject, ignored) in the format of this dashboard.112"""113)114 115uploaded_validated_data = st.file_uploader(116 "Upload a json file containing validated data (OPTIONAL)"117)118if uploaded_validated_data is not None:119 st.session_state.validated_data = read_json_from_web(uploaded_validated_data)120 