Update app.py
Browse files
app.py
CHANGED
|
@@ -2,90 +2,129 @@ import streamlit as st
|
|
| 2 |
|
| 3 |
st.set_page_config(layout="wide")
|
| 4 |
|
| 5 |
-
st.title("AI Model
|
| 6 |
-
|
| 7 |
-
st.markdown(
|
| 8 |
-
"""
|
| 9 |
-
Select actions taken by the **Model Owner** and the **Auditor**.
|
| 10 |
-
The dashboard will update to estimate:
|
| 11 |
-
|
| 12 |
-
- Probability the model owner can cheat the audit
|
| 13 |
-
- Cost of auditing
|
| 14 |
-
- Level of openness required
|
| 15 |
-
"""
|
| 16 |
-
)
|
| 17 |
|
| 18 |
# -------------------------
|
| 19 |
# Strategy Definitions
|
| 20 |
# -------------------------
|
| 21 |
|
| 22 |
model_owner_actions = {
|
| 23 |
-
"Fine-tuning / overfitting on auditing test": {
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
},
|
| 28 |
-
"Fine-tuning on auditing-like data distribution": {
|
| 29 |
-
"cheating": 20,
|
| 30 |
-
"cost": 0,
|
| 31 |
-
"openness": -3
|
| 32 |
-
},
|
| 33 |
-
"Training a special audit-behavior mode": {
|
| 34 |
-
"cheating": 30,
|
| 35 |
-
"cost": 5,
|
| 36 |
-
"openness": -10
|
| 37 |
-
},
|
| 38 |
-
"Withholding training details": {
|
| 39 |
-
"cheating": 15,
|
| 40 |
-
"cost": 0,
|
| 41 |
-
"openness": -15
|
| 42 |
-
}
|
| 43 |
}
|
| 44 |
|
| 45 |
auditor_actions = {
|
| 46 |
-
"Audit on one dataset": {
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
},
|
| 51 |
-
"Audit on multiple datasets": {
|
| 52 |
-
"cheating": -15,
|
| 53 |
-
"cost": 25,
|
| 54 |
-
"openness": 10
|
| 55 |
-
},
|
| 56 |
-
"Request internal model access": {
|
| 57 |
-
"cheating": -25,
|
| 58 |
-
"cost": 30,
|
| 59 |
-
"openness": 30
|
| 60 |
-
},
|
| 61 |
-
"Request training data documentation": {
|
| 62 |
-
"cheating": -10,
|
| 63 |
-
"cost": 5,
|
| 64 |
-
"openness": 20
|
| 65 |
-
}
|
| 66 |
}
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
# -------------------------
|
| 69 |
# Layout
|
| 70 |
# -------------------------
|
| 71 |
|
| 72 |
left, right = st.columns(2)
|
| 73 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 74 |
with left:
|
| 75 |
-
st.header("Model Owner
|
|
|
|
|
|
|
|
|
|
|
|
|
| 76 |
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
|
| 82 |
with right:
|
| 83 |
-
st.header("Auditor
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 84 |
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
# -------------------------
|
| 91 |
# Score Calculation
|
|
@@ -95,12 +134,12 @@ cheating_score = 50
|
|
| 95 |
audit_cost = 0
|
| 96 |
openness_required = 0
|
| 97 |
|
| 98 |
-
for action in
|
| 99 |
cheating_score += model_owner_actions[action]["cheating"]
|
| 100 |
audit_cost += model_owner_actions[action]["cost"]
|
| 101 |
openness_required += model_owner_actions[action]["openness"]
|
| 102 |
|
| 103 |
-
for action in
|
| 104 |
cheating_score += auditor_actions[action]["cheating"]
|
| 105 |
audit_cost += auditor_actions[action]["cost"]
|
| 106 |
openness_required += auditor_actions[action]["openness"]
|
|
@@ -113,27 +152,13 @@ openness_required = max(0, openness_required)
|
|
| 113 |
# -------------------------
|
| 114 |
|
| 115 |
st.divider()
|
|
|
|
| 116 |
st.subheader("Audit Outcome Dashboard")
|
| 117 |
|
| 118 |
col1, col2, col3 = st.columns(3)
|
| 119 |
|
| 120 |
-
col1.metric(
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
)
|
| 124 |
-
|
| 125 |
-
col2.metric(
|
| 126 |
-
"Audit Cost",
|
| 127 |
-
audit_cost
|
| 128 |
-
)
|
| 129 |
-
|
| 130 |
-
col3.metric(
|
| 131 |
-
"Openness Required",
|
| 132 |
-
openness_required
|
| 133 |
-
)
|
| 134 |
-
|
| 135 |
-
# -------------------------
|
| 136 |
-
# Optional Visualization
|
| 137 |
-
# -------------------------
|
| 138 |
|
| 139 |
st.progress(cheating_score / 100)
|
|
|
|
| 2 |
|
| 3 |
st.set_page_config(layout="wide")
|
| 4 |
|
| 5 |
+
st.title("AI Model Fairness Auditing")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
| 7 |
# -------------------------
|
| 8 |
# Strategy Definitions
|
| 9 |
# -------------------------
|
| 10 |
|
| 11 |
model_owner_actions = {
|
| 12 |
+
"Fine-tuning / overfitting on auditing test": {"cheating": 25, "cost": 0, "openness": -5},
|
| 13 |
+
"Fine-tuning on auditing-like data distribution": {"cheating": 20, "cost": 0, "openness": -3},
|
| 14 |
+
"Training a special audit-behavior mode": {"cheating": 30, "cost": 5, "openness": -10},
|
| 15 |
+
"Withholding training details": {"cheating": 15, "cost": 0, "openness": -15}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 16 |
}
|
| 17 |
|
| 18 |
auditor_actions = {
|
| 19 |
+
"Audit on one dataset": {"cheating": 20, "cost": 10, "openness": 5},
|
| 20 |
+
"Audit on multiple datasets": {"cheating": -15, "cost": 25, "openness": 10},
|
| 21 |
+
"Request internal model access": {"cheating": -25, "cost": 30, "openness": 30},
|
| 22 |
+
"Request training data documentation": {"cheating": -10, "cost": 5, "openness": 20}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
}
|
| 24 |
|
| 25 |
+
# -------------------------
|
| 26 |
+
# Session State
|
| 27 |
+
# -------------------------
|
| 28 |
+
|
| 29 |
+
if "owner_selected" not in st.session_state:
|
| 30 |
+
st.session_state.owner_selected = []
|
| 31 |
+
|
| 32 |
+
if "auditor_selected" not in st.session_state:
|
| 33 |
+
st.session_state.auditor_selected = []
|
| 34 |
+
|
| 35 |
+
# -------------------------
|
| 36 |
+
# Toggle functions
|
| 37 |
+
# -------------------------
|
| 38 |
+
|
| 39 |
+
def toggle_owner(action):
|
| 40 |
+
if action in st.session_state.owner_selected:
|
| 41 |
+
st.session_state.owner_selected.remove(action)
|
| 42 |
+
else:
|
| 43 |
+
st.session_state.owner_selected.append(action)
|
| 44 |
+
|
| 45 |
+
def toggle_auditor(action):
|
| 46 |
+
if action in st.session_state.auditor_selected:
|
| 47 |
+
st.session_state.auditor_selected.remove(action)
|
| 48 |
+
else:
|
| 49 |
+
st.session_state.auditor_selected.append(action)
|
| 50 |
+
|
| 51 |
# -------------------------
|
| 52 |
# Layout
|
| 53 |
# -------------------------
|
| 54 |
|
| 55 |
left, right = st.columns(2)
|
| 56 |
|
| 57 |
+
# -------------------------
|
| 58 |
+
# Model Owner Panel
|
| 59 |
+
# -------------------------
|
| 60 |
+
|
| 61 |
with left:
|
| 62 |
+
st.header("Model Owner")
|
| 63 |
+
|
| 64 |
+
st.subheader("Selected Actions")
|
| 65 |
+
|
| 66 |
+
selected_box = st.container(border=True)
|
| 67 |
|
| 68 |
+
with selected_box:
|
| 69 |
+
for action in st.session_state.owner_selected:
|
| 70 |
+
st.button(
|
| 71 |
+
action,
|
| 72 |
+
key=f"owner_selected_{action}",
|
| 73 |
+
on_click=toggle_owner,
|
| 74 |
+
args=(action,),
|
| 75 |
+
use_container_width=True
|
| 76 |
+
)
|
| 77 |
+
|
| 78 |
+
st.subheader("Available Actions")
|
| 79 |
+
|
| 80 |
+
available_box = st.container(border=True)
|
| 81 |
+
|
| 82 |
+
with available_box:
|
| 83 |
+
for action in model_owner_actions:
|
| 84 |
+
if action not in st.session_state.owner_selected:
|
| 85 |
+
st.button(
|
| 86 |
+
action,
|
| 87 |
+
key=f"owner_available_{action}",
|
| 88 |
+
on_click=toggle_owner,
|
| 89 |
+
args=(action,),
|
| 90 |
+
use_container_width=True
|
| 91 |
+
)
|
| 92 |
+
|
| 93 |
+
# -------------------------
|
| 94 |
+
# Auditor Panel
|
| 95 |
+
# -------------------------
|
| 96 |
|
| 97 |
with right:
|
| 98 |
+
st.header("Auditor")
|
| 99 |
+
|
| 100 |
+
st.subheader("Selected Actions")
|
| 101 |
+
|
| 102 |
+
selected_box = st.container(border=True)
|
| 103 |
+
|
| 104 |
+
with selected_box:
|
| 105 |
+
for action in st.session_state.auditor_selected:
|
| 106 |
+
st.button(
|
| 107 |
+
action,
|
| 108 |
+
key=f"auditor_selected_{action}",
|
| 109 |
+
on_click=toggle_auditor,
|
| 110 |
+
args=(action,),
|
| 111 |
+
use_container_width=True
|
| 112 |
+
)
|
| 113 |
|
| 114 |
+
st.subheader("Available Actions")
|
| 115 |
+
|
| 116 |
+
available_box = st.container(border=True)
|
| 117 |
+
|
| 118 |
+
with available_box:
|
| 119 |
+
for action in auditor_actions:
|
| 120 |
+
if action not in st.session_state.auditor_selected:
|
| 121 |
+
st.button(
|
| 122 |
+
action,
|
| 123 |
+
key=f"auditor_available_{action}",
|
| 124 |
+
on_click=toggle_auditor,
|
| 125 |
+
args=(action,),
|
| 126 |
+
use_container_width=True
|
| 127 |
+
)
|
| 128 |
|
| 129 |
# -------------------------
|
| 130 |
# Score Calculation
|
|
|
|
| 134 |
audit_cost = 0
|
| 135 |
openness_required = 0
|
| 136 |
|
| 137 |
+
for action in st.session_state.owner_selected:
|
| 138 |
cheating_score += model_owner_actions[action]["cheating"]
|
| 139 |
audit_cost += model_owner_actions[action]["cost"]
|
| 140 |
openness_required += model_owner_actions[action]["openness"]
|
| 141 |
|
| 142 |
+
for action in st.session_state.auditor_selected:
|
| 143 |
cheating_score += auditor_actions[action]["cheating"]
|
| 144 |
audit_cost += auditor_actions[action]["cost"]
|
| 145 |
openness_required += auditor_actions[action]["openness"]
|
|
|
|
| 152 |
# -------------------------
|
| 153 |
|
| 154 |
st.divider()
|
| 155 |
+
|
| 156 |
st.subheader("Audit Outcome Dashboard")
|
| 157 |
|
| 158 |
col1, col2, col3 = st.columns(3)
|
| 159 |
|
| 160 |
+
col1.metric("Chance of Cheating", f"{cheating_score}%")
|
| 161 |
+
col2.metric("Audit Cost", audit_cost)
|
| 162 |
+
col3.metric("Openness Required", openness_required)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 163 |
|
| 164 |
st.progress(cheating_score / 100)
|