sinapsis-generic-data-tools 0.1.4__tar.gz → 0.1.5__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.
- {sinapsis_generic_data_tools-0.1.4/src/sinapsis_generic_data_tools.egg-info → sinapsis_generic_data_tools-0.1.5}/PKG-INFO +3 -1
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/pyproject.toml +6 -1
- sinapsis_generic_data_tools-0.1.5/src/sinapsis_generic_data_tools/helpers/encode_img_base64.py +28 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/helpers/file_downloader.py +1 -1
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/templates/__init__.py +1 -0
- sinapsis_generic_data_tools-0.1.5/src/sinapsis_generic_data_tools/templates/source_history_aggregator.py +75 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5/src/sinapsis_generic_data_tools.egg-info}/PKG-INFO +3 -1
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools.egg-info/SOURCES.txt +3 -1
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools.egg-info/requires.txt +3 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/LICENSE +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/README.md +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/setup.cfg +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/__init__.py +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/helpers/__init__.py +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/helpers/image_color_space_converter.py +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/templates/image_color_conversion.py +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/templates/mask_non_roi.py +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools/templates/packet_buffer_queue.py +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools.egg-info/dependency_links.txt +0 -0
- {sinapsis_generic_data_tools-0.1.4 → sinapsis_generic_data_tools-0.1.5}/src/sinapsis_generic_data_tools.egg-info/top_level.txt +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sinapsis-generic-data-tools
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Collection of generic data tools
|
|
5
5
|
Author-email: SinapsisAI <dev@sinapsis.tech>
|
|
6
6
|
Project-URL: Homepage, https://sinapsis.tech
|
|
@@ -12,6 +12,8 @@ Description-Content-Type: text/markdown
|
|
|
12
12
|
License-File: LICENSE
|
|
13
13
|
Requires-Dist: requests>=2.32.3
|
|
14
14
|
Requires-Dist: sinapsis>=0.1.1
|
|
15
|
+
Provides-Extra: pillow
|
|
16
|
+
Requires-Dist: pillow>=11.2.1; extra == "pillow"
|
|
15
17
|
Dynamic: license-file
|
|
16
18
|
|
|
17
19
|
<h1 align="center">
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "sinapsis-generic-data-tools"
|
|
3
|
-
version = "0.1.
|
|
3
|
+
version = "0.1.5"
|
|
4
4
|
description = "Collection of generic data tools"
|
|
5
5
|
authors = [{ name = "SinapsisAI", email = "dev@sinapsis.tech" }]
|
|
6
6
|
|
|
@@ -27,3 +27,8 @@ Homepage = "https://sinapsis.tech"
|
|
|
27
27
|
Documentation = "https://docs.sinapsis.tech/docs"
|
|
28
28
|
Tutorials = "https://docs.sinapsis.tech/tutorials"
|
|
29
29
|
Repository = "https://github.com/Sinapsis-AI/sinapsis-data-tools.git"
|
|
30
|
+
|
|
31
|
+
[project.optional-dependencies]
|
|
32
|
+
pillow = [
|
|
33
|
+
"pillow>=11.2.1",
|
|
34
|
+
]
|
sinapsis_generic_data_tools-0.1.5/src/sinapsis_generic_data_tools/helpers/encode_img_base64.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
import base64
|
|
3
|
+
from io import BytesIO
|
|
4
|
+
|
|
5
|
+
import numpy as np
|
|
6
|
+
from PIL import Image
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def convert_image_ndarray_to_base64(np_image: np.ndarray, image_format: str = "JPEG") -> str:
|
|
10
|
+
"""
|
|
11
|
+
Convert a numpy array image to a base64 encoded string using Pillow.
|
|
12
|
+
|
|
13
|
+
Args:
|
|
14
|
+
np_image (np.ndarray): The image represented as a numpy array.
|
|
15
|
+
image_format (str): The image format for encoding ('JPEG', 'PNG', etc.)
|
|
16
|
+
|
|
17
|
+
Returns:
|
|
18
|
+
str: The base64 encoded image string.
|
|
19
|
+
"""
|
|
20
|
+
pil_image = Image.fromarray(np_image)
|
|
21
|
+
|
|
22
|
+
with BytesIO() as buffered:
|
|
23
|
+
pil_image.save(buffered, format=image_format)
|
|
24
|
+
binary_data = buffered.getvalue()
|
|
25
|
+
|
|
26
|
+
base64_encoded_data = base64.b64encode(binary_data)
|
|
27
|
+
|
|
28
|
+
return base64_encoded_data.decode("utf-8")
|
|
@@ -24,4 +24,4 @@ def download_file(url: str, output_path: str, description: str | None = None) ->
|
|
|
24
24
|
f.write(chunk)
|
|
25
25
|
sinapsis_logger.info(f"{description or 'File'} download completed successfully.")
|
|
26
26
|
else:
|
|
27
|
-
raise RuntimeError(f"Failed to download {description or 'file'}. HTTP status code: {response.status_code}")
|
|
27
|
+
raise RuntimeError(f"Failed to download {description or 'file'}. HTTP status code: {response.status_code}")
|
|
@@ -8,6 +8,7 @@ _template_lookup = {
|
|
|
8
8
|
"ImageColorConversion": f"{_root_lib_path}.image_color_conversion",
|
|
9
9
|
"MaskNonROIs": f"{_root_lib_path}.mask_non_roi",
|
|
10
10
|
"PacketBufferQueue": f"{_root_lib_path}.packet_buffer_queue",
|
|
11
|
+
"SourceHistoryAggregator": f"{_root_lib_path}.source_history_aggregator",
|
|
11
12
|
}
|
|
12
13
|
|
|
13
14
|
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from collections import deque
|
|
3
|
+
from typing import Any, Literal
|
|
4
|
+
|
|
5
|
+
from sinapsis_core.data_containers.data_packet import DataContainer
|
|
6
|
+
from sinapsis_core.template_base.template import Template, TemplateAttributes, TemplateAttributeType
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class SourceHistoryAggregator(Template):
|
|
10
|
+
"""Template to store story or content of packets in the generic_field as a deque.
|
|
11
|
+
The number of inputs in the queue is set through the attributes in the template.
|
|
12
|
+
|
|
13
|
+
Usage example:
|
|
14
|
+
|
|
15
|
+
agent:
|
|
16
|
+
name: my_test_agent
|
|
17
|
+
templates:
|
|
18
|
+
- template_name: InputTemplate
|
|
19
|
+
class_name: InputTemplate
|
|
20
|
+
attributes: {}
|
|
21
|
+
- template_name: SourceHistoryAggregator
|
|
22
|
+
class_name: SourceHistoryAggregator
|
|
23
|
+
template_input: InputTemplate
|
|
24
|
+
attributes:
|
|
25
|
+
packet_to_extract_from: texts
|
|
26
|
+
context_max_length: 5
|
|
27
|
+
"""
|
|
28
|
+
|
|
29
|
+
class AttributesBaseModel(TemplateAttributes):
|
|
30
|
+
packet_to_extract_from: Literal["audios", "images", "texts", "generic_data", "time_series", "binary_data"] = (
|
|
31
|
+
"texts"
|
|
32
|
+
)
|
|
33
|
+
context_max_length: int = 5
|
|
34
|
+
|
|
35
|
+
def __init__(self, attributes: TemplateAttributeType) -> None:
|
|
36
|
+
super().__init__(attributes)
|
|
37
|
+
|
|
38
|
+
self.history_tracker: dict[str | int, deque] = {}
|
|
39
|
+
|
|
40
|
+
def fetch_source_history(self, source_id: str | int) -> deque | None:
|
|
41
|
+
"""This method returns the source history based on the id of the history.
|
|
42
|
+
Args:
|
|
43
|
+
source_id (str | int): Source identification for the history
|
|
44
|
+
Returns:
|
|
45
|
+
the deque corresponding to the source_id
|
|
46
|
+
"""
|
|
47
|
+
return self.history_tracker.get(source_id, None)
|
|
48
|
+
|
|
49
|
+
def append_source_history(self, source_id: str | int, content: Any) -> None:
|
|
50
|
+
"""Adds a new entry to the source_id history
|
|
51
|
+
Args:
|
|
52
|
+
source_id (str | int): Source identification for the history
|
|
53
|
+
content (Any): Content of the packet to be added to the queue
|
|
54
|
+
"""
|
|
55
|
+
if not self.history_tracker.get(source_id, False):
|
|
56
|
+
self.history_tracker[source_id] = deque(maxlen=self.attributes.context_max_length)
|
|
57
|
+
self.history_tracker[source_id].append(content)
|
|
58
|
+
|
|
59
|
+
def reset_history(self, source_id: str | int) -> None:
|
|
60
|
+
"""Method to reset the history of a given source"""
|
|
61
|
+
self.history_tracker[source_id] = deque(maxlen=self.attributes.context_max_length)
|
|
62
|
+
|
|
63
|
+
def execute(self, container: DataContainer) -> DataContainer:
|
|
64
|
+
packets = getattr(container, self.attributes.packet_to_extract_from)
|
|
65
|
+
source = ""
|
|
66
|
+
for packet in packets:
|
|
67
|
+
source = packet.source
|
|
68
|
+
content = packet.content
|
|
69
|
+
self.append_source_history(source, content)
|
|
70
|
+
|
|
71
|
+
full_history = self.fetch_source_history(source)
|
|
72
|
+
self.logger.critical(f"This is the full context: {full_history}")
|
|
73
|
+
if full_history:
|
|
74
|
+
self._set_generic_data(container, full_history)
|
|
75
|
+
return container
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: sinapsis-generic-data-tools
|
|
3
|
-
Version: 0.1.
|
|
3
|
+
Version: 0.1.5
|
|
4
4
|
Summary: Collection of generic data tools
|
|
5
5
|
Author-email: SinapsisAI <dev@sinapsis.tech>
|
|
6
6
|
Project-URL: Homepage, https://sinapsis.tech
|
|
@@ -12,6 +12,8 @@ Description-Content-Type: text/markdown
|
|
|
12
12
|
License-File: LICENSE
|
|
13
13
|
Requires-Dist: requests>=2.32.3
|
|
14
14
|
Requires-Dist: sinapsis>=0.1.1
|
|
15
|
+
Provides-Extra: pillow
|
|
16
|
+
Requires-Dist: pillow>=11.2.1; extra == "pillow"
|
|
15
17
|
Dynamic: license-file
|
|
16
18
|
|
|
17
19
|
<h1 align="center">
|
|
@@ -8,9 +8,11 @@ src/sinapsis_generic_data_tools.egg-info/dependency_links.txt
|
|
|
8
8
|
src/sinapsis_generic_data_tools.egg-info/requires.txt
|
|
9
9
|
src/sinapsis_generic_data_tools.egg-info/top_level.txt
|
|
10
10
|
src/sinapsis_generic_data_tools/helpers/__init__.py
|
|
11
|
+
src/sinapsis_generic_data_tools/helpers/encode_img_base64.py
|
|
11
12
|
src/sinapsis_generic_data_tools/helpers/file_downloader.py
|
|
12
13
|
src/sinapsis_generic_data_tools/helpers/image_color_space_converter.py
|
|
13
14
|
src/sinapsis_generic_data_tools/templates/__init__.py
|
|
14
15
|
src/sinapsis_generic_data_tools/templates/image_color_conversion.py
|
|
15
16
|
src/sinapsis_generic_data_tools/templates/mask_non_roi.py
|
|
16
|
-
src/sinapsis_generic_data_tools/templates/packet_buffer_queue.py
|
|
17
|
+
src/sinapsis_generic_data_tools/templates/packet_buffer_queue.py
|
|
18
|
+
src/sinapsis_generic_data_tools/templates/source_history_aggregator.py
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|