Skip to content

Commit

Permalink
Merge branch 'main' into minor_fixing
Browse files Browse the repository at this point in the history
  • Loading branch information
iulusoy authored Feb 1, 2024
2 parents 3ce166b + b4aae93 commit c675835
Show file tree
Hide file tree
Showing 10 changed files with 51 additions and 28 deletions.
5 changes: 3 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
8 changes: 4 additions & 4 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
name: release to pypi

on:
push:
branches:
- main
release:
types: [published]
workflow_dispatch:

jobs:
Expand Down Expand Up @@ -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
Expand All @@ -115,4 +115,4 @@ jobs:
uses: pypa/gh-action-pypi-publish@release/v1
with:
repository-url: https://test.pypi.org/legacy/


4 changes: 2 additions & 2 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
24 changes: 15 additions & 9 deletions ammico/display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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)
Expand Down
5 changes: 5 additions & 0 deletions ammico/faces.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down
12 changes: 6 additions & 6 deletions ammico/multimodal_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion ammico/test/test_display.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 9 additions & 0 deletions ammico/test/test_faces.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import ammico.faces as fc
import json
import pytest


def test_set_keys():
Expand All @@ -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):
Expand Down
8 changes: 5 additions & 3 deletions ammico/text.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [
Expand Down

0 comments on commit c675835

Please sign in to comment.