yolo-mcp 2.0.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- yolo_mcp-2.0.0/.env.example +15 -0
- yolo_mcp-2.0.0/.flake8 +7 -0
- yolo_mcp-2.0.0/.gitignore +45 -0
- yolo_mcp-2.0.0/LICENSE +203 -0
- yolo_mcp-2.0.0/PKG-INFO +92 -0
- yolo_mcp-2.0.0/README.md +47 -0
- yolo_mcp-2.0.0/__init__.py +0 -0
- yolo_mcp-2.0.0/adapter/__init__.py +0 -0
- yolo_mcp-2.0.0/adapter/persistence/crud_attachment.py +92 -0
- yolo_mcp-2.0.0/adapter/persistence/crud_auto_label_job.py +50 -0
- yolo_mcp-2.0.0/adapter/persistence/crud_pre_annotation.py +67 -0
- yolo_mcp-2.0.0/adapter/persistence/crud_project.py +86 -0
- yolo_mcp-2.0.0/adapter/persistence/crud_sample.py +167 -0
- yolo_mcp-2.0.0/adapter/persistence/crud_user.py +43 -0
- yolo_mcp-2.0.0/adapter/routers/__init__.py +18 -0
- yolo_mcp-2.0.0/adapter/routers/attachment.py +111 -0
- yolo_mcp-2.0.0/adapter/routers/pre_annotation.py +62 -0
- yolo_mcp-2.0.0/adapter/routers/project.py +305 -0
- yolo_mcp-2.0.0/adapter/routers/sample.py +247 -0
- yolo_mcp-2.0.0/adapter/routers/training.py +102 -0
- yolo_mcp-2.0.0/adapter/routers/user.py +189 -0
- yolo_mcp-2.0.0/adapter/ws/__init__.py +9 -0
- yolo_mcp-2.0.0/adapter/ws/sample.py +97 -0
- yolo_mcp-2.0.0/application/__init__.py +0 -0
- yolo_mcp-2.0.0/application/command/__init__.py +0 -0
- yolo_mcp-2.0.0/application/command/attachment.py +14 -0
- yolo_mcp-2.0.0/application/command/project.py +48 -0
- yolo_mcp-2.0.0/application/command/sample.py +38 -0
- yolo_mcp-2.0.0/application/command/training.py +99 -0
- yolo_mcp-2.0.0/application/command/user.py +32 -0
- yolo_mcp-2.0.0/application/response/__init__.py +0 -0
- yolo_mcp-2.0.0/application/response/attachment.py +17 -0
- yolo_mcp-2.0.0/application/response/auto_label.py +36 -0
- yolo_mcp-2.0.0/application/response/base.py +30 -0
- yolo_mcp-2.0.0/application/response/pre_annotation.py +51 -0
- yolo_mcp-2.0.0/application/response/project.py +66 -0
- yolo_mcp-2.0.0/application/response/sample.py +50 -0
- yolo_mcp-2.0.0/application/response/training.py +29 -0
- yolo_mcp-2.0.0/application/response/user.py +36 -0
- yolo_mcp-2.0.0/application/service/access.py +26 -0
- yolo_mcp-2.0.0/application/service/access_token.py +94 -0
- yolo_mcp-2.0.0/application/service/attachment.py +238 -0
- yolo_mcp-2.0.0/application/service/auto_label.py +407 -0
- yolo_mcp-2.0.0/application/service/dataset.py +131 -0
- yolo_mcp-2.0.0/application/service/pre_annotation.py +59 -0
- yolo_mcp-2.0.0/application/service/project.py +497 -0
- yolo_mcp-2.0.0/application/service/sample.py +396 -0
- yolo_mcp-2.0.0/application/service/training.py +436 -0
- yolo_mcp-2.0.0/application/service/user.py +150 -0
- yolo_mcp-2.0.0/clients/__init__.py +0 -0
- yolo_mcp-2.0.0/clients/ws.py +3 -0
- yolo_mcp-2.0.0/common/__init__.py +0 -0
- yolo_mcp-2.0.0/common/config.py +96 -0
- yolo_mcp-2.0.0/common/db.py +50 -0
- yolo_mcp-2.0.0/common/error_code.py +282 -0
- yolo_mcp-2.0.0/common/logger.py +82 -0
- yolo_mcp-2.0.0/common/security.py +65 -0
- yolo_mcp-2.0.0/common/storage.py +154 -0
- yolo_mcp-2.0.0/common/websocket.py +155 -0
- yolo_mcp-2.0.0/dependencies/__init__.py +0 -0
- yolo_mcp-2.0.0/dependencies/user.py +116 -0
- yolo_mcp-2.0.0/domain/models/__init__.py +23 -0
- yolo_mcp-2.0.0/domain/models/access_token.py +21 -0
- yolo_mcp-2.0.0/domain/models/attachment.py +31 -0
- yolo_mcp-2.0.0/domain/models/auto_label_job.py +42 -0
- yolo_mcp-2.0.0/domain/models/pre_annotation.py +48 -0
- yolo_mcp-2.0.0/domain/models/project.py +98 -0
- yolo_mcp-2.0.0/domain/models/project_collaborator.py +22 -0
- yolo_mcp-2.0.0/domain/models/project_sample_updater.py +24 -0
- yolo_mcp-2.0.0/domain/models/sample.py +77 -0
- yolo_mcp-2.0.0/domain/models/training_run.py +40 -0
- yolo_mcp-2.0.0/domain/models/user.py +48 -0
- yolo_mcp-2.0.0/hatch_build.py +32 -0
- yolo_mcp-2.0.0/inference.py +184 -0
- yolo_mcp-2.0.0/main.py +158 -0
- yolo_mcp-2.0.0/mcp_server.py +352 -0
- yolo_mcp-2.0.0/middleware/__init__.py +9 -0
- yolo_mcp-2.0.0/middleware/content_type.py +18 -0
- yolo_mcp-2.0.0/middleware/tracing.py +28 -0
- yolo_mcp-2.0.0/migrations/__init__.py +0 -0
- yolo_mcp-2.0.0/migrations/alembic.ini +44 -0
- yolo_mcp-2.0.0/migrations/env.py +54 -0
- yolo_mcp-2.0.0/migrations/run_migrate.py +26 -0
- yolo_mcp-2.0.0/migrations/script.py.mako +24 -0
- yolo_mcp-2.0.0/migrations/versions/001_init_db.py +604 -0
- yolo_mcp-2.0.0/pyproject.toml +103 -0
- yolo_mcp-2.0.0/statics/__init__.py +0 -0
- yolo_mcp-2.0.0/statics/assets/LOGO-4e6a3212.svg +6 -0
- yolo_mcp-2.0.0/statics/assets/add-category-8e196d2c.svg +10 -0
- yolo_mcp-2.0.0/statics/assets/add-text-5d733ee2.svg +6 -0
- yolo_mcp-2.0.0/statics/assets/arrow-2034a73f.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/arrow-df71379f.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/arrow-down-572408f5.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/arrow-down-a0f00ee6.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/arrow-right-c32c7dd7.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/arrow-up-7a7e6c3e.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/brightness-3cad39d2.svg +4 -0
- yolo_mcp-2.0.0/statics/assets/check-5501abaf.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/close-8d0bcd49.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/contrast-e6f4bad1.svg +4 -0
- yolo_mcp-2.0.0/statics/assets/create-project-fb881c2b.svg +22 -0
- yolo_mcp-2.0.0/statics/assets/cuboid-d0ce208f.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/cursor-038b3df5.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/cursor-frame-4f4c2ebe.svg +37 -0
- yolo_mcp-2.0.0/statics/assets/cursor-segment-5fccd2b9.svg +23 -0
- yolo_mcp-2.0.0/statics/assets/delete-ec425f1a.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/delete-f8082aca.svg +10 -0
- yolo_mcp-2.0.0/statics/assets/edit-8ee5f66f.svg +5 -0
- yolo_mcp-2.0.0/statics/assets/email-e2d21e5f.svg +4 -0
- yolo_mcp-2.0.0/statics/assets/fit-container-df5302b3.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/frame-2696ab1f.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/i18n-f6c30761.svg +4 -0
- yolo_mcp-2.0.0/statics/assets/index-20f3956a.js +3648 -0
- yolo_mcp-2.0.0/statics/assets/index-3953b85f.css +1 -0
- yolo_mcp-2.0.0/statics/assets/labelllm-b386607b.svg +11 -0
- yolo_mcp-2.0.0/statics/assets/line-114599e2.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/local-deploy-9489fc1b.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/menu-close-5b2fc796.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/menu-open-0d5dd166.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/mineru-7df2fd51.svg +36 -0
- yolo_mcp-2.0.0/statics/assets/mouse-left-ed85215d.svg +11 -0
- yolo_mcp-2.0.0/statics/assets/mouse-right-230f35cf.svg +18 -0
- yolo_mcp-2.0.0/statics/assets/not-found-56207eaf.svg +12 -0
- yolo_mcp-2.0.0/statics/assets/opacity-fill-4d28187f.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/opacity-stroke-35024f94.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/opendatalab-a71cb491.svg +12 -0
- yolo_mcp-2.0.0/statics/assets/password-b56a5e39.svg +5 -0
- yolo_mcp-2.0.0/statics/assets/pause-2c37ce0d.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/pin-587a3437.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/play-68b6f28e.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/play-a443cb29.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/point-e5e8ee7c.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/polygon-5b439d28.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/polygon-clipping.esm-f0d86bd5.js +2 -0
- yolo_mcp-2.0.0/statics/assets/rect-603e68ca.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/redo-110cc0fa.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/relation-28e7f9b8.svg +5 -0
- yolo_mcp-2.0.0/statics/assets/rotate-7b7e0020.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/saturation-c2801c68.svg +4 -0
- yolo_mcp-2.0.0/statics/assets/scale-reset-0a4bcee0.svg +5 -0
- yolo_mcp-2.0.0/statics/assets/segment-24805bb6.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/setting-7457fac5.svg +4 -0
- yolo_mcp-2.0.0/statics/assets/spark-13b9fa69.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/stroke-width-93455f8d.svg +31 -0
- yolo_mcp-2.0.0/statics/assets/toolbox-3e62683e.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/tree-switcher-de1b8445.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/undo-8b9350e1.svg +3 -0
- yolo_mcp-2.0.0/statics/assets/unknown-a66cb6e9.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/video-error-76105e19.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/video.es-3f0a61ef.js +228 -0
- yolo_mcp-2.0.0/statics/assets/videoError-7854035e.svg +80 -0
- yolo_mcp-2.0.0/statics/assets/visibility-ad1804cb.svg +1 -0
- yolo_mcp-2.0.0/statics/assets/visibility-off-700caeee.svg +1 -0
- yolo_mcp-2.0.0/statics/backend_version.js +6 -0
- yolo_mcp-2.0.0/statics/favicon.svg +5 -0
- yolo_mcp-2.0.0/statics/frontend_version.js +16 -0
- yolo_mcp-2.0.0/statics/index.html +49 -0
- yolo_mcp-2.0.0/statics/logo192.png +0 -0
- yolo_mcp-2.0.0/statics/logo512.png +0 -0
- yolo_mcp-2.0.0/statics/manifest.json +25 -0
- yolo_mcp-2.0.0/statics/robots.txt +3 -0
- yolo_mcp-2.0.0/tests/__init__.py +0 -0
- yolo_mcp-2.0.0/tests/adapter/__init__.py +0 -0
- yolo_mcp-2.0.0/tests/adapter/persistence/test_crud_sample.py +113 -0
- yolo_mcp-2.0.0/tests/adapter/persistence/test_crud_user.py +44 -0
- yolo_mcp-2.0.0/tests/adapter/routers/__init__.py +0 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_attachment.py +242 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_auto_label.py +333 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_dataset.py +289 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_permissions.py +538 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_project.py +678 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_sample.py +978 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_training.py +558 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_training_cleanup.py +165 -0
- yolo_mcp-2.0.0/tests/adapter/routers/test_user.py +188 -0
- yolo_mcp-2.0.0/tests/application/__init__.py +0 -0
- yolo_mcp-2.0.0/tests/application/command/__init__.py +0 -0
- yolo_mcp-2.0.0/tests/common/test_error_code.py +106 -0
- yolo_mcp-2.0.0/tests/common/test_inference.py +100 -0
- yolo_mcp-2.0.0/tests/common/test_mcp_client.py +224 -0
- yolo_mcp-2.0.0/tests/common/test_migrations.py +337 -0
- yolo_mcp-2.0.0/tests/common/test_security.py +87 -0
- yolo_mcp-2.0.0/tests/common/test_storage.py +84 -0
- yolo_mcp-2.0.0/tests/common/test_training.py +230 -0
- yolo_mcp-2.0.0/tests/conftest.py +268 -0
- yolo_mcp-2.0.0/tests/data/test.jsonl +1 -0
- yolo_mcp-2.0.0/tests/data/test.png +0 -0
- yolo_mcp-2.0.0/tests/data/test.txt +1 -0
- yolo_mcp-2.0.0/tests/utils/__init__.py +0 -0
- yolo_mcp-2.0.0/tests/utils/utils.py +18 -0
- yolo_mcp-2.0.0/training/README.md +85 -0
- yolo_mcp-2.0.0/training/__init__.py +1 -0
- yolo_mcp-2.0.0/training/train.py +521 -0
- yolo_mcp-2.0.0/uv.lock +3352 -0
- yolo_mcp-2.0.0/version.py +1 -0
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# 默认数据目录为用户主目录下的 .yolo-mcp,可按需覆盖。
|
|
2
|
+
# DATA_DIR=~/.yolo-mcp
|
|
3
|
+
|
|
4
|
+
# 默认 SQLite 位于 DATA_DIR/labels.sqlite,可按需指定其他数据库。
|
|
5
|
+
# DATABASE_URL=sqlite:///your/custom/labels.sqlite
|
|
6
|
+
|
|
7
|
+
# 签名密钥首次启动时自动生成到 DATA_DIR/secret.key,后续启动复用。
|
|
8
|
+
|
|
9
|
+
# AI 和页面训练复用当前 Python 的 GPU 环境;留空自动选择设备。
|
|
10
|
+
USE_AUTO_LABEL=true
|
|
11
|
+
DEVICE=
|
|
12
|
+
|
|
13
|
+
# MCP 默认只接受本机地址。远程部署时填写实际域名与来源的 JSON 数组。
|
|
14
|
+
# MCP_ALLOWED_HOSTS=["yolo.example.com"]
|
|
15
|
+
# MCP_ALLOWED_ORIGINS=["https://yolo.example.com"]
|
yolo_mcp-2.0.0/.flake8
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# 环境、凭据和本地运行文件。
|
|
2
|
+
.env
|
|
3
|
+
.env.*
|
|
4
|
+
!.env.example
|
|
5
|
+
secret.key
|
|
6
|
+
.venv/
|
|
7
|
+
.venv-*/
|
|
8
|
+
.tmp/
|
|
9
|
+
.cache/
|
|
10
|
+
/data/
|
|
11
|
+
*.sqlite
|
|
12
|
+
*.sqlite-journal
|
|
13
|
+
*.sqlite-wal
|
|
14
|
+
*.sqlite-shm
|
|
15
|
+
*.db
|
|
16
|
+
*.log
|
|
17
|
+
|
|
18
|
+
# Python 与前端依赖、缓存和构建产物。
|
|
19
|
+
__pycache__/
|
|
20
|
+
*.py[cod]
|
|
21
|
+
*.egg-info/
|
|
22
|
+
.pytest_cache/
|
|
23
|
+
.ruff_cache/
|
|
24
|
+
.mypy_cache/
|
|
25
|
+
node_modules/
|
|
26
|
+
dist/
|
|
27
|
+
build/
|
|
28
|
+
coverage/
|
|
29
|
+
*.tsbuildinfo
|
|
30
|
+
|
|
31
|
+
# 模型权重和训练输出保存在本地数据目录,不纳入版本控制。
|
|
32
|
+
*.pt
|
|
33
|
+
*.onnx
|
|
34
|
+
*.engine
|
|
35
|
+
|
|
36
|
+
# 前端静态资源在构建时生成。
|
|
37
|
+
/backend/statics/*
|
|
38
|
+
!/backend/statics/__init__.py
|
|
39
|
+
|
|
40
|
+
.DS_Store
|
|
41
|
+
Thumbs.db
|
|
42
|
+
|
|
43
|
+
# 后端运行数据与训练工作目录。
|
|
44
|
+
/backend/data/
|
|
45
|
+
/backend/workspace/
|
yolo_mcp-2.0.0/LICENSE
ADDED
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
Copyright 2018-2023 OpenMMLab. All rights reserved.
|
|
2
|
+
|
|
3
|
+
Apache License
|
|
4
|
+
Version 2.0, January 2004
|
|
5
|
+
http://www.apache.org/licenses/
|
|
6
|
+
|
|
7
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
8
|
+
|
|
9
|
+
1. Definitions.
|
|
10
|
+
|
|
11
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
12
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
13
|
+
|
|
14
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
15
|
+
the copyright owner that is granting the License.
|
|
16
|
+
|
|
17
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
18
|
+
other entities that control, are controlled by, or are under common
|
|
19
|
+
control with that entity. For the purposes of this definition,
|
|
20
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
21
|
+
direction or management of such entity, whether by contract or
|
|
22
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
23
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
24
|
+
|
|
25
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
26
|
+
exercising permissions granted by this License.
|
|
27
|
+
|
|
28
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
29
|
+
including but not limited to software source code, documentation
|
|
30
|
+
source, and configuration files.
|
|
31
|
+
|
|
32
|
+
"Object" form shall mean any form resulting from mechanical
|
|
33
|
+
transformation or translation of a Source form, including but
|
|
34
|
+
not limited to compiled object code, generated documentation,
|
|
35
|
+
and conversions to other media types.
|
|
36
|
+
|
|
37
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
38
|
+
Object form, made available under the License, as indicated by a
|
|
39
|
+
copyright notice that is included in or attached to the work
|
|
40
|
+
(an example is provided in the Appendix below).
|
|
41
|
+
|
|
42
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
43
|
+
form, that is based on (or derived from) the Work and for which the
|
|
44
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
45
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
46
|
+
of this License, Derivative Works shall not include works that remain
|
|
47
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
48
|
+
the Work and Derivative Works thereof.
|
|
49
|
+
|
|
50
|
+
"Contribution" shall mean any work of authorship, including
|
|
51
|
+
the original version of the Work and any modifications or additions
|
|
52
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
53
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
54
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
55
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
56
|
+
means any form of electronic, verbal, or written communication sent
|
|
57
|
+
to the Licensor or its representatives, including but not limited to
|
|
58
|
+
communication on electronic mailing lists, source code control systems,
|
|
59
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
60
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
61
|
+
excluding communication that is conspicuously marked or otherwise
|
|
62
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
63
|
+
|
|
64
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
65
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
66
|
+
subsequently incorporated within the Work.
|
|
67
|
+
|
|
68
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
69
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
70
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
71
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
72
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
73
|
+
Work and such Derivative Works in Source or Object form.
|
|
74
|
+
|
|
75
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
76
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
77
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
78
|
+
(except as stated in this section) patent license to make, have made,
|
|
79
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
80
|
+
where such license applies only to those patent claims licensable
|
|
81
|
+
by such Contributor that are necessarily infringed by their
|
|
82
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
83
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
84
|
+
institute patent litigation against any entity (including a
|
|
85
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
86
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
87
|
+
or contributory patent infringement, then any patent licenses
|
|
88
|
+
granted to You under this License for that Work shall terminate
|
|
89
|
+
as of the date such litigation is filed.
|
|
90
|
+
|
|
91
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
92
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
93
|
+
modifications, and in Source or Object form, provided that You
|
|
94
|
+
meet the following conditions:
|
|
95
|
+
|
|
96
|
+
(a) You must give any other recipients of the Work or
|
|
97
|
+
Derivative Works a copy of this License; and
|
|
98
|
+
|
|
99
|
+
(b) You must cause any modified files to carry prominent notices
|
|
100
|
+
stating that You changed the files; and
|
|
101
|
+
|
|
102
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
103
|
+
that You distribute, all copyright, patent, trademark, and
|
|
104
|
+
attribution notices from the Source form of the Work,
|
|
105
|
+
excluding those notices that do not pertain to any part of
|
|
106
|
+
the Derivative Works; and
|
|
107
|
+
|
|
108
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
109
|
+
distribution, then any Derivative Works that You distribute must
|
|
110
|
+
include a readable copy of the attribution notices contained
|
|
111
|
+
within such NOTICE file, excluding those notices that do not
|
|
112
|
+
pertain to any part of the Derivative Works, in at least one
|
|
113
|
+
of the following places: within a NOTICE text file distributed
|
|
114
|
+
as part of the Derivative Works; within the Source form or
|
|
115
|
+
documentation, if provided along with the Derivative Works; or,
|
|
116
|
+
within a display generated by the Derivative Works, if and
|
|
117
|
+
wherever such third-party notices normally appear. The contents
|
|
118
|
+
of the NOTICE file are for informational purposes only and
|
|
119
|
+
do not modify the License. You may add Your own attribution
|
|
120
|
+
notices within Derivative Works that You distribute, alongside
|
|
121
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
122
|
+
that such additional attribution notices cannot be construed
|
|
123
|
+
as modifying the License.
|
|
124
|
+
|
|
125
|
+
You may add Your own copyright statement to Your modifications and
|
|
126
|
+
may provide additional or different license terms and conditions
|
|
127
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
128
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
129
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
130
|
+
the conditions stated in this License.
|
|
131
|
+
|
|
132
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
133
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
134
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
135
|
+
this License, without any additional terms or conditions.
|
|
136
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
137
|
+
the terms of any separate license agreement you may have executed
|
|
138
|
+
with Licensor regarding such Contributions.
|
|
139
|
+
|
|
140
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
141
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
142
|
+
except as required for reasonable and customary use in describing the
|
|
143
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
144
|
+
|
|
145
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
146
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
147
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
148
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
149
|
+
implied, including, without limitation, any warranties or conditions
|
|
150
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
151
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
152
|
+
appropriateness of using or redistributing the Work and assume any
|
|
153
|
+
risks associated with Your exercise of permissions under this License.
|
|
154
|
+
|
|
155
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
156
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
157
|
+
unless required by applicable law (such as deliberate and grossly
|
|
158
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
159
|
+
liable to You for damages, including any direct, indirect, special,
|
|
160
|
+
incidental, or consequential damages of any character arising as a
|
|
161
|
+
result of this License or out of the use or inability to use the
|
|
162
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
163
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
164
|
+
other commercial damages or losses), even if such Contributor
|
|
165
|
+
has been advised of the possibility of such damages.
|
|
166
|
+
|
|
167
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
168
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
169
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
170
|
+
or other liability obligations and/or rights consistent with this
|
|
171
|
+
License. However, in accepting such obligations, You may act only
|
|
172
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
173
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
174
|
+
defend, and hold each Contributor harmless for any liability
|
|
175
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
176
|
+
of your accepting any such warranty or additional liability.
|
|
177
|
+
|
|
178
|
+
END OF TERMS AND CONDITIONS
|
|
179
|
+
|
|
180
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
181
|
+
|
|
182
|
+
To apply the Apache License to your work, attach the following
|
|
183
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
184
|
+
replaced with your own identifying information. (Don't include
|
|
185
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
186
|
+
comment syntax for the file format. We also recommend that a
|
|
187
|
+
file or class name and description of purpose be included on the
|
|
188
|
+
same "printed page" as the copyright notice for easier
|
|
189
|
+
identification within third-party archives.
|
|
190
|
+
|
|
191
|
+
Copyright 2018-2023 OpenMMLab.
|
|
192
|
+
|
|
193
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
194
|
+
you may not use this file except in compliance with the License.
|
|
195
|
+
You may obtain a copy of the License at
|
|
196
|
+
|
|
197
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
198
|
+
|
|
199
|
+
Unless required by applicable law or agreed to in writing, software
|
|
200
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
201
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
202
|
+
See the License for the specific language governing permissions and
|
|
203
|
+
limitations under the License.
|
yolo_mcp-2.0.0/PKG-INFO
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: yolo-mcp
|
|
3
|
+
Version: 2.0.0
|
|
4
|
+
Summary: YOLO MCP local image annotation and YOLO training
|
|
5
|
+
Project-URL: repository, https://github.com/killf/LabelS
|
|
6
|
+
Author-email: shenguanlin <shenguanlin@pjlab.org.cn>
|
|
7
|
+
License: Apache-2.0
|
|
8
|
+
License-File: LICENSE
|
|
9
|
+
Requires-Python: >=3.11
|
|
10
|
+
Requires-Dist: aiofiles>=22.1.0
|
|
11
|
+
Requires-Dist: alembic>=1.9.4
|
|
12
|
+
Requires-Dist: bcrypt==4.3.0
|
|
13
|
+
Requires-Dist: click>=8.0
|
|
14
|
+
Requires-Dist: email-validator>=2.0.0
|
|
15
|
+
Requires-Dist: fastapi>=0.100.0
|
|
16
|
+
Requires-Dist: httpx>=0.27.0
|
|
17
|
+
Requires-Dist: loguru>=0.6.0
|
|
18
|
+
Requires-Dist: mcp==2.3.0
|
|
19
|
+
Requires-Dist: pillow>=9.3.0
|
|
20
|
+
Requires-Dist: pydantic-settings>=2.0.0
|
|
21
|
+
Requires-Dist: pydantic>=2.0.0
|
|
22
|
+
Requires-Dist: python-dotenv>=0.21.0
|
|
23
|
+
Requires-Dist: python-jose[cryptography]>=3.3.0
|
|
24
|
+
Requires-Dist: python-multipart>=0.0.5
|
|
25
|
+
Requires-Dist: pyyaml<7,>=6.0
|
|
26
|
+
Requires-Dist: sqlalchemy>=2.0.0
|
|
27
|
+
Requires-Dist: uvicorn>=0.19.0
|
|
28
|
+
Requires-Dist: websockets>=10.0.0
|
|
29
|
+
Provides-Extra: annotation
|
|
30
|
+
Requires-Dist: einops<1,>=0.8; extra == 'annotation'
|
|
31
|
+
Requires-Dist: huggingface-hub<1,>=0.30; extra == 'annotation'
|
|
32
|
+
Requires-Dist: timm<2,>=1; extra == 'annotation'
|
|
33
|
+
Requires-Dist: torch<3,>=2.9; extra == 'annotation'
|
|
34
|
+
Requires-Dist: torchvision<1,>=0.24; extra == 'annotation'
|
|
35
|
+
Requires-Dist: transformers==4.51.3; extra == 'annotation'
|
|
36
|
+
Provides-Extra: mysql
|
|
37
|
+
Requires-Dist: mysqlclient>=2.1.1; extra == 'mysql'
|
|
38
|
+
Provides-Extra: training
|
|
39
|
+
Requires-Dist: pyyaml<7,>=6.0.3; extra == 'training'
|
|
40
|
+
Requires-Dist: torch<3,>=2.9; extra == 'training'
|
|
41
|
+
Requires-Dist: torchvision<1,>=0.24; extra == 'training'
|
|
42
|
+
Requires-Dist: tzdata>=2025.2; extra == 'training'
|
|
43
|
+
Requires-Dist: ultralytics==8.4.203; extra == 'training'
|
|
44
|
+
Description-Content-Type: text/markdown
|
|
45
|
+
|
|
46
|
+
# YOLO MCP 后端
|
|
47
|
+
|
|
48
|
+
本目录是独立 Python 项目,源码包名为 `backend`。业务说明、前端运行和参考项目见[仓库 README](../README.md)。
|
|
49
|
+
|
|
50
|
+
## Web 服务
|
|
51
|
+
|
|
52
|
+
从本目录执行:
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
uv sync --python 3.11 --frozen --group test
|
|
56
|
+
cp .env.example .env
|
|
57
|
+
# 按需调整 DATA_DIR、USE_AUTO_LABEL 和 DEVICE;签名密钥首次启动时自动生成。
|
|
58
|
+
uv run --env-file .env uvicorn backend.main:app --host 127.0.0.1 --port 8002
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
`yolo-mcp` 也是服务 CLI 入口。模块导入和 `--help` 不初始化数据库,实际应用启动时通过 `migrations/versions/001_init_db.py` 初始化空库;默认 SQLite 文件名为 `labels.sqlite`。结构调整后使用新库,旧库不会自动迁移。不提供历史结构升级或 to_mysql。
|
|
62
|
+
|
|
63
|
+
`DATA_DIR` 默认指向用户主目录的 `.yolo-mcp/`。服务首次启动时在此目录生成 `secret.key`,后续启动读取同一密钥;数据库和项目文件也默认保存在此目录。
|
|
64
|
+
|
|
65
|
+
空库允许一次网页初始化管理员,完成后由管理员添加其他账号。个人令牌在网页管理,MCP 使用 Streamable HTTP `/mcp` 和 `Authorization: Bearer <个人令牌>`;不提供 OAuth 流程。项目拥有者管理配置和成员,协作者可以标注及训练,系统管理员管理全部项目。详细用法见[用户权限与 MCP 接入](../README.md#用户与项目权限)。
|
|
66
|
+
|
|
67
|
+
## 训练与 AI 预标注
|
|
68
|
+
|
|
69
|
+
项目页可发起异步训练并查看状态、日志与产物,项目配置第 4 步选择 YOLO 算法和 AI 模型。训练代码位于 `training/`,离线入口为 `yolo-mcp-train` 或 `python -m backend.training.train`。默认 Web 依赖不包含 PyTorch/Ultralytics,需要时安装 `.[training]`;优先复用已有 GPU 运行环境。安装和存储约定见[训练说明](training/README.md)。
|
|
70
|
+
|
|
71
|
+
服务与训练共用根目录的 Dockerfile,从仓库根目录构建:
|
|
72
|
+
|
|
73
|
+
```bash
|
|
74
|
+
docker build -t yolo-mcp:local .
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## 验证
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
uv run --no-sync pytest
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
测试使用隔离 SQLite 和临时本地目录,不读取实际凭据。格式采用 Black(Python 3.11、88 列),核心链路同时执行 Flake8 检查。
|
|
84
|
+
|
|
85
|
+
```bash
|
|
86
|
+
uv run --no-sync black --check .
|
|
87
|
+
uv run --no-sync flake8 .
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
## 发行包
|
|
91
|
+
|
|
92
|
+
在完整仓库根目录执行 `uv build --project backend --out-dir dist`。构建钩子会运行 `pnpm build:frontend`,请先安装前端工作区依赖。生成的 wheel 和源码包均包含前端页面,安装后直接运行 `yolo-mcp`;从源码包构建 wheel 无需前端工具链。可编辑安装跳过构建钩子中的前端编译,开发时单独运行 Vite。
|
yolo_mcp-2.0.0/README.md
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
# YOLO MCP 后端
|
|
2
|
+
|
|
3
|
+
本目录是独立 Python 项目,源码包名为 `backend`。业务说明、前端运行和参考项目见[仓库 README](../README.md)。
|
|
4
|
+
|
|
5
|
+
## Web 服务
|
|
6
|
+
|
|
7
|
+
从本目录执行:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
uv sync --python 3.11 --frozen --group test
|
|
11
|
+
cp .env.example .env
|
|
12
|
+
# 按需调整 DATA_DIR、USE_AUTO_LABEL 和 DEVICE;签名密钥首次启动时自动生成。
|
|
13
|
+
uv run --env-file .env uvicorn backend.main:app --host 127.0.0.1 --port 8002
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
`yolo-mcp` 也是服务 CLI 入口。模块导入和 `--help` 不初始化数据库,实际应用启动时通过 `migrations/versions/001_init_db.py` 初始化空库;默认 SQLite 文件名为 `labels.sqlite`。结构调整后使用新库,旧库不会自动迁移。不提供历史结构升级或 to_mysql。
|
|
17
|
+
|
|
18
|
+
`DATA_DIR` 默认指向用户主目录的 `.yolo-mcp/`。服务首次启动时在此目录生成 `secret.key`,后续启动读取同一密钥;数据库和项目文件也默认保存在此目录。
|
|
19
|
+
|
|
20
|
+
空库允许一次网页初始化管理员,完成后由管理员添加其他账号。个人令牌在网页管理,MCP 使用 Streamable HTTP `/mcp` 和 `Authorization: Bearer <个人令牌>`;不提供 OAuth 流程。项目拥有者管理配置和成员,协作者可以标注及训练,系统管理员管理全部项目。详细用法见[用户权限与 MCP 接入](../README.md#用户与项目权限)。
|
|
21
|
+
|
|
22
|
+
## 训练与 AI 预标注
|
|
23
|
+
|
|
24
|
+
项目页可发起异步训练并查看状态、日志与产物,项目配置第 4 步选择 YOLO 算法和 AI 模型。训练代码位于 `training/`,离线入口为 `yolo-mcp-train` 或 `python -m backend.training.train`。默认 Web 依赖不包含 PyTorch/Ultralytics,需要时安装 `.[training]`;优先复用已有 GPU 运行环境。安装和存储约定见[训练说明](training/README.md)。
|
|
25
|
+
|
|
26
|
+
服务与训练共用根目录的 Dockerfile,从仓库根目录构建:
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
docker build -t yolo-mcp:local .
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
## 验证
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
uv run --no-sync pytest
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
测试使用隔离 SQLite 和临时本地目录,不读取实际凭据。格式采用 Black(Python 3.11、88 列),核心链路同时执行 Flake8 检查。
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
uv run --no-sync black --check .
|
|
42
|
+
uv run --no-sync flake8 .
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
## 发行包
|
|
46
|
+
|
|
47
|
+
在完整仓库根目录执行 `uv build --project backend --out-dir dist`。构建钩子会运行 `pnpm build:frontend`,请先安装前端工作区依赖。生成的 wheel 和源码包均包含前端页面,安装后直接运行 `yolo-mcp`;从源码包构建 wheel 无需前端工具链。可编辑安装跳过构建钩子中的前端编译,开发时单独运行 Vite。
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import List, Optional, Tuple
|
|
3
|
+
|
|
4
|
+
from sqlalchemy.orm import Session
|
|
5
|
+
|
|
6
|
+
from backend.domain.models.attachment import ProjectAttachment
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def list_by(
|
|
10
|
+
db: Session,
|
|
11
|
+
size: int,
|
|
12
|
+
ids: List[int] | None = [],
|
|
13
|
+
project_id: Optional[int] = None,
|
|
14
|
+
owner_id: Optional[int] = None,
|
|
15
|
+
after: Optional[int] = None,
|
|
16
|
+
before: Optional[int] = None,
|
|
17
|
+
page: Optional[int] = None,
|
|
18
|
+
sorting: Optional[str] = None,
|
|
19
|
+
) -> Tuple[List[ProjectAttachment], int]:
|
|
20
|
+
# query filter
|
|
21
|
+
query_filter = [
|
|
22
|
+
ProjectAttachment.deleted_at.is_(None),
|
|
23
|
+
ProjectAttachment.id.in_(ids),
|
|
24
|
+
]
|
|
25
|
+
if owner_id:
|
|
26
|
+
query_filter.append(ProjectAttachment.created_by == owner_id)
|
|
27
|
+
|
|
28
|
+
if before:
|
|
29
|
+
query_filter.append(ProjectAttachment.id < before)
|
|
30
|
+
if after:
|
|
31
|
+
query_filter.append(ProjectAttachment.id > after)
|
|
32
|
+
if project_id:
|
|
33
|
+
query_filter.append(ProjectAttachment.project_id == project_id)
|
|
34
|
+
|
|
35
|
+
query = db.query(ProjectAttachment).filter(*query_filter)
|
|
36
|
+
|
|
37
|
+
# default order by id, before need select last items
|
|
38
|
+
if before:
|
|
39
|
+
query = query.order_by(ProjectAttachment.id.desc())
|
|
40
|
+
else:
|
|
41
|
+
query = query.order_by(ProjectAttachment.id.asc())
|
|
42
|
+
|
|
43
|
+
count = query.count()
|
|
44
|
+
|
|
45
|
+
results = query.offset(offset=page * size if page else 0).limit(limit=size).all()
|
|
46
|
+
|
|
47
|
+
if sorting:
|
|
48
|
+
field, order = sorting.split(":")
|
|
49
|
+
if order == "desc":
|
|
50
|
+
results = sorted(results, key=lambda x: getattr(x, field), reverse=True)
|
|
51
|
+
else:
|
|
52
|
+
results = sorted(results, key=lambda x: getattr(x, field))
|
|
53
|
+
|
|
54
|
+
if before:
|
|
55
|
+
results.reverse()
|
|
56
|
+
|
|
57
|
+
return results, count
|
|
58
|
+
|
|
59
|
+
|
|
60
|
+
def create(db: Session, attachment: ProjectAttachment) -> ProjectAttachment:
|
|
61
|
+
db.add(attachment)
|
|
62
|
+
db.flush()
|
|
63
|
+
db.refresh(attachment)
|
|
64
|
+
return attachment
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
def get(db: Session, attachment_id: int) -> ProjectAttachment:
|
|
68
|
+
return (
|
|
69
|
+
db.query(ProjectAttachment)
|
|
70
|
+
.filter(
|
|
71
|
+
ProjectAttachment.id == attachment_id,
|
|
72
|
+
ProjectAttachment.deleted_at.is_(None),
|
|
73
|
+
)
|
|
74
|
+
.first()
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
def get_by_ids(db: Session, attachment_ids: List[int]) -> List[ProjectAttachment]:
|
|
79
|
+
return (
|
|
80
|
+
db.query(ProjectAttachment)
|
|
81
|
+
.filter(
|
|
82
|
+
ProjectAttachment.id.in_(attachment_ids),
|
|
83
|
+
ProjectAttachment.deleted_at.is_(None),
|
|
84
|
+
)
|
|
85
|
+
.all()
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
def delete(db: Session, attachment_ids: List[int]) -> None:
|
|
90
|
+
db.query(ProjectAttachment).filter(ProjectAttachment.id.in_(attachment_ids)).update(
|
|
91
|
+
{ProjectAttachment.deleted_at: datetime.now()}
|
|
92
|
+
)
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
from typing import Optional
|
|
2
|
+
from sqlalchemy.orm import Session
|
|
3
|
+
from backend.domain.models.auto_label_job import AutoLabelJob
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
def create(
|
|
7
|
+
db: Session,
|
|
8
|
+
project_id: int,
|
|
9
|
+
user_id: int,
|
|
10
|
+
sample_count: int,
|
|
11
|
+
model_name: str,
|
|
12
|
+
algorithm: str = "yolo",
|
|
13
|
+
) -> AutoLabelJob:
|
|
14
|
+
job = AutoLabelJob(
|
|
15
|
+
project_id=project_id,
|
|
16
|
+
created_by=user_id,
|
|
17
|
+
sample_count=sample_count,
|
|
18
|
+
model_name=model_name,
|
|
19
|
+
algorithm=algorithm,
|
|
20
|
+
)
|
|
21
|
+
db.add(job)
|
|
22
|
+
db.flush()
|
|
23
|
+
db.refresh(job)
|
|
24
|
+
return job
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
def get(db: Session, job_id: int) -> Optional[AutoLabelJob]:
|
|
28
|
+
return db.query(AutoLabelJob).filter(AutoLabelJob.id == job_id).first()
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def update_status(
|
|
32
|
+
db: Session, job: AutoLabelJob, status: str, **kwargs
|
|
33
|
+
) -> AutoLabelJob:
|
|
34
|
+
job.status = status
|
|
35
|
+
for k, v in kwargs.items():
|
|
36
|
+
setattr(job, k, v)
|
|
37
|
+
db.flush()
|
|
38
|
+
db.refresh(job)
|
|
39
|
+
return job
|
|
40
|
+
|
|
41
|
+
|
|
42
|
+
def increment_progress(db: Session, job: AutoLabelJob, success: bool) -> AutoLabelJob:
|
|
43
|
+
job.processed_count = (job.processed_count or 0) + 1
|
|
44
|
+
if success:
|
|
45
|
+
job.success_count = (job.success_count or 0) + 1
|
|
46
|
+
else:
|
|
47
|
+
job.failed_count = (job.failed_count or 0) + 1
|
|
48
|
+
db.flush()
|
|
49
|
+
db.refresh(job)
|
|
50
|
+
return job
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
from datetime import datetime
|
|
2
|
+
from typing import List, Tuple
|
|
3
|
+
|
|
4
|
+
from sqlalchemy.orm import Session
|
|
5
|
+
|
|
6
|
+
from backend.domain.models.pre_annotation import ProjectPreAnnotation
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def batch(
|
|
10
|
+
db: Session, pre_annotations: List[ProjectPreAnnotation]
|
|
11
|
+
) -> List[ProjectPreAnnotation]:
|
|
12
|
+
db.bulk_save_objects(pre_annotations, return_defaults=True)
|
|
13
|
+
return pre_annotations
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
def list_by(
|
|
17
|
+
db: Session,
|
|
18
|
+
project_id: int | None = None,
|
|
19
|
+
sample_name: str | None = None,
|
|
20
|
+
after: int | None = None,
|
|
21
|
+
before: int | None = None,
|
|
22
|
+
page: int | None = None,
|
|
23
|
+
sorting: str | None = None,
|
|
24
|
+
size: int | None = 10,
|
|
25
|
+
) -> Tuple[List[ProjectPreAnnotation], int]:
|
|
26
|
+
|
|
27
|
+
# query filter
|
|
28
|
+
query_filter = [ProjectPreAnnotation.deleted_at.is_(None)]
|
|
29
|
+
if before:
|
|
30
|
+
query_filter.append(ProjectPreAnnotation.id < before)
|
|
31
|
+
if after:
|
|
32
|
+
query_filter.append(ProjectPreAnnotation.id > after)
|
|
33
|
+
if project_id:
|
|
34
|
+
query_filter.append(ProjectPreAnnotation.project_id == project_id)
|
|
35
|
+
|
|
36
|
+
if sample_name:
|
|
37
|
+
query_filter.append(ProjectPreAnnotation.sample_name == sample_name)
|
|
38
|
+
|
|
39
|
+
query = db.query(ProjectPreAnnotation).filter(*query_filter)
|
|
40
|
+
|
|
41
|
+
# default order by id, before need select last items
|
|
42
|
+
if before:
|
|
43
|
+
query = query.order_by(ProjectPreAnnotation.id.desc())
|
|
44
|
+
else:
|
|
45
|
+
query = query.order_by(ProjectPreAnnotation.id.asc())
|
|
46
|
+
|
|
47
|
+
count = query.count()
|
|
48
|
+
|
|
49
|
+
results = query.offset(offset=page * size if page else 0).limit(limit=size).all()
|
|
50
|
+
|
|
51
|
+
if sorting:
|
|
52
|
+
field, order = sorting.split(":")
|
|
53
|
+
if order == "desc":
|
|
54
|
+
results = sorted(results, key=lambda x: getattr(x, field), reverse=True)
|
|
55
|
+
else:
|
|
56
|
+
results = sorted(results, key=lambda x: getattr(x, field))
|
|
57
|
+
|
|
58
|
+
if before:
|
|
59
|
+
results.reverse()
|
|
60
|
+
|
|
61
|
+
return results, count
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def delete(db: Session, pre_annotation_ids: List[int]) -> None:
|
|
65
|
+
db.query(ProjectPreAnnotation).filter(
|
|
66
|
+
ProjectPreAnnotation.id.in_(pre_annotation_ids)
|
|
67
|
+
).update({ProjectPreAnnotation.deleted_at: datetime.now()})
|