singlepipe 0.0.1__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.
Files changed (54) hide show
  1. singlepipe-0.0.1/LICENSE +21 -0
  2. singlepipe-0.0.1/PKG-INFO +135 -0
  3. singlepipe-0.0.1/README.md +102 -0
  4. singlepipe-0.0.1/pyproject.toml +70 -0
  5. singlepipe-0.0.1/setup.cfg +4 -0
  6. singlepipe-0.0.1/singlepipe/__init__.py +8 -0
  7. singlepipe-0.0.1/singlepipe/adapters/__init__.py +0 -0
  8. singlepipe-0.0.1/singlepipe/adapters/hf_adapter.py +119 -0
  9. singlepipe-0.0.1/singlepipe/model_types/__init__.py +3 -0
  10. singlepipe-0.0.1/singlepipe/model_types/types.py +79 -0
  11. singlepipe-0.0.1/singlepipe/schemas/__init__.py +25 -0
  12. singlepipe-0.0.1/singlepipe/schemas/audio_schemas/__init__.py +0 -0
  13. singlepipe-0.0.1/singlepipe/schemas/audio_schemas/audio_classification.py +40 -0
  14. singlepipe-0.0.1/singlepipe/schemas/audio_schemas/speech_to_text.py +40 -0
  15. singlepipe-0.0.1/singlepipe/schemas/audio_schemas/text_to_audio.py +40 -0
  16. singlepipe-0.0.1/singlepipe/schemas/audio_schemas/zero_shot_audio_classification.py +40 -0
  17. singlepipe-0.0.1/singlepipe/schemas/image_schemas/__init__.py +0 -0
  18. singlepipe-0.0.1/singlepipe/schemas/image_schemas/depth_estimation.py +40 -0
  19. singlepipe-0.0.1/singlepipe/schemas/image_schemas/image_classification.py +40 -0
  20. singlepipe-0.0.1/singlepipe/schemas/image_schemas/image_embedding.py +40 -0
  21. singlepipe-0.0.1/singlepipe/schemas/image_schemas/image_segmentation.py +40 -0
  22. singlepipe-0.0.1/singlepipe/schemas/image_schemas/keypoint_matching.py +40 -0
  23. singlepipe-0.0.1/singlepipe/schemas/image_schemas/mask_generation.py +40 -0
  24. singlepipe-0.0.1/singlepipe/schemas/image_schemas/object_detection.py +290 -0
  25. singlepipe-0.0.1/singlepipe/schemas/image_schemas/zero_shot_image_classification.py +40 -0
  26. singlepipe-0.0.1/singlepipe/schemas/image_schemas/zero_shot_object_detection.py +40 -0
  27. singlepipe-0.0.1/singlepipe/schemas/multimodal_schemas/__init__.py +0 -0
  28. singlepipe-0.0.1/singlepipe/schemas/multimodal_schemas/document_question_answering.py +40 -0
  29. singlepipe-0.0.1/singlepipe/schemas/multimodal_schemas/image_text_to_text.py +40 -0
  30. singlepipe-0.0.1/singlepipe/schemas/multimodal_schemas/table_question_answering.py +40 -0
  31. singlepipe-0.0.1/singlepipe/schemas/ocr_schemas/__init__.py +0 -0
  32. singlepipe-0.0.1/singlepipe/schemas/ocr_schemas/ocr.py +40 -0
  33. singlepipe-0.0.1/singlepipe/schemas/registry.py +97 -0
  34. singlepipe-0.0.1/singlepipe/schemas/table_schemas/__init__.py +0 -0
  35. singlepipe-0.0.1/singlepipe/schemas/table_schemas/tabular_classification.py +40 -0
  36. singlepipe-0.0.1/singlepipe/schemas/table_schemas/tabular_regression.py +40 -0
  37. singlepipe-0.0.1/singlepipe/schemas/text_schemas/__init__.py +0 -0
  38. singlepipe-0.0.1/singlepipe/schemas/text_schemas/fill_mask.py +40 -0
  39. singlepipe-0.0.1/singlepipe/schemas/text_schemas/question_answering.py +40 -0
  40. singlepipe-0.0.1/singlepipe/schemas/text_schemas/summarization.py +40 -0
  41. singlepipe-0.0.1/singlepipe/schemas/text_schemas/text2text_generation.py +40 -0
  42. singlepipe-0.0.1/singlepipe/schemas/text_schemas/text_classification.py +40 -0
  43. singlepipe-0.0.1/singlepipe/schemas/text_schemas/text_embedding.py +40 -0
  44. singlepipe-0.0.1/singlepipe/schemas/text_schemas/text_generation.py +40 -0
  45. singlepipe-0.0.1/singlepipe/schemas/text_schemas/token_classification.py +40 -0
  46. singlepipe-0.0.1/singlepipe/schemas/text_schemas/translation.py +40 -0
  47. singlepipe-0.0.1/singlepipe/schemas/text_schemas/zero_shot_text_classification.py +40 -0
  48. singlepipe-0.0.1/singlepipe/schemas/video_schemas/__init__.py +0 -0
  49. singlepipe-0.0.1/singlepipe/schemas/video_schemas/video_classification.py +40 -0
  50. singlepipe-0.0.1/singlepipe.egg-info/PKG-INFO +135 -0
  51. singlepipe-0.0.1/singlepipe.egg-info/SOURCES.txt +52 -0
  52. singlepipe-0.0.1/singlepipe.egg-info/dependency_links.txt +1 -0
  53. singlepipe-0.0.1/singlepipe.egg-info/requires.txt +16 -0
  54. singlepipe-0.0.1/singlepipe.egg-info/top_level.txt +1 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Ovcharov Gleb
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is furnished
10
+ to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,135 @@
1
+ Metadata-Version: 2.4
2
+ Name: singlepipe
3
+ Version: 0.0.1
4
+ Summary: Typed interface for ML model inference across HuggingFace, PyTorch, and other backends
5
+ Author-email: Gleb <glebov274@gmail.com>
6
+ License-Expression: MIT
7
+ Keywords: ml,inference,huggingface,pytorch,pydantic,typed
8
+ Classifier: Development Status :: 2 - Pre-Alpha
9
+ Classifier: Intended Audience :: Developers
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.11
12
+ Classifier: Programming Language :: Python :: 3.12
13
+ Classifier: Programming Language :: Python :: 3.13
14
+ Classifier: Programming Language :: Python :: 3.14
15
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
16
+ Requires-Python: >=3.11
17
+ Description-Content-Type: text/markdown
18
+ License-File: LICENSE
19
+ Requires-Dist: httpx>=0.28.1
20
+ Requires-Dist: pillow>=12.3.0
21
+ Requires-Dist: pydantic>=2.13.4
22
+ Requires-Dist: numpy>=2.0
23
+ Requires-Dist: transformers>=5.14.1
24
+ Provides-Extra: torch
25
+ Requires-Dist: torch>=2.13.0; extra == "torch"
26
+ Provides-Extra: detr
27
+ Requires-Dist: torch>=2.13.0; extra == "detr"
28
+ Requires-Dist: timm>=1.0.28; extra == "detr"
29
+ Provides-Extra: all
30
+ Requires-Dist: torch>=2.13.0; extra == "all"
31
+ Requires-Dist: timm>=1.0.28; extra == "all"
32
+ Dynamic: license-file
33
+
34
+ # SinglePipe
35
+
36
+ > Typed interface for ML model inference: one API for HuggingFace, PyTorch, and (eventually) other backends.
37
+
38
+ ⚠️ **Status: pre-alpha.** This PyPI release reserves the package name. The library is under active development, the API is unstable, and only one task — object detection via HuggingFace — is currently supported. Not recommended for production use.
39
+
40
+ ## Why
41
+
42
+ Working with ML models means drowning in mismatched formats: HuggingFace returns `list[dict]`, a custom `nn.Module` returns tensors, a remote API returns JSON with its own schema. SinglePipe gives you **one entry point** and a **typed output** regardless of what's under the hood.
43
+
44
+ ## Features
45
+
46
+ - **Typed input/output schemas** built on pydantic — validation out of the box, IDE autocomplete, JSON serialization ready.
47
+ - **Flexible input** — an image can arrive as `PIL.Image`, `numpy.ndarray`, `torch.Tensor`, a file path, a URL, or raw bytes; SinglePipe normalizes it to a canonical format.
48
+ - **Unified interface across backends** — HuggingFace today, PyTorch, ONNX, and remote APIs next.
49
+ - **Pipeline composition** *(in progress)* — combine multiple models into one typed flow (detector → OCR → classifier) with automatic type-based wiring.
50
+ - **Async and parallel execution of independent nodes** *(on the roadmap)*.
51
+
52
+ ## Installation
53
+
54
+ Not available yet. This release reserves the package name on PyPI.
55
+
56
+ Requires Python 3.11+.
57
+
58
+ ## Quick start
59
+
60
+ ```python
61
+ from singlepipe.adapters.hf_adapter import HFAdapter
62
+ from singlepipe.model_types import TaskType
63
+
64
+ adapter = HFAdapter(
65
+ model_name="facebook/detr-resnet-50",
66
+ task=TaskType.OBJECT_DETECTION,
67
+ )
68
+
69
+ result = adapter("http://images.cocodataset.org/val2017/000000039769.jpg")
70
+
71
+ print(f"Found {len(result)} objects")
72
+ for det in result:
73
+ print(f" {det.label}: score={det.score:.2f}, box={det.box.as_tuple()}")
74
+ ```
75
+
76
+ Accepted inputs: `PIL.Image`, `numpy.ndarray` (HWC), `torch.Tensor` (CHW), a file path (`str` or `Path`), an `http(s)://` URL, or raw `bytes`.
77
+
78
+ ## Working with results
79
+
80
+ The result is a typed pydantic object with a rich API:
81
+
82
+ ```python
83
+ # Filtering
84
+ confident = result.filter_by_score(0.7)
85
+ cats_only = result.filter_by_label("cat")
86
+ some = result.filter_by_label(["cat", "dog", "person"])
87
+
88
+ # Iteration
89
+ for det in result:
90
+ print(det.label, det.score)
91
+ print(f"Total: {len(result)}")
92
+
93
+ # Geometry
94
+ box = result.predictions[0].box
95
+ box.width, box.height, box.area, box.center
96
+ box.clip(image_width=800, image_height=600)
97
+ box.iou(other_box)
98
+
99
+ # Serialization
100
+ result.model_dump()
101
+ result.model_dump_json()
102
+ ```
103
+
104
+ ## Supported tasks
105
+
106
+ | Task | Backend | Status |
107
+ |---|---|---|
108
+ | Object detection | HuggingFace | ✅ |
109
+ | Image classification | HuggingFace | 🚧 planned |
110
+ | Text classification | HuggingFace | 🚧 planned |
111
+ | Text generation | HuggingFace | 🚧 planned |
112
+
113
+ ## Roadmap
114
+
115
+ - [x] HF adapter for single-model inference
116
+ - [x] Typed schemas for object detection
117
+ - [ ] Second task (image classification) — verifies the pattern generalizes
118
+ - [ ] `Node` interface for unified pipeline nodes
119
+ - [ ] Linear pipeline composition (`Sequential`)
120
+ - [ ] PyTorch adapter (for custom `nn.Module`)
121
+ - [ ] Full DAG with branching
122
+ - [ ] Async and parallel execution of independent nodes
123
+ - [ ] ONNX Runtime backend
124
+ - [ ] Remote-API backend (OpenAI-compatible)
125
+
126
+ ## Development
127
+
128
+ ```bash
129
+ uv sync --group dev
130
+ uv run pytest
131
+ ```
132
+
133
+ ## License
134
+
135
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,102 @@
1
+ # SinglePipe
2
+
3
+ > Typed interface for ML model inference: one API for HuggingFace, PyTorch, and (eventually) other backends.
4
+
5
+ ⚠️ **Status: pre-alpha.** This PyPI release reserves the package name. The library is under active development, the API is unstable, and only one task — object detection via HuggingFace — is currently supported. Not recommended for production use.
6
+
7
+ ## Why
8
+
9
+ Working with ML models means drowning in mismatched formats: HuggingFace returns `list[dict]`, a custom `nn.Module` returns tensors, a remote API returns JSON with its own schema. SinglePipe gives you **one entry point** and a **typed output** regardless of what's under the hood.
10
+
11
+ ## Features
12
+
13
+ - **Typed input/output schemas** built on pydantic — validation out of the box, IDE autocomplete, JSON serialization ready.
14
+ - **Flexible input** — an image can arrive as `PIL.Image`, `numpy.ndarray`, `torch.Tensor`, a file path, a URL, or raw bytes; SinglePipe normalizes it to a canonical format.
15
+ - **Unified interface across backends** — HuggingFace today, PyTorch, ONNX, and remote APIs next.
16
+ - **Pipeline composition** *(in progress)* — combine multiple models into one typed flow (detector → OCR → classifier) with automatic type-based wiring.
17
+ - **Async and parallel execution of independent nodes** *(on the roadmap)*.
18
+
19
+ ## Installation
20
+
21
+ Not available yet. This release reserves the package name on PyPI.
22
+
23
+ Requires Python 3.11+.
24
+
25
+ ## Quick start
26
+
27
+ ```python
28
+ from singlepipe.adapters.hf_adapter import HFAdapter
29
+ from singlepipe.model_types import TaskType
30
+
31
+ adapter = HFAdapter(
32
+ model_name="facebook/detr-resnet-50",
33
+ task=TaskType.OBJECT_DETECTION,
34
+ )
35
+
36
+ result = adapter("http://images.cocodataset.org/val2017/000000039769.jpg")
37
+
38
+ print(f"Found {len(result)} objects")
39
+ for det in result:
40
+ print(f" {det.label}: score={det.score:.2f}, box={det.box.as_tuple()}")
41
+ ```
42
+
43
+ Accepted inputs: `PIL.Image`, `numpy.ndarray` (HWC), `torch.Tensor` (CHW), a file path (`str` or `Path`), an `http(s)://` URL, or raw `bytes`.
44
+
45
+ ## Working with results
46
+
47
+ The result is a typed pydantic object with a rich API:
48
+
49
+ ```python
50
+ # Filtering
51
+ confident = result.filter_by_score(0.7)
52
+ cats_only = result.filter_by_label("cat")
53
+ some = result.filter_by_label(["cat", "dog", "person"])
54
+
55
+ # Iteration
56
+ for det in result:
57
+ print(det.label, det.score)
58
+ print(f"Total: {len(result)}")
59
+
60
+ # Geometry
61
+ box = result.predictions[0].box
62
+ box.width, box.height, box.area, box.center
63
+ box.clip(image_width=800, image_height=600)
64
+ box.iou(other_box)
65
+
66
+ # Serialization
67
+ result.model_dump()
68
+ result.model_dump_json()
69
+ ```
70
+
71
+ ## Supported tasks
72
+
73
+ | Task | Backend | Status |
74
+ |---|---|---|
75
+ | Object detection | HuggingFace | ✅ |
76
+ | Image classification | HuggingFace | 🚧 planned |
77
+ | Text classification | HuggingFace | 🚧 planned |
78
+ | Text generation | HuggingFace | 🚧 planned |
79
+
80
+ ## Roadmap
81
+
82
+ - [x] HF adapter for single-model inference
83
+ - [x] Typed schemas for object detection
84
+ - [ ] Second task (image classification) — verifies the pattern generalizes
85
+ - [ ] `Node` interface for unified pipeline nodes
86
+ - [ ] Linear pipeline composition (`Sequential`)
87
+ - [ ] PyTorch adapter (for custom `nn.Module`)
88
+ - [ ] Full DAG with branching
89
+ - [ ] Async and parallel execution of independent nodes
90
+ - [ ] ONNX Runtime backend
91
+ - [ ] Remote-API backend (OpenAI-compatible)
92
+
93
+ ## Development
94
+
95
+ ```bash
96
+ uv sync --group dev
97
+ uv run pytest
98
+ ```
99
+
100
+ ## License
101
+
102
+ MIT — see [LICENSE](LICENSE).
@@ -0,0 +1,70 @@
1
+ [project]
2
+ name = "singlepipe"
3
+ version = "0.0.1"
4
+ description = "Typed interface for ML model inference across HuggingFace, PyTorch, and other backends"
5
+ readme = "README.md"
6
+ requires-python = ">=3.11"
7
+ license = "MIT"
8
+ license-files = ["LICENSE"]
9
+ authors = [
10
+ { name = "Gleb", email = "glebov274@gmail.com" },
11
+ ]
12
+ keywords = ["ml", "inference", "huggingface", "pytorch", "pydantic", "typed"]
13
+ classifiers = [
14
+ "Development Status :: 2 - Pre-Alpha",
15
+ "Intended Audience :: Developers",
16
+ "Programming Language :: Python :: 3",
17
+ "Programming Language :: Python :: 3.11",
18
+ "Programming Language :: Python :: 3.12",
19
+ "Programming Language :: Python :: 3.13",
20
+ "Programming Language :: Python :: 3.14",
21
+ "Topic :: Scientific/Engineering :: Artificial Intelligence",
22
+ ]
23
+ dependencies = [
24
+ "httpx>=0.28.1",
25
+ "pillow>=12.3.0",
26
+ "pydantic>=2.13.4",
27
+ "numpy>=2.0",
28
+ "transformers>=5.14.1",
29
+ ]
30
+
31
+ [project.optional-dependencies]
32
+ torch = [
33
+ "torch>=2.13.0",
34
+ ]
35
+ detr = [
36
+ "torch>=2.13.0",
37
+ "timm>=1.0.28",
38
+ ]
39
+ all = [
40
+ "torch>=2.13.0",
41
+ "timm>=1.0.28",
42
+ ]
43
+
44
+ [dependency-groups]
45
+ dev = [
46
+ "pytest>=8",
47
+ "ruff>=0.16.1",
48
+ "mypy>=2.3.0",
49
+ ]
50
+
51
+ [build-system]
52
+ requires = ["setuptools>=77"]
53
+ build-backend = "setuptools.build_meta"
54
+
55
+ [tool.setuptools.packages.find]
56
+ where = ["."]
57
+ include = ["singlepipe*"]
58
+
59
+ [tool.ruff]
60
+ line-length = 100
61
+ target-version = "py311"
62
+
63
+ [tool.ruff.lint]
64
+ select = ["E", "F", "I", "UP", "B", "SIM"]
65
+
66
+ [tool.mypy]
67
+ python_version = "3.11"
68
+ strict = false
69
+ warn_return_any = true
70
+ warn_unused_ignores = true
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,8 @@
1
+ """SinglePipe: typed multi-model inference orchestrator."""
2
+
3
+ from singlepipe.adapters.hf_adapter import HFAdapter
4
+ from singlepipe.model_types import TaskType
5
+
6
+ __version__ = "0.0.1"
7
+
8
+ __all__ = ["HFAdapter", "TaskType"]
File without changes
@@ -0,0 +1,119 @@
1
+ from typing import TYPE_CHECKING, Any
2
+
3
+ from transformers import pipeline as hf_pipeline
4
+
5
+ from singlepipe.model_types import TaskType
6
+ from singlepipe.schemas import get_schemas
7
+
8
+ if TYPE_CHECKING:
9
+ pass
10
+
11
+
12
+ class HFAdapter:
13
+ """Typed adapter around ``transformers.pipeline`` for a specific task.
14
+
15
+ Wraps a HuggingFace pipeline with SinglePipe's input/output schemas:
16
+ the raw input is validated and normalized into the schema's canonical
17
+ form, the pipeline is invoked, and its raw output is validated and
18
+ materialized as a typed SinglePipe output object.
19
+
20
+ The heavy work (loading the model, tokenizer/processor, and running
21
+ pre- and post-processing) is delegated to ``transformers.pipeline``.
22
+ This class only enforces the typed boundary on both sides.
23
+
24
+ Parameters
25
+ ----------
26
+ model_name:
27
+ HuggingFace model id (e.g. ``"facebook/detr-resnet-50"``) or a
28
+ local path to model weights.
29
+ task:
30
+ SinglePipe task identifier. Its ``.value`` must match a valid
31
+ ``transformers.pipeline`` task string (e.g. ``"object-detection"``).
32
+ Determines which input/output schemas are pulled from the registry.
33
+ device:
34
+ Device to place the model on. ``None`` = CPU, an ``int`` = CUDA
35
+ device index, or a device string such as ``"cpu"`` or ``"cuda:0"``.
36
+ **pipeline_kwargs:
37
+ Extra keyword arguments passed straight to ``transformers.pipeline``
38
+ (e.g. ``torch_dtype``, ``trust_remote_code``, ``revision``).
39
+
40
+ Attributes
41
+ ----------
42
+ model_name : str
43
+ The model id or path this adapter was constructed with.
44
+ task : TaskType
45
+ The task this adapter is bound to.
46
+ pipeline : transformers.Pipeline
47
+ The underlying HuggingFace pipeline instance.
48
+
49
+ Examples
50
+ --------
51
+ >>> adapter = HFAdapter("facebook/detr-resnet-50", TaskType.OBJECT_DETECTION)
52
+ >>> result = adapter("http://images.cocodataset.org/val2017/000000039769.jpg")
53
+ >>> for det in result:
54
+ ... print(det.label, det.score, det.box.as_tuple())
55
+
56
+ Notes
57
+ -----
58
+ - The model is loaded once at construction; subsequent calls reuse it.
59
+ - Batching, streaming, and async execution are not supported at this
60
+ layer — one input, one output per call.
61
+ - Task↔model compatibility is not pre-validated: mismatches surface as
62
+ errors from ``transformers.pipeline`` at construction time.
63
+ """
64
+
65
+
66
+
67
+
68
+ def __init__(
69
+ self,
70
+ model_name: str,
71
+ task: TaskType,
72
+ device: int | str | None = None,
73
+ **pipeline_kwargs: Any,
74
+ ) -> None:
75
+ self.model_name = model_name
76
+ self.task = task
77
+
78
+ self.pipeline = hf_pipeline(
79
+ task=task.value, # type: ignore[arg-type]
80
+ model=model_name,
81
+ device=device, # type: ignore[arg-type]
82
+ **pipeline_kwargs,
83
+ )
84
+
85
+ self._input_schema, self._output_schema = get_schemas(task)
86
+
87
+
88
+
89
+
90
+
91
+ def __call__(self, raw_input):
92
+
93
+ if isinstance(raw_input, self._input_schema):
94
+ validated_in = raw_input
95
+ elif isinstance(raw_input, dict):
96
+ validated_in = self._input_schema.model_validate(raw_input)
97
+ else:
98
+ validated_in = self._input_schema.from_raw(raw_input)
99
+
100
+
101
+ raw_output = self.pipeline(validated_in.to_pipeline_input())
102
+
103
+ return self._output_schema.from_pipeline_output(
104
+ raw_output,
105
+ **validated_in.output_context
106
+ )
107
+
108
+ def __repr__(self) -> str:
109
+ return f"HFAdapter(model={self.model_name!r}, task={self.task.value!r})"
110
+
111
+
112
+ if __name__ == "__main__":
113
+ adapter = HFAdapter("facebook/detr-resnet-50", TaskType.OBJECT_DETECTION)
114
+ print(adapter)
115
+
116
+ result = adapter("http://images.cocodataset.org/val2017/000000039769.jpg")
117
+ print(f"Found {len(result)} objects")
118
+ for det in result:
119
+ print(f" {det.label}: {det.score:.3f}")
@@ -0,0 +1,3 @@
1
+ from .types import TaskType
2
+
3
+ __all__ = ["TaskType"]
@@ -0,0 +1,79 @@
1
+ from enum import StrEnum
2
+
3
+
4
+ class TaskType(StrEnum):
5
+ """Semantic identifier of an ML task in SinglePipe.
6
+
7
+ ``TaskType`` is the vocabulary the schema registry keys on:
8
+ each member corresponds to a pair of input/output schemas
9
+ describing the contract of that task.
10
+
11
+ Enum values are intentionally aligned with HuggingFace
12
+ ``transformers.pipeline`` task strings whenever a matching HF
13
+ pipeline exists — this lets ``HFAdapter`` pass the value straight
14
+ through without a lookup table. Tasks with no HF equivalent
15
+ (``TABULAR_CLASSIFICATION``, ``TABULAR_REGRESSION``, ``OCR``)
16
+ keep values chosen for readability; they are served by other
17
+ adapters.
18
+
19
+ Because ``TaskType`` inherits from ``StrEnum``, members compare
20
+ equal to their string values and can be used interchangeably
21
+ with strings — in dict keys, HF pipeline arguments, JSON, etc.
22
+
23
+ The enum grows as new tasks gain first-class support. A member
24
+ listed here is *known* to SinglePipe; whether schemas are actually
25
+ registered for it is a separate question answered by the registry
26
+ (``get_schemas`` raises a descriptive error for known-but-
27
+ unregistered tasks).
28
+
29
+ Examples
30
+ --------
31
+ >>> TaskType.OBJECT_DETECTION == "object-detection"
32
+ True
33
+ >>> TaskType.OBJECT_DETECTION.value
34
+ 'object-detection'
35
+ """
36
+
37
+ # Image
38
+ IMAGE_CLASSIFICATION = "image-classification"
39
+ IMAGE_SEGMENTATION = "image-segmentation"
40
+ OBJECT_DETECTION = "object-detection"
41
+ DEPTH_ESTIMATION = "depth-estimation"
42
+ IMAGE_EMBEDDING = "image-feature-extraction"
43
+ ZERO_SHOT_IMAGE_CLASSIFICATION = "zero-shot-image-classification"
44
+ ZERO_SHOT_OBJECT_DETECTION = "zero-shot-object-detection"
45
+ MASK_GENERATION = "mask-generation"
46
+ KEYPOINT_MATCHING = "keypoint-matching"
47
+
48
+ # Text
49
+ TEXT_CLASSIFICATION = "text-classification"
50
+ TOKEN_CLASSIFICATION = "token-classification"
51
+ TEXT_GENERATION = "text-generation"
52
+ TEXT2TEXT_GENERATION = "text2text-generation"
53
+ FILL_MASK = "fill-mask"
54
+ SUMMARIZATION = "summarization"
55
+ TRANSLATION = "translation"
56
+ QUESTION_ANSWERING = "question-answering"
57
+ TEXT_EMBEDDING = "feature-extraction"
58
+ ZERO_SHOT_TEXT_CLASSIFICATION = "zero-shot-classification"
59
+
60
+ # Audio
61
+ AUDIO_CLASSIFICATION = "audio-classification"
62
+ SPEECH_TO_TEXT = "automatic-speech-recognition"
63
+ TEXT_TO_AUDIO = "text-to-audio"
64
+ ZERO_SHOT_AUDIO_CLASSIFICATION = "zero-shot-audio-classification"
65
+
66
+ # Vidio
67
+ VIDEO_CLASSIFICATION = "video-classification"
68
+
69
+ # Multimodel
70
+ IMAGE_TEXT_TO_TEXT = "image-text-to-text"
71
+ DOCUMENT_QUESTION_ANSWERING = "document-question-answering"
72
+ TABLE_QUESTION_ANSWERING = "table-question-answering"
73
+
74
+ # Table
75
+ TABULAR_CLASSIFICATION = "tabular-classification"
76
+ TABULAR_REGRESSION = "tabular-regression"
77
+
78
+ # OCR
79
+ OCR = "ocr"
@@ -0,0 +1,25 @@
1
+ from singlepipe.model_types import TaskType
2
+
3
+ from .image_schemas.object_detection import (
4
+ BBox,
5
+ Detection,
6
+ ObjectDetectionInput,
7
+ ObjectDetectionOutput,
8
+ )
9
+ from .registry import InputOutputSchema, get_schemas, register
10
+
11
+ register(
12
+ TaskType.OBJECT_DETECTION,
13
+ ObjectDetectionInput,
14
+ ObjectDetectionOutput,
15
+ )
16
+
17
+ __all__ = [
18
+ "BBox",
19
+ "Detection",
20
+ "InputOutputSchema",
21
+ "ObjectDetectionInput",
22
+ "ObjectDetectionOutput",
23
+ "get_schemas",
24
+ "register",
25
+ ]
@@ -0,0 +1,40 @@
1
+ """Placeholder schemas for TaskType.AUDIO_CLASSIFICATION.
2
+
3
+ Not yet implemented. Exists to unlock ``HFAdapter`` type overloads.
4
+ Replace with real schemas when this task gains first-class support.
5
+ """
6
+
7
+ from typing import Any, Self
8
+
9
+ from pydantic import BaseModel, ConfigDict
10
+
11
+
12
+ class AudioClassificationInput(BaseModel):
13
+ """Placeholder input schema. Fields TBD."""
14
+
15
+ model_config = ConfigDict(arbitrary_types_allowed=True)
16
+
17
+ @classmethod
18
+ def from_raw(cls, raw: Any) -> Self:
19
+ raise NotImplementedError(
20
+ "AudioClassificationInput is not implemented yet."
21
+ )
22
+
23
+ def to_pipeline_input(self) -> Any:
24
+ raise NotImplementedError(
25
+ "AudioClassificationInput is not implemented yet."
26
+ )
27
+
28
+ @property
29
+ def output_context(self) -> dict[str, Any]:
30
+ return {}
31
+
32
+
33
+ class AudioClassificationOutput(BaseModel):
34
+ """Placeholder output schema. Fields TBD."""
35
+
36
+ @classmethod
37
+ def from_pipeline_output(cls, raw_output: Any, **context: Any) -> Self:
38
+ raise NotImplementedError(
39
+ "AudioClassificationOutput is not implemented yet."
40
+ )
@@ -0,0 +1,40 @@
1
+ """Placeholder schemas for TaskType.SPEECH_TO_TEXT.
2
+
3
+ Not yet implemented. Exists to unlock ``HFAdapter`` type overloads.
4
+ Replace with real schemas when this task gains first-class support.
5
+ """
6
+
7
+ from typing import Any, Self
8
+
9
+ from pydantic import BaseModel, ConfigDict
10
+
11
+
12
+ class SpeechToTextInput(BaseModel):
13
+ """Placeholder input schema. Fields TBD."""
14
+
15
+ model_config = ConfigDict(arbitrary_types_allowed=True)
16
+
17
+ @classmethod
18
+ def from_raw(cls, raw: Any) -> Self:
19
+ raise NotImplementedError(
20
+ "SpeechToTextInput is not implemented yet."
21
+ )
22
+
23
+ def to_pipeline_input(self) -> Any:
24
+ raise NotImplementedError(
25
+ "SpeechToTextInput is not implemented yet."
26
+ )
27
+
28
+ @property
29
+ def output_context(self) -> dict[str, Any]:
30
+ return {}
31
+
32
+
33
+ class SpeechToTextOutput(BaseModel):
34
+ """Placeholder output schema. Fields TBD."""
35
+
36
+ @classmethod
37
+ def from_pipeline_output(cls, raw_output: Any, **context: Any) -> Self:
38
+ raise NotImplementedError(
39
+ "SpeechToTextOutput is not implemented yet."
40
+ )