Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,9 @@ from rapidfuzz import fuzz, utils
|
|
| 10 |
if 'current_var' not in st.session_state:
|
| 11 |
st.session_state['current_var'] = None
|
| 12 |
|
|
|
|
|
|
|
|
|
|
| 13 |
data = pd.read_parquet('var_meta.parquet')
|
| 14 |
subject = pd.read_parquet('subject_meta.parquet')
|
| 15 |
count_meta = pd.read_parquet('count_meta.parquet')
|
|
@@ -32,6 +35,7 @@ def search_data(query, search_criteria, search_filter):
|
|
| 32 |
data_sub = data.loc[data.var_name.isin(selected_vars)]
|
| 33 |
if len(query) == 0:
|
| 34 |
return data_sub
|
|
|
|
| 35 |
query = query.lower()
|
| 36 |
d1 = data_sub.loc[data_sub['var_name'].str.lower().str.contains(query)]
|
| 37 |
d2 = data_sub.loc[data_sub['var_description'].str.lower().str.contains(query)]
|
|
@@ -67,6 +71,9 @@ def show_data(var):
|
|
| 67 |
def show_search():
|
| 68 |
st.session_state['current_var'] = None
|
| 69 |
|
|
|
|
|
|
|
|
|
|
| 70 |
# Main function to run the Streamlit app
|
| 71 |
def main():
|
| 72 |
st.set_page_config(page_title="AI-Augmented Surveys: Browse Retrodictions", layout="wide")
|
|
@@ -83,10 +90,10 @@ def main():
|
|
| 83 |
search_criteria = st.selectbox("Criteria", ['All', 'Variable Names', 'Variable Descriptions', 'Survey Questions', 'GSS Tags'])
|
| 84 |
with col3:
|
| 85 |
search_filter = st.multiselect("Filter by GSS tags", count_meta['option'])
|
| 86 |
-
search_button = st.button("Search")
|
| 87 |
|
| 88 |
# Perform search when the search button is clicked
|
| 89 |
-
if
|
| 90 |
results = search_data(search_query, search_criteria, search_filter).reset_index(drop=True)
|
| 91 |
if results.empty:
|
| 92 |
st.warning('No variables found.')
|
|
@@ -113,7 +120,7 @@ def main():
|
|
| 113 |
st.markdown(f"*{row['var_description'].strip()}*", unsafe_allow_html=True)
|
| 114 |
st.markdown(f"Survey question: {row['question']}", unsafe_allow_html=True)
|
| 115 |
st.markdown(f"GSS tags: {row['subject']}", unsafe_allow_html=True)
|
| 116 |
-
button_list.append(st.button('View this variable', key=row['var_name'], on_click=show_data, args=(row['
|
| 117 |
for i in range(len(button_list)):
|
| 118 |
if button_list[i]:
|
| 119 |
current_variable = str(results.loc[i, 'var_name'])
|
|
|
|
| 10 |
if 'current_var' not in st.session_state:
|
| 11 |
st.session_state['current_var'] = None
|
| 12 |
|
| 13 |
+
if 'search_ongoing' not in st.session_state:
|
| 14 |
+
st.session_state['search_ongoing'] = False
|
| 15 |
+
|
| 16 |
data = pd.read_parquet('var_meta.parquet')
|
| 17 |
subject = pd.read_parquet('subject_meta.parquet')
|
| 18 |
count_meta = pd.read_parquet('count_meta.parquet')
|
|
|
|
| 35 |
data_sub = data.loc[data.var_name.isin(selected_vars)]
|
| 36 |
if len(query) == 0:
|
| 37 |
return data_sub
|
| 38 |
+
data_sub['original_var_name'] = data_sub['var_name']
|
| 39 |
query = query.lower()
|
| 40 |
d1 = data_sub.loc[data_sub['var_name'].str.lower().str.contains(query)]
|
| 41 |
d2 = data_sub.loc[data_sub['var_description'].str.lower().str.contains(query)]
|
|
|
|
| 71 |
def show_search():
|
| 72 |
st.session_state['current_var'] = None
|
| 73 |
|
| 74 |
+
def start_search():
|
| 75 |
+
st.session_state['search_ongoing'] = True
|
| 76 |
+
|
| 77 |
# Main function to run the Streamlit app
|
| 78 |
def main():
|
| 79 |
st.set_page_config(page_title="AI-Augmented Surveys: Browse Retrodictions", layout="wide")
|
|
|
|
| 90 |
search_criteria = st.selectbox("Criteria", ['All', 'Variable Names', 'Variable Descriptions', 'Survey Questions', 'GSS Tags'])
|
| 91 |
with col3:
|
| 92 |
search_filter = st.multiselect("Filter by GSS tags", count_meta['option'])
|
| 93 |
+
search_button = st.button("Search", on_click=start_search)
|
| 94 |
|
| 95 |
# Perform search when the search button is clicked
|
| 96 |
+
if st.session_state['search_ongoing']:
|
| 97 |
results = search_data(search_query, search_criteria, search_filter).reset_index(drop=True)
|
| 98 |
if results.empty:
|
| 99 |
st.warning('No variables found.')
|
|
|
|
| 120 |
st.markdown(f"*{row['var_description'].strip()}*", unsafe_allow_html=True)
|
| 121 |
st.markdown(f"Survey question: {row['question']}", unsafe_allow_html=True)
|
| 122 |
st.markdown(f"GSS tags: {row['subject']}", unsafe_allow_html=True)
|
| 123 |
+
button_list.append(st.button('View this variable', key=row['var_name'], on_click=show_data, args=(row['original_var_name'], )))
|
| 124 |
for i in range(len(button_list)):
|
| 125 |
if button_list[i]:
|
| 126 |
current_variable = str(results.loc[i, 'var_name'])
|