-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
17dca4a
commit 16aca37
Showing
24 changed files
with
930 additions
and
571 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,4 +5,4 @@ | |
|
||
@register(Config) | ||
class ConfigAdmin(ModelAdmin): | ||
pass | ||
list_display = ("name", "settings") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
...ne/apps/api/migrations/0009_remove_config_face_distance_threshold_config_name_and_more.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Generated by Django 5.0.7 on 2024-10-31 06:31 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("api", "0008_ignoredfilenamepair"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="config", | ||
name="face_distance_threshold", | ||
), | ||
migrations.AddField( | ||
model_name="config", | ||
name="name", | ||
field=models.CharField( | ||
blank=True, db_index=True, max_length=128, null=True, unique=True | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="config", | ||
name="settings", | ||
field=models.JSONField(blank=True, default=dict, null=True), | ||
), | ||
migrations.AlterField( | ||
model_name="deduplicationset", | ||
name="config", | ||
field=models.ForeignKey( | ||
null=True, on_delete=django.db.models.deletion.SET_NULL, to="api.config" | ||
), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from django.core.exceptions import ValidationError | ||
from django.db import models | ||
|
||
from jsonschema import ValidationError as JSONSchemaValidationError | ||
|
||
from hope_dedup_engine.apps.api.utils.config_schema import ( | ||
DefaultValidatingValidator, | ||
settings_schema, | ||
) | ||
|
||
|
||
class Config(models.Model): | ||
name = models.CharField( | ||
max_length=128, unique=True, null=True, blank=True, db_index=True | ||
) | ||
settings = models.JSONField(default=dict, null=True, blank=True) | ||
|
||
def __str__(self) -> str: | ||
return f"{self.name}" if self.name else f"ID: {self.pk}" | ||
|
||
def clean(self) -> None: | ||
try: | ||
DefaultValidatingValidator(settings_schema).validate(self.settings) | ||
except JSONSchemaValidationError as e: | ||
raise ValidationError({"settings": e.message}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
from django.conf import settings | ||
|
||
from constance import config | ||
from jsonschema import Draft202012Validator, validators | ||
|
||
settings_schema: dict = { | ||
"type": "object", | ||
"properties": { | ||
"detection": { | ||
"type": "object", | ||
"properties": { | ||
"confidence": { | ||
"type": "number", | ||
"exclusiveMinimum": 0, | ||
"maximum": 1.0, | ||
"default": "constance.config.FACE_DETECTION_CONFIDENCE", | ||
}, | ||
}, | ||
"default": {}, | ||
}, | ||
"recognition": { | ||
"type": "object", | ||
"properties": { | ||
"num_jitters": { | ||
"type": "integer", | ||
"minimum": 1, | ||
"default": "constance.config.FACE_ENCODINGS_NUM_JITTERS", | ||
}, | ||
"model": { | ||
"type": "string", | ||
"enum": tuple( | ||
ch[0] | ||
for ch in settings.CONSTANCE_ADDITIONAL_FIELDS.get( | ||
"face_encodings_model" | ||
)[1].get("choices") | ||
), | ||
"default": "constance.config.FACE_ENCODINGS_MODEL", | ||
}, | ||
"preprocessors": { | ||
type: "array", | ||
"items": { | ||
"type": "string", | ||
"enum": ["contrast"], | ||
}, | ||
"uniqueItems": True, | ||
"default": [], | ||
}, | ||
}, | ||
"default": {}, | ||
}, | ||
"duplicates": { | ||
"type": "object", | ||
"properties": { | ||
"tolerance": { | ||
"type": "number", | ||
"exclusiveMinimum": 0, | ||
"maximum": 1.0, | ||
"default": "constance.config.FACE_DISTANCE_THRESHOLD", | ||
}, | ||
}, | ||
"default": {}, | ||
}, | ||
}, | ||
} | ||
|
||
|
||
def extend_with_default(validator_class): | ||
validate_properties = validator_class.VALIDATORS["properties"] | ||
|
||
def set_defaults(validator, properties, instance, schema): | ||
for property, subschema in properties.items(): | ||
|
||
if "default" in subschema: | ||
default_value = subschema["default"] | ||
if isinstance(default_value, str) and default_value.startswith( | ||
"constance.config." | ||
): | ||
config_name = default_value.split(".")[-1] | ||
default_value = getattr(config, config_name) | ||
|
||
instance.setdefault(property, default_value) | ||
|
||
for error in validate_properties( | ||
validator, | ||
properties, | ||
instance, | ||
schema, | ||
): | ||
yield error | ||
|
||
return validators.extend( | ||
validator_class, | ||
{"properties": set_defaults}, | ||
) | ||
|
||
|
||
DefaultValidatingValidator = extend_with_default(Draft202012Validator) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.