Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -60,20 +60,24 @@ def search_data(query, search_criteria, search_filter):
|
|
| 60 |
elif search_criteria == 'GSS Tags':
|
| 61 |
return d4
|
| 62 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 63 |
# Main function to run the Streamlit app
|
| 64 |
def main():
|
| 65 |
-
|
| 66 |
-
st.
|
| 67 |
-
st.title("AI-Augmented Surveys: Retrodiction Browser")
|
| 68 |
st.markdown("Junsol Kim, Byungkyu Lee<br />Paper: https://arxiv.org/abs/2305.09620", unsafe_allow_html=True)
|
| 69 |
n_var_per_page = 25
|
| 70 |
-
|
| 71 |
current_variable = None
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
if '
|
| 74 |
-
st.session_state['search_mode'] = True
|
| 75 |
-
|
| 76 |
-
if st.session_state['search_mode']:
|
| 77 |
col1, col2, col3 = st.columns([3, 1, 1])
|
| 78 |
with col1:
|
| 79 |
search_query = st.text_input('Search available GSS variables')
|
|
@@ -101,26 +105,24 @@ def main():
|
|
| 101 |
st.markdown(f'Page {page} of {maxpage}')
|
| 102 |
button_list = []
|
| 103 |
for n_row, row in results.loc[(page-1)*n_var_per_page:page*n_var_per_page-1].reset_index().iterrows():
|
| 104 |
-
i = n_row %
|
| 105 |
if i == 0:
|
| 106 |
st.write("---")
|
| 107 |
-
cols = st.columns(
|
| 108 |
# draw the card
|
| 109 |
-
with cols[n_row %
|
| 110 |
st.markdown(f"**{row['var_name'].strip()}**", unsafe_allow_html=True)
|
| 111 |
st.markdown(f"*{row['var_description'].strip()}*", unsafe_allow_html=True)
|
| 112 |
st.markdown(f"Survey question: {row['question']}", unsafe_allow_html=True)
|
| 113 |
st.markdown(f"GSS tags: {row['subject']}", unsafe_allow_html=True)
|
| 114 |
-
button_list.append(st.button('View this variable', key=
|
| 115 |
for i in range(len(button_list)):
|
| 116 |
if button_list[i]:
|
| 117 |
current_variable = str(results.loc[i, 'var_name'])
|
| 118 |
st.session_state['search_mode'] = False
|
| 119 |
else:
|
| 120 |
-
goback = st.button('Go back')
|
| 121 |
-
|
| 122 |
-
st.session_state['search_mode'] = True
|
| 123 |
-
var = current_variable
|
| 124 |
tab_pred = dt_summary1.loc[(dt_summary1.variable == var) & (dt_summary1.pred_type == 'rescale')]
|
| 125 |
tab_obs = dt_summary1.loc[(dt_summary1.variable == var) & (dt_summary1.pred_type == 'obsbin')]
|
| 126 |
tab_obs = tab_obs.merge(tab_pred[['year']], how='right').rename({'mean': 'obs_mean', 'lci': 'obs_lci', 'uci': 'obs_uci'}, axis=1)
|
|
|
|
| 60 |
elif search_criteria == 'GSS Tags':
|
| 61 |
return d4
|
| 62 |
|
| 63 |
+
def show_data(var):
|
| 64 |
+
st.session_state['current_var'] = var
|
| 65 |
+
|
| 66 |
+
def show_search():
|
| 67 |
+
st.session_state['current_var'] = None
|
| 68 |
+
|
| 69 |
# Main function to run the Streamlit app
|
| 70 |
def main():
|
| 71 |
+
st.set_page_config(page_title="AI-Augmented Surveys: Browse Retrodictions", layout="wide")
|
| 72 |
+
st.title("AI-Augmented Surveys: Browse Retrodictions")
|
|
|
|
| 73 |
st.markdown("Junsol Kim, Byungkyu Lee<br />Paper: https://arxiv.org/abs/2305.09620", unsafe_allow_html=True)
|
| 74 |
n_var_per_page = 25
|
| 75 |
+
n_cards_per_row = 5
|
| 76 |
current_variable = None
|
| 77 |
+
if 'current_var' not in st.session_state:
|
| 78 |
+
st.session_state['current_var'] = None
|
| 79 |
|
| 80 |
+
if st.session_state['current_var'] is None:
|
|
|
|
|
|
|
|
|
|
| 81 |
col1, col2, col3 = st.columns([3, 1, 1])
|
| 82 |
with col1:
|
| 83 |
search_query = st.text_input('Search available GSS variables')
|
|
|
|
| 105 |
st.markdown(f'Page {page} of {maxpage}')
|
| 106 |
button_list = []
|
| 107 |
for n_row, row in results.loc[(page-1)*n_var_per_page:page*n_var_per_page-1].reset_index().iterrows():
|
| 108 |
+
i = n_row % n_cards_per_row
|
| 109 |
if i == 0:
|
| 110 |
st.write("---")
|
| 111 |
+
cols = st.columns(n_cards_per_row, gap="large")
|
| 112 |
# draw the card
|
| 113 |
+
with cols[n_row % n_cards_per_row]:
|
| 114 |
st.markdown(f"**{row['var_name'].strip()}**", unsafe_allow_html=True)
|
| 115 |
st.markdown(f"*{row['var_description'].strip()}*", unsafe_allow_html=True)
|
| 116 |
st.markdown(f"Survey question: {row['question']}", unsafe_allow_html=True)
|
| 117 |
st.markdown(f"GSS tags: {row['subject']}", unsafe_allow_html=True)
|
| 118 |
+
button_list.append(st.button('View this variable', key=row['var_name'], on_click=show_data, args=(row['var_name'], )))
|
| 119 |
for i in range(len(button_list)):
|
| 120 |
if button_list[i]:
|
| 121 |
current_variable = str(results.loc[i, 'var_name'])
|
| 122 |
st.session_state['search_mode'] = False
|
| 123 |
else:
|
| 124 |
+
goback = st.button('Go back', on_click=show_search)
|
| 125 |
+
var = st.session_state['current_var']
|
|
|
|
|
|
|
| 126 |
tab_pred = dt_summary1.loc[(dt_summary1.variable == var) & (dt_summary1.pred_type == 'rescale')]
|
| 127 |
tab_obs = dt_summary1.loc[(dt_summary1.variable == var) & (dt_summary1.pred_type == 'obsbin')]
|
| 128 |
tab_obs = tab_obs.merge(tab_pred[['year']], how='right').rename({'mean': 'obs_mean', 'lci': 'obs_lci', 'uci': 'obs_uci'}, axis=1)
|