Spaces:
Sleeping
Sleeping
jacopoteneggi
commited on
Commit
•
f6eb5e3
1
Parent(s):
5e91161
Update
Browse files- app.py +2 -0
- app_lib/test.py +1 -1
- app_lib/user_input.py +9 -9
- app_lib/viz.py +18 -1
- style.css +7 -29
app.py
CHANGED
@@ -11,6 +11,8 @@ if "results" not in st.session_state:
|
|
11 |
|
12 |
st.set_page_config(layout="wide", initial_sidebar_state=st.session_state.sidebar_state)
|
13 |
|
|
|
|
|
14 |
with open("style.css", "r") as f:
|
15 |
style = f.read()
|
16 |
with open("header.md", "r") as f:
|
|
|
11 |
|
12 |
st.set_page_config(layout="wide", initial_sidebar_state=st.session_state.sidebar_state)
|
13 |
|
14 |
+
st.session_state.sidebar_state = "collapsed"
|
15 |
+
|
16 |
with open("style.css", "r") as f:
|
17 |
style = f.read()
|
18 |
with open("header.md", "r") as f:
|
app_lib/test.py
CHANGED
@@ -113,7 +113,7 @@ def _test(testing_config, z, concept_idx, concepts, cardinality, sampler, classi
|
|
113 |
cond_p,
|
114 |
f,
|
115 |
interrupt_on="max_wealth",
|
116 |
-
max_wealth=
|
117 |
)
|
118 |
wealth = tester.wealth._wealth
|
119 |
wealth = wealth + [wealth[-1]] * (testing_config.tau_max - len(wealth))
|
|
|
113 |
cond_p,
|
114 |
f,
|
115 |
interrupt_on="max_wealth",
|
116 |
+
max_wealth=3 * 1 / testing_config.significance_level,
|
117 |
)
|
118 |
wealth = tester.wealth._wealth
|
119 |
wealth = wealth + [wealth[-1]] * (testing_config.tau_max - len(wealth))
|
app_lib/user_input.py
CHANGED
@@ -22,7 +22,7 @@ def _validate_concepts(concepts):
|
|
22 |
|
23 |
|
24 |
def _get_significance_level():
|
25 |
-
DEFAULT = 0.05
|
26 |
return st.slider(
|
27 |
"Significance level",
|
28 |
help=" ".join(
|
@@ -31,16 +31,16 @@ def _get_significance_level():
|
|
31 |
f"Defaults to {DEFAULT:.2F}.",
|
32 |
]
|
33 |
),
|
34 |
-
min_value=
|
35 |
max_value=1.0,
|
36 |
value=DEFAULT,
|
37 |
-
step=
|
38 |
disabled=st.session_state.disabled,
|
39 |
)
|
40 |
|
41 |
|
42 |
def _get_tau_max():
|
43 |
-
DEFAULT = 200
|
44 |
return int(
|
45 |
st.slider(
|
46 |
"Length of test",
|
@@ -50,9 +50,9 @@ def _get_tau_max():
|
|
50 |
f"Defaults to {DEFAULT}.",
|
51 |
]
|
52 |
),
|
53 |
-
min_value=
|
54 |
max_value=1000,
|
55 |
-
step=
|
56 |
value=DEFAULT,
|
57 |
disabled=st.session_state.disabled,
|
58 |
)
|
@@ -60,7 +60,7 @@ def _get_tau_max():
|
|
60 |
|
61 |
|
62 |
def _get_number_of_tests():
|
63 |
-
DEFAULT =
|
64 |
return int(
|
65 |
st.slider(
|
66 |
"Number of tests per concept",
|
@@ -70,9 +70,9 @@ def _get_number_of_tests():
|
|
70 |
f"Defaults to {DEFAULT}.",
|
71 |
]
|
72 |
),
|
73 |
-
min_value=
|
74 |
max_value=100,
|
75 |
-
step=
|
76 |
value=DEFAULT,
|
77 |
disabled=st.session_state.disabled,
|
78 |
)
|
|
|
22 |
|
23 |
|
24 |
def _get_significance_level():
|
25 |
+
STEP, DEFAULT = 0.01, 0.05
|
26 |
return st.slider(
|
27 |
"Significance level",
|
28 |
help=" ".join(
|
|
|
31 |
f"Defaults to {DEFAULT:.2F}.",
|
32 |
]
|
33 |
),
|
34 |
+
min_value=STEP,
|
35 |
max_value=1.0,
|
36 |
value=DEFAULT,
|
37 |
+
step=STEP,
|
38 |
disabled=st.session_state.disabled,
|
39 |
)
|
40 |
|
41 |
|
42 |
def _get_tau_max():
|
43 |
+
STEP, DEFAULT = 50, 200
|
44 |
return int(
|
45 |
st.slider(
|
46 |
"Length of test",
|
|
|
50 |
f"Defaults to {DEFAULT}.",
|
51 |
]
|
52 |
),
|
53 |
+
min_value=STEP,
|
54 |
max_value=1000,
|
55 |
+
step=STEP,
|
56 |
value=DEFAULT,
|
57 |
disabled=st.session_state.disabled,
|
58 |
)
|
|
|
60 |
|
61 |
|
62 |
def _get_number_of_tests():
|
63 |
+
STEP, DEFAULT = 5, 10
|
64 |
return int(
|
65 |
st.slider(
|
66 |
"Number of tests per concept",
|
|
|
70 |
f"Defaults to {DEFAULT}.",
|
71 |
]
|
72 |
),
|
73 |
+
min_value=STEP,
|
74 |
max_value=100,
|
75 |
+
step=STEP,
|
76 |
value=DEFAULT,
|
77 |
disabled=st.session_state.disabled,
|
78 |
)
|
app_lib/viz.py
CHANGED
@@ -19,7 +19,14 @@ def _viz_wealth(results):
|
|
19 |
wealth_df = pd.DataFrame(wealth_df)
|
20 |
|
21 |
fig = px.line(wealth_df, x="time", y="wealth", color="concept")
|
22 |
-
fig.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
st.plotly_chart(fig, use_container_width=True)
|
24 |
|
25 |
|
@@ -33,8 +40,18 @@ def viz_results():
|
|
33 |
|
34 |
with rank_tab:
|
35 |
st.subheader("Rank of Semantic Importance")
|
|
|
|
|
|
|
|
|
|
|
36 |
with wealth_tab:
|
37 |
st.subheader("Wealth Process of Testing Procedures")
|
38 |
|
|
|
|
|
|
|
|
|
|
|
39 |
if results is not None:
|
40 |
_viz_wealth(results)
|
|
|
19 |
wealth_df = pd.DataFrame(wealth_df)
|
20 |
|
21 |
fig = px.line(wealth_df, x="time", y="wealth", color="concept")
|
22 |
+
fig.add_hline(
|
23 |
+
y=1 / significance_level,
|
24 |
+
line_dash="dash",
|
25 |
+
line_color="black",
|
26 |
+
annotation_text="Rejection threshold (1 / α)",
|
27 |
+
annotation_position="bottom right",
|
28 |
+
)
|
29 |
+
fig.update_yaxes(range=[0, 1.5 * 1 / significance_level])
|
30 |
st.plotly_chart(fig, use_container_width=True)
|
31 |
|
32 |
|
|
|
40 |
|
41 |
with rank_tab:
|
42 |
st.subheader("Rank of Semantic Importance")
|
43 |
+
|
44 |
+
with st.expander("Details"):
|
45 |
+
st.write(
|
46 |
+
"This tab shows the rank of semantic importance of the concepts for the predictions of the model on the image. Concepts are sorted by increasing rejection time, where a shorter rejection time indicates higher importance."
|
47 |
+
)
|
48 |
with wealth_tab:
|
49 |
st.subheader("Wealth Process of Testing Procedures")
|
50 |
|
51 |
+
with st.expander("Details"):
|
52 |
+
st.write(
|
53 |
+
"This tab shows the average wealth process of the testing procedures for random draws of conditioning subsets with the same cardinality. The black dashed line represents the rejection threshold."
|
54 |
+
)
|
55 |
+
|
56 |
if results is not None:
|
57 |
_viz_wealth(results)
|
style.css
CHANGED
@@ -14,23 +14,24 @@ h1 {
|
|
14 |
align-items: center;
|
15 |
}
|
16 |
|
17 |
-
|
18 |
display: flex;
|
19 |
justify-content: center;
|
20 |
}
|
21 |
|
22 |
[data-testid="stVerticalBlock"]:has(> [data-testid="stExpander"]) {
|
23 |
display: block;
|
|
|
24 |
|
25 |
-
|
|
|
26 |
border: 0;
|
27 |
}
|
28 |
|
29 |
-
|
30 |
padding: 0;
|
|
|
31 |
display: inline-flex;
|
32 |
-
align-items: center;
|
33 |
-
width: fit-content;
|
34 |
}
|
35 |
|
36 |
hr {
|
@@ -38,30 +39,7 @@ h1 {
|
|
38 |
}
|
39 |
}
|
40 |
|
41 |
-
|
42 |
-
button {
|
43 |
-
padding: 0;
|
44 |
-
border: 0;
|
45 |
-
|
46 |
-
div:first-of-type>p {
|
47 |
-
font-size: small;
|
48 |
-
}
|
49 |
-
}
|
50 |
-
|
51 |
-
button:active {
|
52 |
-
background: white;
|
53 |
-
}
|
54 |
-
|
55 |
-
button:focus:not(:active) {
|
56 |
-
color: rgb(49, 51, 63);
|
57 |
-
}
|
58 |
-
|
59 |
-
button:hover>div:first-of-type>p {
|
60 |
-
text-decoration: underline;
|
61 |
-
}
|
62 |
-
}
|
63 |
-
|
64 |
-
[data-testid="stSpinner"]>div {
|
65 |
display: flex;
|
66 |
justify-content: center;
|
67 |
}
|
|
|
14 |
align-items: center;
|
15 |
}
|
16 |
|
17 |
+
.stButton {
|
18 |
display: flex;
|
19 |
justify-content: center;
|
20 |
}
|
21 |
|
22 |
[data-testid="stVerticalBlock"]:has(> [data-testid="stExpander"]) {
|
23 |
display: block;
|
24 |
+
}
|
25 |
|
26 |
+
[data-testid="stExpander"] {
|
27 |
+
>ul {
|
28 |
border: 0;
|
29 |
}
|
30 |
|
31 |
+
[role="button"] {
|
32 |
padding: 0;
|
33 |
+
margin-bottom: 4px;
|
34 |
display: inline-flex;
|
|
|
|
|
35 |
}
|
36 |
|
37 |
hr {
|
|
|
39 |
}
|
40 |
}
|
41 |
|
42 |
+
.stSpinner>div {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
43 |
display: flex;
|
44 |
justify-content: center;
|
45 |
}
|