From 7eb8526b05a4bc862dc32efdaeed4ab8484ec084 Mon Sep 17 00:00:00 2001 From: Inga Ulusoy Date: Wed, 5 Jun 2024 14:27:45 +0200 Subject: [PATCH] add changes to display --- ammico/display.py | 57 +++++++++++++++++++++- ammico/notebooks/DemoNotebook_ammico.ipynb | 9 ++++ ammico/test/test_display.py | 12 ++++- ammico/test/test_faces.py | 16 +++--- 4 files changed, 83 insertions(+), 11 deletions(-) diff --git a/ammico/display.py b/ammico/display.py index ed150ab1..cd047b7b 100644 --- a/ammico/display.py +++ b/ammico/display.py @@ -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"), @@ -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", @@ -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%"}, ), @@ -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, @@ -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( diff --git a/ammico/notebooks/DemoNotebook_ammico.ipynb b/ammico/notebooks/DemoNotebook_ammico.ipynb index f3767c3c..9bdc482f 100644 --- a/ammico/notebooks/DemoNotebook_ammico.ipynb +++ b/ammico/notebooks/DemoNotebook_ammico.ipynb @@ -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, diff --git a/ammico/test/test_display.py b/ammico/test/test_display.py index 8b19073a..102f9731 100644 --- a/ammico/test/test_display.py +++ b/ammico/test/test_display.py @@ -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], @@ -53,6 +54,9 @@ def test_right_output_analysis_summary(get_AE, get_options): None, 50, 50, + 50, + 50, + "OTHER_VAR", "CIE 1976", "summary_and_questions", "base", @@ -60,7 +64,8 @@ def test_right_output_analysis_summary(get_AE, get_options): ) -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], @@ -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", diff --git a/ammico/test/test_faces.py b/ammico/test/test_faces.py index e63e1d01..6cd935e4 100644 --- a/ammico/test/test_faces.py +++ b/ammico/test/test_faces.py @@ -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" @@ -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")