lynn-twinkl
commited on
Commit
·
6925f1d
1
Parent(s):
a8ba5bb
ability to download selectoin of csvs; small UI improvements
Browse files
app.py
CHANGED
|
@@ -20,6 +20,8 @@ from src.twinkl_originals import find_book_candidates
|
|
| 20 |
from src.preprocess_text import normalise_text
|
| 21 |
from typing import Tuple
|
| 22 |
|
|
|
|
|
|
|
| 23 |
##################################
|
| 24 |
# CACHED PROCESSING FUNCTION
|
| 25 |
##################################
|
|
@@ -68,7 +70,7 @@ def load_and_process(raw_csv: bytes) -> Tuple[pd.DataFrame, str]:
|
|
| 68 |
|
| 69 |
# Usage Extraction
|
| 70 |
docs = df_orig[freeform_col].to_list()
|
| 71 |
-
|
| 72 |
|
| 73 |
return scored, freeform_col
|
| 74 |
|
|
@@ -85,11 +87,9 @@ def compute_shortlist(df: pd.DataFrame) -> pd.DataFrame:
|
|
| 85 |
return shortlist_applications(df, k=len(df))
|
| 86 |
|
| 87 |
################################
|
| 88 |
-
# APP SCRIPT
|
| 89 |
################################
|
| 90 |
|
| 91 |
-
style_metric_cards(box_shadow=False, border_left_color='#E7F4FF',background_color='#E7F4FF', border_size_px=0, border_radius_px=6)
|
| 92 |
-
|
| 93 |
st.title("Community Collections Helper")
|
| 94 |
|
| 95 |
uploaded_file = st.file_uploader("Upload grant applications file for analysis", type='csv')
|
|
@@ -98,17 +98,20 @@ if uploaded_file is not None:
|
|
| 98 |
# Read file from raw bytes for caching and repeated use --> this ensure all the processing isn't repeated when a user changes the filters
|
| 99 |
raw = uploaded_file.read()
|
| 100 |
|
| 101 |
-
##
|
| 102 |
|
| 103 |
df, freeform_col = load_and_process(raw)
|
| 104 |
|
| 105 |
-
|
| 106 |
|
| 107 |
-
|
|
|
|
|
|
|
| 108 |
|
| 109 |
with st.sidebar:
|
| 110 |
st.title("Shortlist Mode")
|
| 111 |
|
|
|
|
| 112 |
quantile_map = {"strict": 0.75, "generous": 0.5}
|
| 113 |
mode = st.segmented_control(
|
| 114 |
"Select one option",
|
|
@@ -126,31 +129,52 @@ if uploaded_file is not None:
|
|
| 126 |
filter_range = st.sidebar.slider(
|
| 127 |
"Necessity Index Range", min_value=min_idx, max_value=max_idx, value=(min_idx, max_idx)
|
| 128 |
)
|
|
|
|
| 129 |
filtered_df = df[(~df.index.isin(auto_short_df.index)) & (df['necessity_index'].between(filter_range[0], filter_range[1]))]
|
| 130 |
|
| 131 |
st.markdown(f"**Total Applications:** {len(df)}")
|
| 132 |
st.markdown(f"**Filtered Applications:** {len(filtered_df)}")
|
| 133 |
|
| 134 |
-
|
| 135 |
-
|
| 136 |
tab1, tab2 = st.tabs(["Shortlist Manager","Insights"])
|
| 137 |
|
| 138 |
-
|
|
|
|
|
|
|
| 139 |
|
| 140 |
with tab1:
|
| 141 |
|
|
|
|
|
|
|
| 142 |
st.header("✨ Automatic Shortlist")
|
| 143 |
-
st.markdown("Here's your **automatically genereated shortlist!** If you'd like to manually add additional applications, you may do so on the section below!")
|
| 144 |
|
| 145 |
csv_auto = auto_short_df.to_csv(index=False).encode("utf-8")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 146 |
st.download_button(
|
| 147 |
-
label="Download
|
| 148 |
-
data=
|
| 149 |
-
file_name=
|
| 150 |
mime="text/csv",
|
| 151 |
-
|
|
|
|
|
|
|
| 152 |
)
|
| 153 |
-
|
|
|
|
| 154 |
st.write("")
|
| 155 |
total_col, shortlistCounter_col, mode_col = st.columns(3)
|
| 156 |
|
|
@@ -172,8 +196,9 @@ if uploaded_file is not None:
|
|
| 172 |
|
| 173 |
st.dataframe(auto_short_df.loc[:, shorltist_cols_to_show], hide_index=True)
|
| 174 |
|
| 175 |
-
##
|
| 176 |
|
|
|
|
| 177 |
st.header("🌸 Manual Filtering")
|
| 178 |
st.markdown(
|
| 179 |
"""
|
|
@@ -214,7 +239,7 @@ if uploaded_file is not None:
|
|
| 214 |
key=f"shortlist_{idx}"
|
| 215 |
)
|
| 216 |
|
| 217 |
-
|
| 218 |
shortlisted = [
|
| 219 |
i for i in filtered_df.index
|
| 220 |
if st.session_state.get(f"shortlist_{i}", False)
|
|
|
|
| 20 |
from src.preprocess_text import normalise_text
|
| 21 |
from typing import Tuple
|
| 22 |
|
| 23 |
+
style_metric_cards(box_shadow=False, border_left_color='#E7F4FF',background_color='#E7F4FF', border_size_px=0, border_radius_px=6)
|
| 24 |
+
|
| 25 |
##################################
|
| 26 |
# CACHED PROCESSING FUNCTION
|
| 27 |
##################################
|
|
|
|
| 70 |
|
| 71 |
# Usage Extraction
|
| 72 |
docs = df_orig[freeform_col].to_list()
|
| 73 |
+
scored['Usage'] = extract_usage(docs)
|
| 74 |
|
| 75 |
return scored, freeform_col
|
| 76 |
|
|
|
|
| 87 |
return shortlist_applications(df, k=len(df))
|
| 88 |
|
| 89 |
################################
|
| 90 |
+
# MAIN APP SCRIPT
|
| 91 |
################################
|
| 92 |
|
|
|
|
|
|
|
| 93 |
st.title("Community Collections Helper")
|
| 94 |
|
| 95 |
uploaded_file = st.file_uploader("Upload grant applications file for analysis", type='csv')
|
|
|
|
| 98 |
# Read file from raw bytes for caching and repeated use --> this ensure all the processing isn't repeated when a user changes the filters
|
| 99 |
raw = uploaded_file.read()
|
| 100 |
|
| 101 |
+
## ====== PROCESSED DATA (CACHED) ======
|
| 102 |
|
| 103 |
df, freeform_col = load_and_process(raw)
|
| 104 |
|
| 105 |
+
book_candidates_df = df[df['book_candidates'] == True]
|
| 106 |
|
| 107 |
+
###############################
|
| 108 |
+
# SIDEBAR #
|
| 109 |
+
###############################
|
| 110 |
|
| 111 |
with st.sidebar:
|
| 112 |
st.title("Shortlist Mode")
|
| 113 |
|
| 114 |
+
|
| 115 |
quantile_map = {"strict": 0.75, "generous": 0.5}
|
| 116 |
mode = st.segmented_control(
|
| 117 |
"Select one option",
|
|
|
|
| 129 |
filter_range = st.sidebar.slider(
|
| 130 |
"Necessity Index Range", min_value=min_idx, max_value=max_idx, value=(min_idx, max_idx)
|
| 131 |
)
|
| 132 |
+
|
| 133 |
filtered_df = df[(~df.index.isin(auto_short_df.index)) & (df['necessity_index'].between(filter_range[0], filter_range[1]))]
|
| 134 |
|
| 135 |
st.markdown(f"**Total Applications:** {len(df)}")
|
| 136 |
st.markdown(f"**Filtered Applications:** {len(filtered_df)}")
|
| 137 |
|
| 138 |
+
# ------ CREATE TAB SECTIONS -------
|
|
|
|
| 139 |
tab1, tab2 = st.tabs(["Shortlist Manager","Insights"])
|
| 140 |
|
| 141 |
+
##################################################
|
| 142 |
+
# SHORTLIST MANAGER TAB #
|
| 143 |
+
##################################################
|
| 144 |
|
| 145 |
with tab1:
|
| 146 |
|
| 147 |
+
## =========== AUTOMATIC SHORTLIST =========
|
| 148 |
+
|
| 149 |
st.header("✨ Automatic Shortlist")
|
|
|
|
| 150 |
|
| 151 |
csv_auto = auto_short_df.to_csv(index=False).encode("utf-8")
|
| 152 |
+
all_processed_data = df.to_csv(index=False).encode("utf-8")
|
| 153 |
+
book_candidates = book_candidates_df.to_csv(index=False).encode("utf-8")
|
| 154 |
+
|
| 155 |
+
|
| 156 |
+
csv_options = {
|
| 157 |
+
"Shortlist": (csv_auto, "shortlist.csv"),
|
| 158 |
+
"All Processed Data": (all_processed_data, "all_processed.csv"),
|
| 159 |
+
"Book Candidates": (book_candidates, "book_candidates.csv"),
|
| 160 |
+
}
|
| 161 |
+
|
| 162 |
+
choice = st.selectbox("Select a file for download", list(csv_options.keys()))
|
| 163 |
+
|
| 164 |
+
csv_data, file_name = csv_options[choice]
|
| 165 |
+
|
| 166 |
+
|
| 167 |
st.download_button(
|
| 168 |
+
label=f"Download CSV",
|
| 169 |
+
data=csv_data,
|
| 170 |
+
file_name=file_name,
|
| 171 |
mime="text/csv",
|
| 172 |
+
help="This button will download the selected file from above",
|
| 173 |
+
icon="⬇️"
|
| 174 |
+
|
| 175 |
)
|
| 176 |
+
|
| 177 |
+
|
| 178 |
st.write("")
|
| 179 |
total_col, shortlistCounter_col, mode_col = st.columns(3)
|
| 180 |
|
|
|
|
| 196 |
|
| 197 |
st.dataframe(auto_short_df.loc[:, shorltist_cols_to_show], hide_index=True)
|
| 198 |
|
| 199 |
+
## ====== APPLICATIONS REVIEW =======
|
| 200 |
|
| 201 |
+
st.divider()
|
| 202 |
st.header("🌸 Manual Filtering")
|
| 203 |
st.markdown(
|
| 204 |
"""
|
|
|
|
| 239 |
key=f"shortlist_{idx}"
|
| 240 |
)
|
| 241 |
|
| 242 |
+
## ======== SHORTLIST SUMMARY AND DOWNLOAD (MANUAL) ======
|
| 243 |
shortlisted = [
|
| 244 |
i for i in filtered_df.index
|
| 245 |
if st.session_state.get(f"shortlist_{i}", False)
|