sinapsis-generic-data-tools 0.1.8__tar.gz → 0.1.9__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.8/src/sinapsis_generic_data_tools.egg-info → sinapsis_generic_data_tools-0.1.9}/PKG-INFO +1 -1
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/pyproject.toml +1 -1
- sinapsis_generic_data_tools-0.1.9/src/sinapsis_generic_data_tools/helpers/audio_encoder.py +16 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/helpers/encode_img_base64.py +14 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/templates/image_color_conversion_np.py +11 -1
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/templates/text_content_filter.py +14 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9/src/sinapsis_generic_data_tools.egg-info}/PKG-INFO +1 -1
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools.egg-info/SOURCES.txt +1 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/LICENSE +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/README.md +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/setup.cfg +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/__init__.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/helpers/__init__.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/helpers/file_downloader.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/helpers/image_color_space_converter.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/helpers/image_color_space_converter_cv.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/helpers/image_color_space_converter_torch.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/helpers/tags.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/templates/__init__.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/templates/image_color_conversion.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/templates/mask_non_roi.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/templates/packet_buffer_queue.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools/templates/source_history_aggregator.py +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools.egg-info/dependency_links.txt +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools.egg-info/requires.txt +0 -0
- {sinapsis_generic_data_tools-0.1.8 → sinapsis_generic_data_tools-0.1.9}/src/sinapsis_generic_data_tools.egg-info/top_level.txt +0 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# -*- coding: utf-8 -*-
|
|
2
|
+
from io import BytesIO
|
|
3
|
+
|
|
4
|
+
import numpy as np
|
|
5
|
+
from pydub import AudioSegment
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
def audio_bytes_to_numpy(audio_bytes: bytes) -> tuple[np.ndarray, int]:
|
|
9
|
+
audio = AudioSegment.from_file(BytesIO(audio_bytes), format="mp3")
|
|
10
|
+
|
|
11
|
+
samples = np.array(audio.get_array_of_samples())
|
|
12
|
+
|
|
13
|
+
if audio.channels == 2:
|
|
14
|
+
samples = samples.reshape((-1, 2))
|
|
15
|
+
|
|
16
|
+
return samples, audio.frame_rate
|
|
@@ -3,6 +3,7 @@ import base64
|
|
|
3
3
|
from io import BytesIO
|
|
4
4
|
|
|
5
5
|
import numpy as np
|
|
6
|
+
import requests # type:ignore[import-untyped]
|
|
6
7
|
from PIL import Image
|
|
7
8
|
|
|
8
9
|
|
|
@@ -26,3 +27,16 @@ def convert_image_ndarray_to_base64(np_image: np.ndarray, image_format: str = "J
|
|
|
26
27
|
base64_encoded_data = base64.b64encode(binary_data)
|
|
27
28
|
|
|
28
29
|
return base64_encoded_data.decode("utf-8")
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
def decode_base64_to_numpy(base64_str: str) -> np.ndarray:
|
|
33
|
+
image_bytes = base64.b64decode(base64_str)
|
|
34
|
+
image = Image.open(BytesIO(image_bytes)).convert("RGB")
|
|
35
|
+
return np.array(image)
|
|
36
|
+
|
|
37
|
+
|
|
38
|
+
def fetch_url_to_numpy(url: str) -> np.ndarray:
|
|
39
|
+
response = requests.get(url)
|
|
40
|
+
response.raise_for_status()
|
|
41
|
+
image = Image.open(BytesIO(response.content)).convert("RGB")
|
|
42
|
+
return np.array(image)
|
|
@@ -4,9 +4,14 @@ from sinapsis_core.data_containers.data_packet import (
|
|
|
4
4
|
ImageColor,
|
|
5
5
|
)
|
|
6
6
|
from sinapsis_core.template_base import Template
|
|
7
|
-
from sinapsis_core.template_base.base_models import
|
|
7
|
+
from sinapsis_core.template_base.base_models import (
|
|
8
|
+
OutputTypes,
|
|
9
|
+
TemplateAttributes,
|
|
10
|
+
UIPropertiesMetadata,
|
|
11
|
+
)
|
|
8
12
|
|
|
9
13
|
from sinapsis_generic_data_tools.helpers.image_color_space_converter_cv import convert_color_space_cv
|
|
14
|
+
from sinapsis_generic_data_tools.helpers.tags import Tags
|
|
10
15
|
|
|
11
16
|
|
|
12
17
|
class ImageColorConversionNumpy(Template):
|
|
@@ -30,6 +35,11 @@ class ImageColorConversionNumpy(Template):
|
|
|
30
35
|
target_color_space: 2
|
|
31
36
|
"""
|
|
32
37
|
|
|
38
|
+
UIProperties = UIPropertiesMetadata(
|
|
39
|
+
output_type=OutputTypes.IMAGE,
|
|
40
|
+
tags=[Tags.COLOR, Tags.CONVERSION, Tags.IMAGE, Tags.SPACE],
|
|
41
|
+
)
|
|
42
|
+
|
|
33
43
|
class AttributesBaseModel(TemplateAttributes):
|
|
34
44
|
"""Defines the attributes required for the ColorConversion template.
|
|
35
45
|
|
|
@@ -9,6 +9,17 @@ from sinapsis_core.template_base.template import Template
|
|
|
9
9
|
STOPWORDS = {"and", "the", "or", "is", "in", "to", "of", "a"}
|
|
10
10
|
|
|
11
11
|
|
|
12
|
+
|
|
13
|
+
def has_repetitive_chars(word: str) -> bool:
|
|
14
|
+
"""Detect if a single character is repeated excessively in a word."""
|
|
15
|
+
count = 1
|
|
16
|
+
for i in range(1, len(word)):
|
|
17
|
+
if word[i] == word[i - 1]:
|
|
18
|
+
count += 1
|
|
19
|
+
if count >= 5:
|
|
20
|
+
return True
|
|
21
|
+
return False
|
|
22
|
+
|
|
12
23
|
def is_logical(
|
|
13
24
|
text: str, repeat_threshold: int = 10, unique_ratio_threshold: float = 0.1, window_size: int = 20
|
|
14
25
|
) -> bool:
|
|
@@ -32,6 +43,9 @@ def is_logical(
|
|
|
32
43
|
for word, count in counts.items():
|
|
33
44
|
if word not in STOPWORDS and count > repeat_threshold:
|
|
34
45
|
return False
|
|
46
|
+
for word in words:
|
|
47
|
+
if has_repetitive_chars(word):
|
|
48
|
+
return False
|
|
35
49
|
return True
|
|
36
50
|
|
|
37
51
|
|
|
@@ -8,6 +8,7 @@ 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/audio_encoder.py
|
|
11
12
|
src/sinapsis_generic_data_tools/helpers/encode_img_base64.py
|
|
12
13
|
src/sinapsis_generic_data_tools/helpers/file_downloader.py
|
|
13
14
|
src/sinapsis_generic_data_tools/helpers/image_color_space_converter.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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|