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..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: @@ -95,6 +94,7 @@ jobs: publish-to-testpypi: name: Publish Python distribution to TestPyPI + if: startsWith(github.ref, 'refs/tags/') needs: - build runs-on: ubuntu-latest @@ -115,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/.pre-commit-config.yaml b/.pre-commit-config.yaml index 978f7226..e7aed591 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -5,11 +5,11 @@ repos: - id: nbstripout files: ".ipynb" - repo: https://github.com/psf/black - rev: 23.11.0 + rev: 24.1.1 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 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/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/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/test/test_display.py b/ammico/test/test_display.py index b49d2ee0..8b19073a 100644 --- a/ammico/test/test_display.py +++ b/ammico/test/test_display.py @@ -49,10 +49,10 @@ def test_right_output_analysis_summary(get_AE, get_options): get_options[0], "SummaryDetector", 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 ef2c3e9c..6dcf2841 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): 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): diff --git a/pyproject.toml b/pyproject.toml index 76bbc679..493547c1 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 = [