From 5df77c03bb960c9b545a08f490a4ebbcbf6de1f9 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 2 Jan 2024 20:43:38 +0100 Subject: [PATCH 1/5] [pre-commit.ci] pre-commit autoupdate (#170) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/psf/black: 23.11.0 → 23.12.1](https://github.com/psf/black/compare/23.11.0...23.12.1) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 978f7226..9650570a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: nbstripout files: ".ipynb" - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 23.12.1 hooks: - id: black - repo: https://github.com/pycqa/flake8 From 899194efd66a7536108d540cef2c891c3be171af Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 15 Jan 2024 09:31:01 +0100 Subject: [PATCH 2/5] [pre-commit.ci] pre-commit autoupdate (#173) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit updates: - [github.com/pycqa/flake8: 6.1.0 → 7.0.0](https://github.com/pycqa/flake8/compare/6.1.0...7.0.0) Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 9650570a..0fa1614a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -9,7 +9,7 @@ repos: hooks: - id: black - repo: https://github.com/pycqa/flake8 - rev: 6.1.0 + rev: 7.0.0 hooks: - id: flake8 - repo: https://github.com/s-weigand/flake8-nb From 721bc98f7ab309aec7f3d2480502158e986539b3 Mon Sep 17 00:00:00 2001 From: Inga Ulusoy Date: Mon, 15 Jan 2024 11:59:18 +0100 Subject: [PATCH 3/5] increment version number (#168) * increment version number increment version number for automated release with new dependency ammico-lavis * only upload to testpypi for new release tag * change codecov token transmission method --- .github/workflows/ci.yml | 5 +++-- .github/workflows/release.yml | 1 + pyproject.toml | 2 +- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index f9119718..5621a22e 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -71,8 +71,9 @@ jobs: - name: Upload coverage if: matrix.os == 'ubuntu-22.04' && matrix.python-version == '3.9' uses: codecov/codecov-action@v3 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: - fail_ci_if_error: true + fail_ci_if_error: false files: ammico/coverage.xml verbose: true - token: ${{ secrets.CODECOV_TOKEN }} diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 52628bd2..2ff1b4e4 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -95,6 +95,7 @@ jobs: publish-to-testpypi: name: Publish Python distribution to TestPyPI + if: startsWith(github.ref, 'refs/tags/') needs: - build runs-on: ubuntu-latest diff --git a/pyproject.toml b/pyproject.toml index b624220c..e1a078a0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -6,7 +6,7 @@ build-backend = "setuptools.build_meta" [project] name = "ammico" -version = "0.2.0" +version = "0.2.1" description = "AI Media and Misinformation Content Analysis Tool" readme = "README.md" maintainers = [ From f128fa4754ff76c5cd0c70e843a8456cbed0888c Mon Sep 17 00:00:00 2001 From: Inga Ulusoy Date: Tue, 16 Jan 2024 11:13:22 +0100 Subject: [PATCH 4/5] check threshold for emotion and race lies in btw 0 and 100 (#175) * check threshold for emotion and race liezs in btw 0 and 100 * Update release.yml * correct order of calling args in test display --- .github/workflows/release.yml | 7 +++---- ammico/faces.py | 5 +++++ ammico/test/test_display.py | 2 +- ammico/test/test_faces.py | 9 +++++++++ 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2ff1b4e4..0dc6e3d0 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,9 +1,8 @@ name: release to pypi on: - push: - branches: - - main + release: + types: [published] workflow_dispatch: jobs: @@ -116,4 +115,4 @@ jobs: uses: pypa/gh-action-pypi-publish@release/v1 with: repository-url: https://test.pypi.org/legacy/ - \ No newline at end of file + diff --git a/ammico/faces.py b/ammico/faces.py index c9e1c43c..a485cbb6 100644 --- a/ammico/faces.py +++ b/ammico/faces.py @@ -97,6 +97,11 @@ def __init__( """ super().__init__(subdict) self.subdict.update(self.set_keys()) + # check if thresholds are valid + if emotion_threshold < 0 or emotion_threshold > 100: + raise ValueError("Emotion threshold must be between 0 and 100.") + if race_threshold < 0 or race_threshold > 100: + raise ValueError("Race threshold must be between 0 and 100.") self.emotion_threshold = emotion_threshold self.race_threshold = race_threshold self.emotion_categories = { diff --git a/ammico/test/test_display.py b/ammico/test/test_display.py index e00c06ae..5dc0e540 100644 --- a/ammico/test/test_display.py +++ b/ammico/test/test_display.py @@ -49,10 +49,10 @@ def test_right_output_analysis_emotions(get_AE, get_options): get_options[0], "EmotionDetector", True, - 50, None, None, 50, + 50, "CIE 1976", "summary_and_questions", "base", diff --git a/ammico/test/test_faces.py b/ammico/test/test_faces.py index 66ddad32..a1d10db0 100644 --- a/ammico/test/test_faces.py +++ b/ammico/test/test_faces.py @@ -1,5 +1,6 @@ import ammico.faces as fc import json +import pytest def test_set_keys(): @@ -8,6 +9,14 @@ def test_set_keys(): assert ed.subdict["multiple_faces"] == "No" assert ed.subdict["wears_mask"] == ["No"] assert ed.subdict["emotion"] == [None] + with pytest.raises(ValueError): + fc.EmotionDetector({}, emotion_threshold=150) + with pytest.raises(ValueError): + fc.EmotionDetector({}, emotion_threshold=-50) + with pytest.raises(ValueError): + fc.EmotionDetector({}, race_threshold=150) + with pytest.raises(ValueError): + fc.EmotionDetector({}, race_threshold=-50) def test_analyse_faces(get_path): From b4aae9321cd35f82dc8086d2e6d798a47529e72f Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 31 Jan 2024 14:17:29 +0100 Subject: [PATCH 5/5] [pre-commit.ci] pre-commit autoupdate (#176) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * [pre-commit.ci] pre-commit autoupdate updates: - [github.com/psf/black: 23.12.1 → 24.1.1](https://github.com/psf/black/compare/23.12.1...24.1.1) * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> --- .pre-commit-config.yaml | 2 +- ammico/display.py | 24 +++++++++++++++--------- ammico/multimodal_search.py | 12 ++++++------ ammico/text.py | 8 +++++--- 4 files changed, 27 insertions(+), 19 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 0fa1614a..e7aed591 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,7 +5,7 @@ repos: - id: nbstripout files: ".ipynb" - repo: https://github.com/psf/black - rev: 23.12.1 + rev: 24.1.1 hooks: - id: black - repo: https://github.com/pycqa/flake8 diff --git a/ammico/display.py b/ammico/display.py index 4b289aee..ed150ab1 100644 --- a/ammico/display.py +++ b/ammico/display.py @@ -479,12 +479,16 @@ def _right_output_analysis( detector_class = identify_function( image_copy, analyse_text=analyse_text, - model_names=[settings_text_model_names] - if (settings_text_model_names is not None) - else None, - revision_numbers=[settings_text_revision_numbers] - if (settings_text_revision_numbers is not None) - else None, + model_names=( + [settings_text_model_names] + if (settings_text_model_names is not None) + else None + ), + revision_numbers=( + [settings_text_revision_numbers] + if (settings_text_revision_numbers is not None) + else None + ), ) elif detector_value == "EmotionDetector": detector_class = identify_function( @@ -502,9 +506,11 @@ def _right_output_analysis( image_copy, analysis_type=setting_summary_analysis_type, model_type=setting_summary_model, - list_of_questions=[setting_summary_list_of_questions] - if (setting_summary_list_of_questions is not None) - else None, + list_of_questions=( + [setting_summary_list_of_questions] + if (setting_summary_list_of_questions is not None) + else None + ), ) else: detector_class = identify_function(image_copy) diff --git a/ammico/multimodal_search.py b/ammico/multimodal_search.py index 47649f98..ff85570c 100644 --- a/ammico/multimodal_search.py +++ b/ammico/multimodal_search.py @@ -534,9 +534,9 @@ def multimodal_search( self.subdict[image_keys[key]][ "rank " + list(search_query[q].values())[0] ] = places[q][key] - self.subdict[image_keys[key]][ - list(search_query[q].values())[0] - ] = similarity[key][q].item() + self.subdict[image_keys[key]][list(search_query[q].values())[0]] = ( + similarity[key][q].item() + ) else: self.subdict[image_keys[key]][ "rank " + list(search_query[q].values())[0] @@ -915,9 +915,9 @@ def image_text_match_reordering( avg_gradcams.append(local_avg_gradcams) itm_scores.append(local_itm_scores) itm_scores2.append(local_itm_scores2) - image_gradcam_with_itm[ - list(search_query[index_text_query].values())[0] - ] = localimage_gradcam_with_itm + image_gradcam_with_itm[list(search_query[index_text_query].values())[0]] = ( + localimage_gradcam_with_itm + ) del ( itm_model, vis_processor_itm, diff --git a/ammico/text.py b/ammico/text.py index d4279d00..7465d958 100644 --- a/ammico/text.py +++ b/ammico/text.py @@ -220,9 +220,11 @@ def clean_text(self): """Clean the text from unrecognized words and any numbers.""" templist = [] for token in self.doc: - templist.append( - token.text - ) if token.pos_ != "NUM" and token.has_vector else None + ( + templist.append(token.text) + if token.pos_ != "NUM" and token.has_vector + else None + ) self.subdict["text_clean"] = " ".join(templist).rstrip().lstrip() def text_summary(self):