meta-sam-parser 0.0.2__py3-none-any.whl
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.
- meta_sam_parser/__init__.py +99 -0
- meta_sam_parser/_errors.py +116 -0
- meta_sam_parser/_mask_codec.py +539 -0
- meta_sam_parser/_mask_conversion.py +367 -0
- meta_sam_parser/_segmentation.py +533 -0
- meta_sam_parser/_stream.py +618 -0
- meta_sam_parser/_types.py +224 -0
- meta_sam_parser/py.typed +0 -0
- meta_sam_parser-0.0.2.dist-info/METADATA +394 -0
- meta_sam_parser-0.0.2.dist-info/RECORD +12 -0
- meta_sam_parser-0.0.2.dist-info/WHEEL +4 -0
- meta_sam_parser-0.0.2.dist-info/licenses/LICENSE +61 -0
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
from ._errors import (
|
|
4
|
+
InvalidSegmentationMaskError,
|
|
5
|
+
ResponsesStreamAbortedError,
|
|
6
|
+
ResponsesStreamConsumedError,
|
|
7
|
+
ResponsesStreamError,
|
|
8
|
+
ResponsesStreamEventError,
|
|
9
|
+
ResponsesStreamFailedError,
|
|
10
|
+
ResponsesStreamLaneError,
|
|
11
|
+
ResponsesStreamParserError,
|
|
12
|
+
ResponsesStreamRefusalError,
|
|
13
|
+
ResponsesStreamSourceError,
|
|
14
|
+
)
|
|
15
|
+
from ._mask_codec import decode_mask_to_raster
|
|
16
|
+
from ._mask_conversion import RLEObject, decode_mask_to_rle, decode_mask_to_svg_path
|
|
17
|
+
from ._segmentation import image_segmentation_format, video_segmentation_format
|
|
18
|
+
from ._stream import ParsedResponsesStream, parse_responses_stream
|
|
19
|
+
from ._types import (
|
|
20
|
+
CompletedOutcome,
|
|
21
|
+
DiagnosticSeverity,
|
|
22
|
+
FrameReference,
|
|
23
|
+
ImageSegmentationResult,
|
|
24
|
+
ImageSegmentationSnapshot,
|
|
25
|
+
IncompleteOutcome,
|
|
26
|
+
IncompleteReason,
|
|
27
|
+
OutputTextLane,
|
|
28
|
+
ParserFinish,
|
|
29
|
+
ResponseFormat,
|
|
30
|
+
ResponseFormatParser,
|
|
31
|
+
ResponsesEvent,
|
|
32
|
+
ResponsesEventLike,
|
|
33
|
+
ResponseSourceOperation,
|
|
34
|
+
ResponseStreamOutcome,
|
|
35
|
+
SegmentationBoxRecord,
|
|
36
|
+
SegmentationDiagnostic,
|
|
37
|
+
SegmentationMask,
|
|
38
|
+
SegmentationMaskBounds,
|
|
39
|
+
SegmentationMaskIdentity,
|
|
40
|
+
SegmentationMaskRecord,
|
|
41
|
+
SegmentationMedia,
|
|
42
|
+
SegmentationPointRecord,
|
|
43
|
+
SegmentationRecord,
|
|
44
|
+
SegmentationResult,
|
|
45
|
+
SegmentationSnapshot,
|
|
46
|
+
SegmentationTextRecord,
|
|
47
|
+
VideoSegmentationResult,
|
|
48
|
+
VideoSegmentationSnapshot,
|
|
49
|
+
)
|
|
50
|
+
|
|
51
|
+
__all__ = [
|
|
52
|
+
"CompletedOutcome",
|
|
53
|
+
"DiagnosticSeverity",
|
|
54
|
+
"FrameReference",
|
|
55
|
+
"ImageSegmentationResult",
|
|
56
|
+
"ImageSegmentationSnapshot",
|
|
57
|
+
"IncompleteOutcome",
|
|
58
|
+
"IncompleteReason",
|
|
59
|
+
"InvalidSegmentationMaskError",
|
|
60
|
+
"OutputTextLane",
|
|
61
|
+
"ParsedResponsesStream",
|
|
62
|
+
"ParserFinish",
|
|
63
|
+
"RLEObject",
|
|
64
|
+
"ResponseFormat",
|
|
65
|
+
"ResponseFormatParser",
|
|
66
|
+
"ResponseSourceOperation",
|
|
67
|
+
"ResponseStreamOutcome",
|
|
68
|
+
"ResponsesEvent",
|
|
69
|
+
"ResponsesEventLike",
|
|
70
|
+
"ResponsesStreamAbortedError",
|
|
71
|
+
"ResponsesStreamConsumedError",
|
|
72
|
+
"ResponsesStreamError",
|
|
73
|
+
"ResponsesStreamEventError",
|
|
74
|
+
"ResponsesStreamFailedError",
|
|
75
|
+
"ResponsesStreamLaneError",
|
|
76
|
+
"ResponsesStreamParserError",
|
|
77
|
+
"ResponsesStreamRefusalError",
|
|
78
|
+
"ResponsesStreamSourceError",
|
|
79
|
+
"SegmentationBoxRecord",
|
|
80
|
+
"SegmentationDiagnostic",
|
|
81
|
+
"SegmentationMask",
|
|
82
|
+
"SegmentationMaskBounds",
|
|
83
|
+
"SegmentationMaskIdentity",
|
|
84
|
+
"SegmentationMaskRecord",
|
|
85
|
+
"SegmentationMedia",
|
|
86
|
+
"SegmentationPointRecord",
|
|
87
|
+
"SegmentationRecord",
|
|
88
|
+
"SegmentationResult",
|
|
89
|
+
"SegmentationSnapshot",
|
|
90
|
+
"SegmentationTextRecord",
|
|
91
|
+
"VideoSegmentationResult",
|
|
92
|
+
"VideoSegmentationSnapshot",
|
|
93
|
+
"decode_mask_to_raster",
|
|
94
|
+
"decode_mask_to_rle",
|
|
95
|
+
"decode_mask_to_svg_path",
|
|
96
|
+
"image_segmentation_format",
|
|
97
|
+
"parse_responses_stream",
|
|
98
|
+
"video_segmentation_format",
|
|
99
|
+
]
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
# Copyright (c) Meta Platforms, Inc. and affiliates. All Rights Reserved.
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from ._types import OutputTextLane, ResponseSourceOperation
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class ResponsesStreamError(Exception):
|
|
9
|
+
"""Base error for stable parser failures exposed by this package."""
|
|
10
|
+
|
|
11
|
+
def __init__(
|
|
12
|
+
self,
|
|
13
|
+
message: str,
|
|
14
|
+
code: str,
|
|
15
|
+
*,
|
|
16
|
+
cause: BaseException | None = None,
|
|
17
|
+
) -> None:
|
|
18
|
+
super().__init__(message)
|
|
19
|
+
self.code = code
|
|
20
|
+
self.cause = cause
|
|
21
|
+
if cause is not None:
|
|
22
|
+
self.__cause__ = cause
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
class ResponsesStreamConsumedError(ResponsesStreamError):
|
|
26
|
+
"""Raised when a parsed stream is assigned more than one consumer mode."""
|
|
27
|
+
|
|
28
|
+
def __init__(self) -> None:
|
|
29
|
+
super().__init__(
|
|
30
|
+
"A parsed response stream can be iterated only once.",
|
|
31
|
+
"stream_consumed",
|
|
32
|
+
)
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
class ResponsesStreamAbortedError(ResponsesStreamError):
|
|
36
|
+
"""Raised when explicit cleanup abandons a stream before completion."""
|
|
37
|
+
|
|
38
|
+
def __init__(self) -> None:
|
|
39
|
+
super().__init__(
|
|
40
|
+
"The parsed response stream was abandoned before completion.",
|
|
41
|
+
"stream_aborted",
|
|
42
|
+
)
|
|
43
|
+
|
|
44
|
+
|
|
45
|
+
class ResponsesStreamFailedError(ResponsesStreamError):
|
|
46
|
+
"""Raised for an official ``response.failed`` event."""
|
|
47
|
+
|
|
48
|
+
def __init__(self, message: str, event: object) -> None:
|
|
49
|
+
super().__init__(message, "response_failed")
|
|
50
|
+
self.event = event
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
class ResponsesStreamEventError(ResponsesStreamError):
|
|
54
|
+
"""Raised for an official stream ``error`` event."""
|
|
55
|
+
|
|
56
|
+
def __init__(self, message: str, event: object) -> None:
|
|
57
|
+
super().__init__(message, "response_error")
|
|
58
|
+
self.event = event
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
class ResponsesStreamLaneError(ResponsesStreamError):
|
|
62
|
+
"""Raised when output-text lane identity or ordering is inconsistent."""
|
|
63
|
+
|
|
64
|
+
def __init__(
|
|
65
|
+
self,
|
|
66
|
+
message: str,
|
|
67
|
+
expected: OutputTextLane | None,
|
|
68
|
+
received: OutputTextLane | None,
|
|
69
|
+
) -> None:
|
|
70
|
+
super().__init__(message, "response_lane")
|
|
71
|
+
self.expected = expected
|
|
72
|
+
self.received = received
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
class ResponsesStreamRefusalError(ResponsesStreamError):
|
|
76
|
+
"""Raised for an official refusal event on any content lane."""
|
|
77
|
+
|
|
78
|
+
def __init__(self, message: str, event: object) -> None:
|
|
79
|
+
super().__init__(message, "response_refusal")
|
|
80
|
+
self.event = event
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
class ResponsesStreamParserError(ResponsesStreamError):
|
|
84
|
+
"""Raised when a non-package exception escapes a response-format parser."""
|
|
85
|
+
|
|
86
|
+
def __init__(self, cause: BaseException) -> None:
|
|
87
|
+
super().__init__(
|
|
88
|
+
"The response format parser failed.",
|
|
89
|
+
"parser_error",
|
|
90
|
+
cause=cause,
|
|
91
|
+
)
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
class ResponsesStreamSourceError(ResponsesStreamError):
|
|
95
|
+
"""Raised when creating, reading, or closing the event source fails."""
|
|
96
|
+
|
|
97
|
+
def __init__(
|
|
98
|
+
self,
|
|
99
|
+
operation: ResponseSourceOperation,
|
|
100
|
+
cause: BaseException,
|
|
101
|
+
prior_error: BaseException | None = None,
|
|
102
|
+
) -> None:
|
|
103
|
+
super().__init__(
|
|
104
|
+
f"The Responses event source failed during {operation}.",
|
|
105
|
+
"source_error",
|
|
106
|
+
cause=cause,
|
|
107
|
+
)
|
|
108
|
+
self.operation = operation
|
|
109
|
+
self.prior_error = prior_error
|
|
110
|
+
|
|
111
|
+
|
|
112
|
+
class InvalidSegmentationMaskError(ResponsesStreamError):
|
|
113
|
+
"""Raised when a complete segmentation-mask payload is invalid."""
|
|
114
|
+
|
|
115
|
+
def __init__(self, message: str, *, cause: BaseException | None = None) -> None:
|
|
116
|
+
super().__init__(message, "invalid_mask_payload", cause=cause)
|