You've already forked DataMate
* feat: Enhance annotation module with template management and validation - Added DatasetMappingCreateRequest and DatasetMappingUpdateRequest schemas to handle dataset mapping requests with camelCase and snake_case support. - Introduced Annotation Template schemas including CreateAnnotationTemplateRequest, UpdateAnnotationTemplateRequest, and AnnotationTemplateResponse for managing annotation templates. - Implemented AnnotationTemplateService for creating, updating, retrieving, and deleting annotation templates, including validation of configurations and XML generation. - Added utility class LabelStudioConfigValidator for validating Label Studio configurations and XML formats. - Updated database schema for annotation templates and labeling projects to include new fields and constraints. - Seeded initial annotation templates for various use cases including image classification, object detection, and text classification. * feat: Enhance TemplateForm with improved validation and dynamic field rendering; update LabelStudio config validation for camelCase support * feat: Update docker-compose.yml to mark datamate dataset volume and network as external * feat: Add tag configuration management and related components - Introduced new components for tag selection and browsing in the frontend. - Added API endpoint to fetch tag configuration from the backend. - Implemented tag configuration management in the backend, including loading from YAML. - Enhanced template service to support dynamic tag rendering based on configuration. - Updated validation utilities to incorporate tag configuration checks. - Refactored existing code to utilize the new tag configuration structure. * feat: Refactor LabelStudioTagConfig for improved configuration loading and validation * feat: Update Makefile to include backend-python-docker-build in the build process * feat: Migrate to poetry for better deps management * Add pyyaml dependency and update Dockerfile to use Poetry for dependency management - Added pyyaml (>=6.0.3,<7.0.0) to pyproject.toml dependencies. - Updated Dockerfile to install Poetry and manage dependencies using it. - Improved layer caching by copying only dependency files before the application code. - Removed unnecessary installation of build dependencies to keep the final image size small. * feat: Remove duplicated backend-python-docker-build target from Makefile * fix: airflow is not ready for adding yet * feat: update Python version to 3.12 and remove project installation step in Dockerfile
94 lines
4.5 KiB
Python
94 lines
4.5 KiB
Python
"""
|
|
Annotation Template Schemas
|
|
"""
|
|
from typing import List, Dict, Any, Optional
|
|
from datetime import datetime
|
|
from pydantic import BaseModel, Field, ConfigDict
|
|
|
|
|
|
class LabelDefinition(BaseModel):
|
|
"""标签定义"""
|
|
from_name: str = Field(alias="fromName", description="控件名称")
|
|
to_name: str = Field(alias="toName", description="目标对象名称")
|
|
type: str = Field(description="控件类型: choices/rectanglelabels/polygonlabels/textarea/etc")
|
|
options: Optional[List[str]] = Field(None, description="选项列表(用于choices类型)")
|
|
labels: Optional[List[str]] = Field(None, description="标签列表(用于rectanglelabels等类型)")
|
|
required: bool = Field(False, description="是否必填")
|
|
description: Optional[str] = Field(None, description="标签描述")
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
class ObjectDefinition(BaseModel):
|
|
"""对象定义"""
|
|
name: str = Field(description="对象标识符")
|
|
type: str = Field(description="对象类型: Image/Text/Audio/Video/etc")
|
|
value: str = Field(description="变量名,如$image")
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
class TemplateConfiguration(BaseModel):
|
|
"""模板配置结构"""
|
|
labels: List[LabelDefinition] = Field(description="标签定义列表")
|
|
objects: List[ObjectDefinition] = Field(description="对象定义列表")
|
|
metadata: Optional[Dict[str, Any]] = Field(None, description="额外元数据")
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
class CreateAnnotationTemplateRequest(BaseModel):
|
|
"""创建标注模板请求"""
|
|
name: str = Field(..., min_length=1, max_length=100, description="模板名称")
|
|
description: Optional[str] = Field(None, max_length=500, description="模板描述")
|
|
data_type: str = Field(alias="dataType", description="数据类型")
|
|
labeling_type: str = Field(alias="labelingType", description="标注类型")
|
|
configuration: TemplateConfiguration = Field(..., description="标注配置")
|
|
style: str = Field(default="horizontal", description="样式配置")
|
|
category: str = Field(default="custom", description="模板分类")
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
class UpdateAnnotationTemplateRequest(BaseModel):
|
|
"""更新标注模板请求"""
|
|
name: Optional[str] = Field(None, min_length=1, max_length=100, description="模板名称")
|
|
description: Optional[str] = Field(None, max_length=500, description="模板描述")
|
|
data_type: Optional[str] = Field(None, alias="dataType", description="数据类型")
|
|
labeling_type: Optional[str] = Field(None, alias="labelingType", description="标注类型")
|
|
configuration: Optional[TemplateConfiguration] = Field(None, description="标注配置")
|
|
style: Optional[str] = Field(None, description="样式配置")
|
|
category: Optional[str] = Field(None, description="模板分类")
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|
|
|
|
|
|
class AnnotationTemplateResponse(BaseModel):
|
|
"""标注模板响应"""
|
|
id: str = Field(..., description="模板ID")
|
|
name: str = Field(..., description="模板名称")
|
|
description: Optional[str] = Field(None, description="模板描述")
|
|
data_type: str = Field(alias="dataType", description="数据类型")
|
|
labeling_type: str = Field(alias="labelingType", description="标注类型")
|
|
configuration: TemplateConfiguration = Field(..., description="标注配置")
|
|
label_config: Optional[str] = Field(None, alias="labelConfig", description="生成的Label Studio XML配置")
|
|
style: str = Field(..., description="样式配置")
|
|
category: str = Field(..., description="模板分类")
|
|
built_in: bool = Field(alias="builtIn", description="是否内置模板")
|
|
version: str = Field(..., description="版本号")
|
|
created_at: datetime = Field(alias="createdAt", description="创建时间")
|
|
updated_at: Optional[datetime] = Field(None, alias="updatedAt", description="更新时间")
|
|
|
|
model_config = ConfigDict(populate_by_name=True, from_attributes=True)
|
|
|
|
|
|
class AnnotationTemplateListResponse(BaseModel):
|
|
"""模板列表响应"""
|
|
content: List[AnnotationTemplateResponse] = Field(..., description="模板列表")
|
|
total: int = Field(..., description="总数")
|
|
page: int = Field(..., description="当前页")
|
|
size: int = Field(..., description="每页大小")
|
|
total_pages: int = Field(alias="totalPages", description="总页数")
|
|
|
|
model_config = ConfigDict(populate_by_name=True)
|