2025-02-26 08:58:25 -06:00
from enum import Enum
2026-03-08 09:55:00 -06:00
from typing import Dict , List , Optional , Union
2024-09-28 22:21:42 +03:00
2026-03-30 08:34:54 -05:00
from pydantic import ConfigDict , Field , field_validator
2024-09-28 22:21:42 +03:00
from .base import FrigateBaseModel
2024-10-26 12:07:45 -05:00
__all__ = [
2025-03-19 09:02:40 -06:00
"CameraFaceRecognitionConfig" ,
"CameraLicensePlateRecognitionConfig" ,
2025-10-08 18:06:03 -05:00
"CameraAudioTranscriptionConfig" ,
2024-10-26 12:07:45 -05:00
"FaceRecognitionConfig" ,
"SemanticSearchConfig" ,
2025-07-07 09:03:57 -05:00
"CameraSemanticSearchConfig" ,
2024-10-26 12:07:45 -05:00
"LicensePlateRecognitionConfig" ,
]
2024-10-22 16:05:48 -06:00
2025-02-26 08:58:25 -06:00
class SemanticSearchModelEnum ( str , Enum ):
jinav1 = "jinav1"
jinav2 = "jinav2"
2025-05-27 10:26:00 -05:00
class EnrichmentsDeviceEnum ( str , Enum ):
2025-04-07 20:30:08 -05:00
GPU = "GPU"
CPU = "CPU"
2025-07-07 09:03:57 -05:00
class TriggerType ( str , Enum ):
THUMBNAIL = "thumbnail"
DESCRIPTION = "description"
class TriggerAction ( str , Enum ):
NOTIFICATION = "notification"
2025-10-28 16:13:04 -05:00
SUB_LABEL = "sub_label"
ATTRIBUTE = "attribute"
2025-07-07 09:03:57 -05:00
2025-07-18 08:28:02 -06:00
class ObjectClassificationType ( str , Enum ):
sub_label = "sub_label"
attribute = "attribute"
2025-05-27 10:26:00 -05:00
class AudioTranscriptionConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable audio transcription" ,
description = "Enable or disable automatic audio transcription for all cameras; can be overridden per-camera." ,
)
2025-05-27 10:26:00 -05:00
language : str = Field (
default = "en" ,
2026-02-27 09:55:36 -06:00
title = "Transcription language" ,
description = "Language code used for transcription/translation (for example 'en' for English). See https://whisper-api.com/docs/languages/ for supported language codes." ,
2025-05-27 10:26:00 -05:00
)
device : Optional [ EnrichmentsDeviceEnum ] = Field (
default = EnrichmentsDeviceEnum . CPU ,
2026-02-27 09:55:36 -06:00
title = "Transcription device" ,
description = "Device key (CPU/GPU) to run the transcription model on. Only NVIDIA CUDA GPUs are currently supported for transcription." ,
2025-05-27 10:26:00 -05:00
)
model_size : str = Field (
2026-02-27 09:55:36 -06:00
default = "small" ,
title = "Model size" ,
description = "Model size to use for offline audio event transcription." ,
2025-05-27 10:26:00 -05:00
)
live_enabled : Optional [ bool ] = Field (
2026-02-27 09:55:36 -06:00
default = False ,
title = "Live transcription" ,
description = "Enable streaming live transcription for audio as it is received." ,
2025-05-27 10:26:00 -05:00
)
2025-01-13 08:09:04 -07:00
class BirdClassificationConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Bird classification" ,
description = "Enable or disable bird classification." ,
)
2025-01-13 08:09:04 -07:00
threshold : float = Field (
default = 0.9 ,
2026-02-27 09:55:36 -06:00
title = "Minimum score" ,
description = "Minimum classification score required to accept a bird classification." ,
2025-01-13 08:09:04 -07:00
gt = 0.0 ,
le = 1.0 ,
)
2025-05-23 08:46:53 -06:00
class CustomClassificationStateCameraConfig ( FrigateBaseModel ):
2025-10-22 07:36:09 -06:00
crop : list [ float , float , float , float ] = Field (
2026-02-27 09:55:36 -06:00
title = "Classification crop" ,
description = "Crop coordinates to use for running classification on this camera." ,
2025-05-23 08:46:53 -06:00
)
class CustomClassificationStateConfig ( FrigateBaseModel ):
cameras : Dict [ str , CustomClassificationStateCameraConfig ] = Field (
2026-02-27 09:55:36 -06:00
title = "Classification cameras" ,
description = "Per-camera crop and settings for running state classification." ,
2025-05-23 08:46:53 -06:00
)
2025-05-24 10:18:46 -06:00
motion : bool = Field (
default = False ,
2026-02-27 09:55:36 -06:00
title = "Run on motion" ,
description = "If true, run classification when motion is detected within the specified crop." ,
2025-05-24 10:18:46 -06:00
)
interval : int | None = Field (
default = None ,
2026-02-27 09:55:36 -06:00
title = "Classification interval" ,
description = "Interval (seconds) between periodic classification runs for state classification." ,
2025-05-24 10:18:46 -06:00
gt = 0 ,
)
2025-05-23 08:46:53 -06:00
class CustomClassificationObjectConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
objects : list [ str ] = Field (
default_factory = list ,
title = "Classify objects" ,
description = "List of object types to run object classification on." ,
)
2025-07-18 08:28:02 -06:00
classification_type : ObjectClassificationType = Field (
default = ObjectClassificationType . sub_label ,
2026-02-27 09:55:36 -06:00
title = "Classification type" ,
description = "Classification type applied: 'sub_label' (adds sub_label) or other supported types." ,
2025-07-18 08:28:02 -06:00
)
2025-05-23 08:46:53 -06:00
class CustomClassificationConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = True ,
title = "Enable model" ,
description = "Enable or disable the custom classification model." ,
)
name : str | None = Field (
default = None ,
title = "Model name" ,
description = "Identifier for the custom classification model to use." ,
)
2025-06-27 08:35:02 -06:00
threshold : float = Field (
2026-02-27 09:55:36 -06:00
default = 0.8 ,
title = "Score threshold" ,
description = "Score threshold used to change the classification state." ,
2025-06-27 08:35:02 -06:00
)
2025-12-02 08:21:15 -06:00
save_attempts : int | None = Field (
default = None ,
2026-02-27 09:55:36 -06:00
title = "Save attempts" ,
description = "How many classification attempts to save for recent classifications UI." ,
2025-12-02 08:21:15 -06:00
ge = 0 ,
)
2025-05-23 08:46:53 -06:00
object_config : CustomClassificationObjectConfig | None = Field ( default = None )
state_config : CustomClassificationStateConfig | None = Field ( default = None )
2025-01-13 08:09:04 -07:00
class ClassificationConfig ( FrigateBaseModel ):
bird : BirdClassificationConfig = Field (
2026-02-27 09:55:36 -06:00
default_factory = BirdClassificationConfig ,
title = "Bird classification config" ,
description = "Settings specific to bird classification models." ,
2025-01-13 08:09:04 -07:00
)
2025-05-23 08:46:53 -06:00
custom : Dict [ str , CustomClassificationConfig ] = Field (
2026-02-27 09:55:36 -06:00
default = {},
title = "Custom Classification Models" ,
description = "Configuration for custom classification models used for objects or state detection." ,
2025-05-23 08:46:53 -06:00
)
2025-01-13 08:09:04 -07:00
2024-10-23 09:03:18 -06:00
class SemanticSearchConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable semantic search" ,
description = "Enable or disable the semantic search feature." ,
)
2024-10-23 09:03:18 -06:00
reindex : Optional [ bool ] = Field (
2026-02-27 09:55:36 -06:00
default = False ,
title = "Reindex on startup" ,
description = "Trigger a full reindex of historical tracked objects into the embeddings database." ,
2025-02-26 08:58:25 -06:00
)
2026-03-08 09:55:00 -06:00
model : Optional [ Union [ SemanticSearchModelEnum , str ]] = Field (
2025-02-26 08:58:25 -06:00
default = SemanticSearchModelEnum . jinav1 ,
2026-03-08 09:55:00 -06:00
title = "Semantic search model or GenAI provider name" ,
description = "The embeddings model to use for semantic search (for example 'jinav1'), or the name of a GenAI provider with the embeddings role." ,
2024-10-23 09:03:18 -06:00
)
2026-03-30 08:34:54 -05:00
@field_validator ( "model" , mode = "before" )
@classmethod
def coerce_model_enum ( cls , v ):
if isinstance ( v , str ):
try :
return SemanticSearchModelEnum ( v )
except ValueError :
return v
return v
2024-10-23 09:03:18 -06:00
model_size : str = Field (
2026-02-27 09:55:36 -06:00
default = "small" ,
title = "Model size" ,
description = "Select model size; 'small' runs on CPU and 'large' typically requires GPU." ,
2024-10-23 09:03:18 -06:00
)
2025-08-18 17:43:53 -06:00
device : Optional [ str ] = Field (
default = None ,
2026-02-27 09:55:36 -06:00
title = "Device" ,
2025-08-18 17:43:53 -06:00
description = "This is an override, to target a specific device. See https://onnxruntime.ai/docs/execution-providers/ for more information" ,
)
2024-10-23 09:03:18 -06:00
2025-07-07 09:03:57 -05:00
class TriggerConfig ( FrigateBaseModel ):
2025-10-03 07:36:14 -05:00
friendly_name : Optional [ str ] = Field (
2026-02-27 09:55:36 -06:00
None ,
title = "Friendly name" ,
description = "Optional friendly name displayed in the UI for this trigger." ,
)
enabled : bool = Field (
default = True ,
title = "Enable this trigger" ,
description = "Enable or disable this semantic search trigger." ,
)
type : TriggerType = Field (
default = TriggerType . DESCRIPTION ,
title = "Trigger type" ,
description = "Type of trigger: 'thumbnail' (match against image) or 'description' (match against text)." ,
)
data : str = Field (
title = "Trigger content" ,
description = "Text phrase or thumbnail ID to match against tracked objects." ,
2025-10-03 07:36:14 -05:00
)
2025-07-07 09:03:57 -05:00
threshold : float = Field (
2026-02-27 09:55:36 -06:00
title = "Trigger threshold" ,
description = "Minimum similarity score (0-1) required to activate this trigger." ,
2025-07-07 09:03:57 -05:00
default = 0.8 ,
gt = 0.0 ,
le = 1.0 ,
)
2025-08-08 06:08:37 -06:00
actions : List [ TriggerAction ] = Field (
2026-02-27 09:55:36 -06:00
default = [],
title = "Trigger actions" ,
description = "List of actions to execute when trigger matches (notification, sub_label, attribute)." ,
2025-07-07 09:03:57 -05:00
)
model_config = ConfigDict ( extra = "forbid" , protected_namespaces = ())
class CameraSemanticSearchConfig ( FrigateBaseModel ):
2025-08-08 06:08:37 -06:00
triggers : Dict [ str , TriggerConfig ] = Field (
default = {},
2026-02-27 09:55:36 -06:00
title = "Triggers" ,
description = "Actions and matching criteria for camera-specific semantic search triggers." ,
2025-07-07 09:03:57 -05:00
)
model_config = ConfigDict ( extra = "forbid" , protected_namespaces = ())
2024-10-22 16:05:48 -06:00
class FaceRecognitionConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable face recognition" ,
description = "Enable or disable face recognition for all cameras; can be overridden per-camera." ,
)
2025-03-25 18:59:03 -06:00
model_size : str = Field (
2026-02-27 09:55:36 -06:00
default = "small" ,
title = "Model size" ,
description = "Model size to use for face embeddings (small/large); larger may require GPU." ,
2025-03-25 18:59:03 -06:00
)
2025-03-26 07:23:01 -06:00
unknown_score : float = Field (
2026-02-27 09:55:36 -06:00
title = "Unknown score threshold" ,
description = "Distance threshold below which a face is considered a potential match (higher = stricter)." ,
2024-12-31 15:56:01 -06:00
default = 0.8 ,
gt = 0.0 ,
le = 1.0 ,
)
2025-03-13 11:22:14 -06:00
detection_threshold : float = Field (
default = 0.7 ,
2026-02-27 09:55:36 -06:00
title = "Detection threshold" ,
description = "Minimum detection confidence required to consider a face detection valid." ,
2025-03-13 11:22:14 -06:00
gt = 0.0 ,
le = 1.0 ,
)
recognition_threshold : float = Field (
2024-12-31 15:56:01 -06:00
default = 0.9 ,
2026-02-27 09:55:36 -06:00
title = "Recognition threshold" ,
description = "Face embedding distance threshold to consider two faces a match." ,
2024-11-26 13:41:49 -07:00
gt = 0.0 ,
le = 1.0 ,
2024-10-22 16:05:48 -06:00
)
min_area : int = Field (
2026-02-27 09:55:36 -06:00
default = 750 ,
title = "Minimum face area" ,
description = "Minimum area (pixels) of a detected face box required to attempt recognition." ,
2024-10-22 16:05:48 -06:00
)
2025-05-18 06:20:59 -06:00
min_faces : int = Field (
default = 1 ,
gt = 0 ,
le = 6 ,
2026-02-27 09:55:36 -06:00
title = "Minimum faces" ,
description = "Minimum number of face recognitions required before applying a recognized sub-label to a person." ,
2025-05-18 06:20:59 -06:00
)
2025-03-19 09:02:25 -06:00
save_attempts : int = Field (
2025-10-22 07:36:09 -06:00
default = 200 ,
ge = 0 ,
2026-02-27 09:55:36 -06:00
title = "Save attempts" ,
description = "Number of face recognition attempts to retain for recent recognition UI." ,
2024-12-25 20:52:35 -06:00
)
2025-03-11 13:18:43 -06:00
blur_confidence_filter : bool = Field (
2026-02-27 09:55:36 -06:00
default = True ,
title = "Blur confidence filter" ,
description = "Adjust confidence scores based on image blur to reduce false positives for poor quality faces." ,
2025-03-11 13:18:43 -06:00
)
2025-08-18 17:43:53 -06:00
device : Optional [ str ] = Field (
default = None ,
2026-02-27 09:55:36 -06:00
title = "Device" ,
2025-08-18 17:43:53 -06:00
description = "This is an override, to target a specific device. See https://onnxruntime.ai/docs/execution-providers/ for more information" ,
)
2024-10-26 12:07:45 -05:00
2025-03-19 09:02:40 -06:00
class CameraFaceRecognitionConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable face recognition" ,
description = "Enable or disable face recognition." ,
)
2025-03-19 09:02:40 -06:00
min_area : int = Field (
2026-02-27 09:55:36 -06:00
default = 750 ,
title = "Minimum face area" ,
description = "Minimum area (pixels) of a detected face box required to attempt recognition." ,
2025-03-19 09:02:40 -06:00
)
2025-04-24 08:30:10 -05:00
model_config = ConfigDict ( extra = "forbid" , protected_namespaces = ())
2025-03-19 20:52:55 -06:00
2025-03-19 09:02:40 -06:00
2025-09-18 16:12:17 -05:00
class ReplaceRule ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
pattern : str = Field ( ... , title = "Regex pattern" )
replacement : str = Field ( ... , title = "Replacement string" )
2025-09-18 16:12:17 -05:00
2024-10-26 12:07:45 -05:00
class LicensePlateRecognitionConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable LPR" ,
description = "Enable or disable license plate recognition for all cameras; can be overridden per-camera." ,
)
2025-04-15 10:40:12 -05:00
model_size : str = Field (
2026-02-27 09:55:36 -06:00
default = "small" ,
title = "Model size" ,
description = "Model size used for text detection/recognition. Most users should use 'small'." ,
2025-04-15 10:40:12 -05:00
)
2025-02-14 16:12:36 -06:00
detection_threshold : float = Field (
default = 0.7 ,
2026-02-27 09:55:36 -06:00
title = "Detection threshold" ,
description = "Detection confidence threshold to begin running OCR on a suspected plate." ,
2025-02-14 16:12:36 -06:00
gt = 0.0 ,
le = 1.0 ,
2024-10-26 12:07:45 -05:00
)
min_area : int = Field (
2025-02-13 17:08:56 -06:00
default = 1000 ,
2026-02-27 09:55:36 -06:00
title = "Minimum plate area" ,
description = "Minimum plate area (pixels) required to attempt recognition." ,
2025-02-14 16:12:36 -06:00
)
recognition_threshold : float = Field (
default = 0.9 ,
2026-02-27 09:55:36 -06:00
title = "Recognition threshold" ,
description = "Confidence threshold required for recognized plate text to be attached as a sub-label." ,
2025-02-14 16:12:36 -06:00
gt = 0.0 ,
le = 1.0 ,
2025-02-13 17:08:56 -06:00
)
min_plate_length : int = Field (
default = 4 ,
2026-02-27 09:55:36 -06:00
title = "Min plate length" ,
description = "Minimum number of characters a recognized plate must contain to be considered valid." ,
2025-02-13 17:08:56 -06:00
)
2025-02-14 16:12:36 -06:00
format : Optional [ str ] = Field (
default = None ,
2026-02-27 09:55:36 -06:00
title = "Plate format regex" ,
description = "Optional regex to validate recognized plate strings against an expected format." ,
2025-02-14 16:12:36 -06:00
)
2025-02-13 17:08:56 -06:00
match_distance : int = Field (
default = 1 ,
2026-02-27 09:55:36 -06:00
title = "Match distance" ,
description = "Number of character mismatches allowed when comparing detected plates to known plates." ,
2025-02-14 16:12:36 -06:00
ge = 0 ,
2024-10-26 12:07:45 -05:00
)
known_plates : Optional [ Dict [ str , List [ str ]]] = Field (
2026-02-27 09:55:36 -06:00
default = {},
title = "Known plates" ,
description = "List of plates or regexes to specially track or alert on." ,
2024-10-26 12:07:45 -05:00
)
2025-03-28 07:29:11 -05:00
enhancement : int = Field (
default = 0 ,
2026-02-27 09:55:36 -06:00
title = "Enhancement level" ,
description = "Enhancement level (0-10) to apply to plate crops prior to OCR; higher values may not always improve results, levels above 5 may only work with night time plates and should be used with caution." ,
2025-03-28 07:29:11 -05:00
ge = 0 ,
le = 10 ,
)
debug_save_plates : bool = Field (
default = False ,
2026-02-27 09:55:36 -06:00
title = "Save debug plates" ,
description = "Save plate crop images for debugging LPR performance." ,
2025-03-28 07:29:11 -05:00
)
2025-08-18 17:43:53 -06:00
device : Optional [ str ] = Field (
default = None ,
2026-02-27 09:55:36 -06:00
title = "Device" ,
2025-08-18 17:43:53 -06:00
description = "This is an override, to target a specific device. See https://onnxruntime.ai/docs/execution-providers/ for more information" ,
)
2025-09-18 16:12:17 -05:00
replace_rules : List [ ReplaceRule ] = Field (
default_factory = list ,
2026-02-27 09:55:36 -06:00
title = "Replacement rules" ,
description = "Regex replacement rules used to normalize detected plate strings before matching." ,
2025-09-18 16:12:17 -05:00
)
2025-03-19 09:02:40 -06:00
class CameraLicensePlateRecognitionConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable LPR" ,
description = "Enable or disable LPR on this camera." ,
)
2025-03-23 14:30:48 -05:00
expire_time : int = Field (
default = 3 ,
2026-02-27 09:55:36 -06:00
title = "Expire seconds" ,
description = "Time in seconds after which an unseen plate is expired from the tracker (for dedicated LPR cameras only)." ,
2025-03-23 14:30:48 -05:00
gt = 0 ,
)
2025-03-19 09:02:40 -06:00
min_area : int = Field (
default = 1000 ,
2026-02-27 09:55:36 -06:00
title = "Minimum plate area" ,
description = "Minimum plate area (pixels) required to attempt recognition." ,
2025-03-19 09:02:40 -06:00
)
2025-03-28 07:29:11 -05:00
enhancement : int = Field (
default = 0 ,
2026-02-27 09:55:36 -06:00
title = "Enhancement level" ,
description = "Enhancement level (0-10) to apply to plate crops prior to OCR; higher values may not always improve results, levels above 5 may only work with night time plates and should be used with caution." ,
2025-03-28 07:29:11 -05:00
ge = 0 ,
le = 10 ,
)
2025-03-19 20:52:55 -06:00
2025-04-24 08:30:10 -05:00
model_config = ConfigDict ( extra = "forbid" , protected_namespaces = ())
2025-10-08 18:06:03 -05:00
class CameraAudioTranscriptionConfig ( FrigateBaseModel ):
2026-02-27 09:55:36 -06:00
enabled : bool = Field (
default = False ,
title = "Enable transcription" ,
description = "Enable or disable manually triggered audio event transcription." ,
)
2025-10-08 18:06:03 -05:00
enabled_in_config : Optional [ bool ] = Field (
2026-02-27 09:55:36 -06:00
default = None , title = "Original transcription state"
2025-10-08 18:06:03 -05:00
)
live_enabled : Optional [ bool ] = Field (
2026-02-27 09:55:36 -06:00
default = False ,
title = "Live transcription" ,
description = "Enable streaming live transcription for audio as it is received." ,
2025-10-08 18:06:03 -05:00
)
model_config = ConfigDict ( extra = "forbid" , protected_namespaces = ())