ccm commited on
Commit
a01f519
1 Parent(s): ae3b34d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py CHANGED
@@ -106,7 +106,50 @@ label_to_ethnicity = {
106
  ethnicity_to_label = {v: k for k, v in label_to_ethnicity.items()}
107
  gender_to_label = {v: k for k, v in label_to_gender.items()}
108
 
 
 
 
 
 
 
 
109
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
110
 
111
 
112
  # Define a function for addition
@@ -217,5 +260,6 @@ if time_to_analyze or 'already_analyzed' in streamlit.session_state:
217
  streamlit.session_state['already_analyzed'] = True
218
  placeholder.empty()
219
  with streamlit.spinner("Analyzing..."):
 
220
  streamlit.markdown("These tabs summarize your results with a variety of visualizations and statistics.")
221
  make_results()
 
106
  ethnicity_to_label = {v: k for k, v in label_to_ethnicity.items()}
107
  gender_to_label = {v: k for k, v in label_to_gender.items()}
108
 
109
+ def make_table():
110
+ if 'table_data' in streamlit.session_state:
111
+ df = streamlit.session_state['table_data']
112
+ else:
113
+ refs = References(streamlit.session_state.bib)
114
+ refs.infer_gender()
115
+ refs.infer_ethnicity()
116
 
117
+ df = refs.raw_results
118
+ df = df.replace({"Most Likely Ethnicity": label_to_ethnicity})
119
+ df = df.replace({"Most Likely Gender": label_to_gender})
120
+ df = df.sort_values(["Last Name", "First Name"])
121
+ df = df.reset_index(drop=True)
122
+
123
+ gb = st_aggrid.GridOptionsBuilder.from_dataframe(df)
124
+ gb.configure_default_column(editable=True)
125
+
126
+ gb.configure_column('Most Likely Ethnicity',
127
+ cellEditor='agRichSelectCellEditor',
128
+ cellEditorParams={'values': list(label_to_ethnicity.values())},
129
+ cellEditorPopup=True
130
+ )
131
+
132
+ gb.configure_column('Most Likely Gender',
133
+ cellEditor='agRichSelectCellEditor',
134
+ cellEditorParams={'values': list(label_to_gender.values())},
135
+ cellEditorPopup=True
136
+ )
137
+
138
+ gb.configure_column('Title',
139
+ editable=False
140
+ )
141
+
142
+ response = st_aggrid.AgGrid(
143
+ data=df,
144
+ gridOptions=gb.build(),
145
+ fit_columns_on_grid_load=True,
146
+ update_mode=st_aggrid.GridUpdateMode.VALUE_CHANGED,
147
+ height=400,
148
+ )
149
+
150
+ streamlit.session_state['table_data'] = response.data
151
+ if response.column_state:
152
+ streamlit.experimental_rerun()
153
 
154
 
155
  # Define a function for addition
 
260
  streamlit.session_state['already_analyzed'] = True
261
  placeholder.empty()
262
  with streamlit.spinner("Analyzing..."):
263
+ make_table()
264
  streamlit.markdown("These tabs summarize your results with a variety of visualizations and statistics.")
265
  make_results()