You've already forked DataMate
LSF
This commit is contained in:
@@ -2,9 +2,10 @@ from fastapi import APIRouter
|
||||
|
||||
from .config import router as about_router
|
||||
from .project import router as project_router
|
||||
from .task import router as task_router
|
||||
from .template import router as template_router
|
||||
from .auto import router as auto_router
|
||||
from .task import router as task_router
|
||||
from .template import router as template_router
|
||||
from .auto import router as auto_router
|
||||
from .editor import router as editor_router
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/annotation",
|
||||
@@ -13,6 +14,7 @@ router = APIRouter(
|
||||
|
||||
router.include_router(about_router)
|
||||
router.include_router(project_router)
|
||||
router.include_router(task_router)
|
||||
router.include_router(template_router)
|
||||
router.include_router(auto_router)
|
||||
router.include_router(task_router)
|
||||
router.include_router(template_router)
|
||||
router.include_router(auto_router)
|
||||
router.include_router(editor_router)
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
"""
|
||||
Label Studio Editor(前端嵌入式)接口
|
||||
|
||||
说明:
|
||||
- 不依赖 Label Studio Server;仅复用其“编辑器”前端库
|
||||
- DataMate 负责提供 tasks/annotations 数据与保存能力
|
||||
- 当前为 TEXT POC:只支持 dataset_type=TEXT 的项目
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from fastapi import APIRouter, Depends, Query, Path
|
||||
from sqlalchemy.ext.asyncio import AsyncSession
|
||||
|
||||
from app.core.logging import get_logger
|
||||
from app.db.session import get_db
|
||||
from app.module.annotation.schema.editor import (
|
||||
EditorProjectInfo,
|
||||
EditorTaskListResponse,
|
||||
EditorTaskResponse,
|
||||
UpsertAnnotationRequest,
|
||||
UpsertAnnotationResponse,
|
||||
)
|
||||
from app.module.annotation.service.editor import AnnotationEditorService
|
||||
from app.module.shared.schema import StandardResponse
|
||||
|
||||
logger = get_logger(__name__)
|
||||
|
||||
router = APIRouter(
|
||||
prefix="/editor",
|
||||
tags=["annotation/editor"],
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/projects/{project_id}",
|
||||
response_model=StandardResponse[EditorProjectInfo],
|
||||
)
|
||||
async def get_editor_project_info(
|
||||
project_id: str = Path(..., description="标注项目ID(t_dm_labeling_projects.id)"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
service = AnnotationEditorService(db)
|
||||
info = await service.get_project_info(project_id)
|
||||
return StandardResponse(code=200, message="success", data=info)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/projects/{project_id}/tasks",
|
||||
response_model=StandardResponse[EditorTaskListResponse],
|
||||
)
|
||||
async def list_editor_tasks(
|
||||
project_id: str = Path(..., description="标注项目ID(t_dm_labeling_projects.id)"),
|
||||
page: int = Query(0, ge=0, description="页码(从0开始)"),
|
||||
size: int = Query(50, ge=1, le=200, description="每页大小"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
service = AnnotationEditorService(db)
|
||||
result = await service.list_tasks(project_id, page=page, size=size)
|
||||
return StandardResponse(code=200, message="success", data=result)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/projects/{project_id}/tasks/{file_id}",
|
||||
response_model=StandardResponse[EditorTaskResponse],
|
||||
)
|
||||
async def get_editor_task(
|
||||
project_id: str = Path(..., description="标注项目ID(t_dm_labeling_projects.id)"),
|
||||
file_id: str = Path(..., description="文件ID(t_dm_dataset_files.id)"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
service = AnnotationEditorService(db)
|
||||
task = await service.get_task(project_id, file_id)
|
||||
return StandardResponse(code=200, message="success", data=task)
|
||||
|
||||
|
||||
@router.put(
|
||||
"/projects/{project_id}/tasks/{file_id}/annotation",
|
||||
response_model=StandardResponse[UpsertAnnotationResponse],
|
||||
)
|
||||
async def upsert_editor_annotation(
|
||||
request: UpsertAnnotationRequest,
|
||||
project_id: str = Path(..., description="标注项目ID(t_dm_labeling_projects.id)"),
|
||||
file_id: str = Path(..., description="文件ID(t_dm_dataset_files.id)"),
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
service = AnnotationEditorService(db)
|
||||
result = await service.upsert_annotation(project_id, file_id, request)
|
||||
return StandardResponse(code=200, message="success", data=result)
|
||||
|
||||
Reference in New Issue
Block a user