Skip to content

Commit

Permalink
add changes to display
Browse files Browse the repository at this point in the history
  • Loading branch information
iulusoy committed Jun 5, 2024
1 parent bb4cee6 commit 7eb8526
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 11 deletions.
57 changes: 56 additions & 1 deletion ammico/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,9 @@ def __init__(self, mydict: dict) -> None:
State("setting_Text_revision_numbers", "value"),
State("setting_Emotion_emotion_threshold", "value"),
State("setting_Emotion_race_threshold", "value"),
State("setting_Emotion_gender_threshold", "value"),
State("setting_Emotion_age_threshold", "value"),
State("setting_Emotion_env_var", "value"),
State("setting_Color_delta_e_method", "value"),
State("setting_Summary_analysis_type", "value"),
State("setting_Summary_model", "value"),
Expand Down Expand Up @@ -200,6 +203,13 @@ def _create_setting_layout(self):
style={"width": "100%"},
),
),
dbc.Col(
[
html.P(
"Select name of the environment variable to accept or reject the disclaimer*:"
),
]
),
dbc.Col(
dcc.Input(
type="text",
Expand Down Expand Up @@ -246,6 +256,41 @@ def _create_setting_layout(self):
],
align="start",
),
dbc.Col(
[
html.P("Gender threshold"),
dcc.Input(
type="number",
value=50,
max=100,
min=0,
id="setting_Emotion_gender_threshold",
style={"width": "100%"},
),
],
align="start",
),
dbc.Col(
[
html.P("Age threshold"),
dcc.Input(
type="number",
value=50,
max=100,
min=0,
id="setting_Emotion_age_threshold",
style={"width": "100%"},
),
],
align="start",
),
dbc.Col(
dcc.Input(
type="text",
id="setting_Emotion_env_var",
style={"width": "100%"},
),
),
],
style={"width": "100%"},
),
Expand Down Expand Up @@ -441,6 +486,9 @@ def _right_output_analysis(
settings_text_revision_numbers: str,
setting_emotion_emotion_threshold: int,
setting_emotion_race_threshold: int,
setting_emotion_gender_threshold: int,
setting_emotion_age_threshold: int,
setting_emotion_env_var: str,
setting_color_delta_e_method: str,
setting_summary_analysis_type: str,
setting_summary_model: str,
Expand Down Expand Up @@ -493,8 +541,15 @@ def _right_output_analysis(
elif detector_value == "EmotionDetector":
detector_class = identify_function(
image_copy,
race_threshold=setting_emotion_race_threshold,
emotion_threshold=setting_emotion_emotion_threshold,
race_threshold=setting_emotion_race_threshold,
gender_threshold=setting_emotion_gender_threshold,
age_threshold=setting_emotion_age_threshold,
accept_disclaimer=(
setting_emotion_env_var
if setting_emotion_env_var
else "DISCLAIMER_AMMICO"
),
)
elif detector_value == "ColorDetector":
detector_class = identify_function(
Expand Down
9 changes: 9 additions & 0 deletions ammico/notebooks/DemoNotebook_ammico.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,15 @@
"The interface opens a dash app inside the Jupyter Notebook and allows selection of the input file in the top left dropdown menu, as well as selection of the detector type in the top right, with options for each detector type as explained below. The output of the detector is shown directly on the right next to the image. This way, the user can directly inspect how updating the options for each detector changes the computed results, and find the best settings for a production run."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"os.environ[\"DISCLAIMER_AMMICO\"] = \"True\""
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
12 changes: 10 additions & 2 deletions ammico/test/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ def test_AnalysisExplorer(get_AE, get_options):
assert get_AE.update_picture(None) is None


def test_right_output_analysis_summary(get_AE, get_options):
def test_right_output_analysis_summary(get_AE, get_options, monkeypatch):
monkeypatch.setenv("OTHER_VAR", "True")
get_AE._right_output_analysis(
2,
get_options[3],
Expand All @@ -53,14 +54,18 @@ def test_right_output_analysis_summary(get_AE, get_options):
None,
50,
50,
50,
50,
"OTHER_VAR",
"CIE 1976",
"summary_and_questions",
"base",
"How many people are in the picture?",
)


def test_right_output_analysis_emotions(get_AE, get_options):
def test_right_output_analysis_emotions(get_AE, get_options, monkeypatch):
monkeypatch.setenv("OTHER_VAR", "True")
get_AE._right_output_analysis(
2,
get_options[3],
Expand All @@ -71,6 +76,9 @@ def test_right_output_analysis_emotions(get_AE, get_options):
None,
50,
50,
50,
50,
"OTHER_VAR",
"CIE 1976",
"summary_and_questions",
"base",
Expand Down
16 changes: 8 additions & 8 deletions ammico/test/test_faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ def test_init_EmotionDetector(monkeypatch):
assert ed.subdict["wears_mask"] == ["No"]
assert ed.subdict["emotion"] == [None]
assert ed.subdict["age"] == [None]
assert ed.emotion_threshold == 50.0
assert ed.age_threshold == 50.0
assert ed.gender_threshold == 50.0
assert ed.race_threshold == 50.0
assert ed.emotion_threshold == 50
assert ed.age_threshold == 50
assert ed.gender_threshold == 50
assert ed.race_threshold == 50
assert ed.emotion_categories["angry"] == "Negative"
assert ed.emotion_categories["happy"] == "Positive"
assert ed.emotion_categories["surprise"] == "Neutral"
Expand All @@ -33,10 +33,10 @@ def test_init_EmotionDetector(monkeypatch):
age_threshold=90,
accept_disclaimer="OTHER_VAR",
)
assert ed.emotion_threshold == 80.0
assert ed.race_threshold == 30.0
assert ed.gender_threshold == 70.0
assert ed.age_threshold == 90.0
assert ed.emotion_threshold == 80
assert ed.race_threshold == 30
assert ed.gender_threshold == 70
assert ed.age_threshold == 90
monkeypatch.delenv(ed.accept_disclaimer, raising=False)
# do not accept disclaimer
monkeypatch.setattr("builtins.input", lambda _: "no")
Expand Down

0 comments on commit 7eb8526

Please sign in to comment.