|
import modules |
|
import streamlit as st |
|
from streamlit_extras.let_it_rain import rain |
|
|
|
|
|
DISCLAIMER = """ |
|
*This app processes data using 2-anonymity, an implementation of the k-anonymity framework. While this is a great start to anonymizing your data, it is by no means perfect, and should be used with caution. For example, some sets of sensitive features which may clearly be identified by a human could be missed by our algorithm. Please keep this in mind.* |
|
""" |
|
K = 2 |
|
|
|
|
|
st.set_page_config(layout="wide") |
|
|
|
|
|
with st.sidebar: |
|
st.header("🕵️ 2anonymity") |
|
st.markdown("*Clean and anonymize data*") |
|
with st.container() as upload: |
|
file = st.file_uploader(f"Upload dataset:", type=modules.SUPPORTED_TYPES, label_visibility="collapsed") |
|
df, (filename, extension), result = modules.load_file(file) |
|
|
|
|
|
if df is None: |
|
rain("🤠") |
|
else: |
|
|
|
with st.sidebar: |
|
|
|
with st.container() as loading_options: |
|
st.markdown("### Data loading options:") |
|
remove_duplicates = st.checkbox("Remove duplicate rows", value=True) |
|
drop_missing = st.checkbox("Remove rows with missing values", value=False) |
|
|
|
|
|
with st.container() as anonymizing_options: |
|
st.markdown("### Anonymizing options:") |
|
max_categorical_size = st.slider("Categorical Variable Threshold", min_value=2, max_value=200, value=50, step=1) |
|
bin_size = st.slider("Bin Size", min_value=2, max_value=200, value=20, step=1) |
|
redaction_selection = st.selectbox("Redaction strength", ["Low", "Medium", "High", "Extreme"]) |
|
sensitivity_minimum = {"Low": 2, "Medium": 4, "High": 6, "Extreme": 12}[redaction_selection] |
|
|
|
|
|
|
|
|
|
with st.container() as before_data: |
|
s = df.style |
|
s = s.set_properties(**{'background-color': '#fce4e4'}) |
|
st.dataframe(s) |
|
|
|
|
|
df = modules.data_cleaner(df, drop_missing, remove_duplicates) |
|
df, unprocessed = modules.data_anonymizer(df, K, max_categorical_size, bin_size, sensitivity_minimum) |
|
|
|
|
|
with st.container() as after_data: |
|
s = df.style |
|
s = s.set_properties(**{'background-color': '#e4fce4'}) |
|
st.dataframe(s) |
|
|
|
|
|
|
|
with st.sidebar: |
|
|
|
with st.container() as download_header: |
|
st.markdown("### Download options:") |
|
output_extension = st.selectbox("File type", [".csv", ".json", ".xlsx"]) |
|
if unprocessed: st.markdown(f"Error encountered when processing columns {str(unprocessed)}") |
|
|
|
|
|
with st.container() as downloader: |
|
if output_extension == ".csv": output_file = df.to_csv().encode("utf-8") |
|
elif output_extension == ".json": output_file = df.to_json().encode("utf-8") |
|
elif output_extension == ".xlsx": output_file = df.to_excel().encode("utf-8") |
|
output_filename = f"""{filename.split(".")[:-1][0]}-clean{output_extension}""" |
|
st.download_button("Download", output_file, file_name=output_filename) |
|
|
|
|
|
with st.container() as disclaimer: |
|
st.markdown( |
|
f""" |
|
Disclaimer: |
|
{DISCLAIMER} |
|
""" |
|
) |
|
|
|
|
|
st.sidebar.markdown("Created by team #2hack2furious for the hackthethreat2023") |