diff --git a/frigate/api/classification.py b/frigate/api/classification.py index 9ddce4e3e..7961a8e82 100644 --- a/frigate/api/classification.py +++ b/frigate/api/classification.py @@ -772,28 +772,19 @@ def delete_classification_train_images(request: Request, name: str, body: dict = ) async def generate_state_examples(request: Request, body: GenerateStateExamplesBody): """Generate examples for state classification.""" - try: - cameras_normalized = { - camera_name: tuple(crop) - for camera_name, crop in body.cameras.items() - if camera_name in request.app.frigate_config.cameras - } + model_name = sanitize_filename(body.model_name) + cameras_normalized = { + camera_name: tuple(crop) + for camera_name, crop in body.cameras.items() + if camera_name in request.app.frigate_config.cameras + } - collect_state_classification_examples(body.model_name, cameras_normalized) + collect_state_classification_examples(model_name, cameras_normalized) - return JSONResponse( - content={"success": True, "message": "Example generation completed"}, - status_code=200, - ) - except Exception as e: - logger.error(f"Failed to generate state examples: {e}") - return JSONResponse( - content={ - "success": False, - "message": f"Failed to generate examples: {str(e)}", - }, - status_code=500, - ) + return JSONResponse( + content={"success": True, "message": "Example generation completed"}, + status_code=200, + ) @router.post( @@ -804,19 +795,10 @@ async def generate_state_examples(request: Request, body: GenerateStateExamplesB ) async def generate_object_examples(request: Request, body: GenerateObjectExamplesBody): """Generate examples for object classification.""" - try: - collect_object_classification_examples(body.model_name, body.label) + model_name = sanitize_filename(body.model_name) + collect_object_classification_examples(model_name, body.label) - return JSONResponse( - content={"success": True, "message": "Example generation completed"}, - status_code=200, - ) - except Exception as e: - logger.error(f"Failed to generate object examples: {e}") - return JSONResponse( - content={ - "success": False, - "message": f"Failed to generate examples: {str(e)}", - }, - status_code=500, - ) + return JSONResponse( + content={"success": True, "message": "Example generation completed"}, + status_code=200, + ) diff --git a/frigate/api/defs/request/classification_body.py b/frigate/api/defs/request/classification_body.py index d38ba4b0f..fb6a7dd0f 100644 --- a/frigate/api/defs/request/classification_body.py +++ b/frigate/api/defs/request/classification_body.py @@ -4,11 +4,11 @@ from pydantic import BaseModel, Field class RenameFaceBody(BaseModel): - new_name: str + new_name: str = Field(description="New name for the face") class AudioTranscriptionBody(BaseModel): - event_id: str + event_id: str = Field(description="ID of the event to transcribe audio for") class DeleteFaceImagesBody(BaseModel): @@ -18,12 +18,14 @@ class DeleteFaceImagesBody(BaseModel): class GenerateStateExamplesBody(BaseModel): - model_name: str + model_name: str = Field(description="Name of the classification model") cameras: Dict[str, Tuple[float, float, float, float]] = Field( - description="Dictionary mapping camera names to crop coordinates (x, y, width, height) normalized 0-1" + description="Dictionary mapping camera names to normalized crop coordinates in [x1, y1, x2, y2] format (values 0-1)" ) class GenerateObjectExamplesBody(BaseModel): - model_name: str - label: str + model_name: str = Field(description="Name of the classification model") + label: str = Field( + description="Object label to collect examples for (e.g., 'person', 'car')" + )