synapsai-python 0.1.0__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.
synapsai/logging.py ADDED
@@ -0,0 +1,70 @@
1
+ # Copyright 2026 SynapsAI Technologies Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ from __future__ import annotations
16
+
17
+ import logging
18
+ from typing import Optional
19
+
20
+ LOGGER_NAME = "synapsai"
21
+ logging.getLogger(LOGGER_NAME).addHandler(logging.NullHandler())
22
+
23
+
24
+ def get_logger(name: Optional[str] = None) -> logging.Logger:
25
+ """
26
+ Return a logger within the synapsai namespace.
27
+
28
+ Example:
29
+ logger = get_logger(__name__)
30
+ """
31
+ if not name:
32
+ return logging.getLogger(LOGGER_NAME)
33
+
34
+ # Ensure everything stays under synapsai.*
35
+ if name.startswith(LOGGER_NAME):
36
+ return logging.getLogger(name)
37
+
38
+ return logging.getLogger(f"{LOGGER_NAME}.{name}")
39
+
40
+
41
+ def enable_debug_logging(level: int = logging.DEBUG) -> None:
42
+ """
43
+ Convenience function for developers who want quick SDK logging.
44
+
45
+ This adds a simple StreamHandler to the synapsai logger only.
46
+ It does NOT modify global logging configuration.
47
+
48
+ Example:
49
+ import synapsai
50
+ from synapsai.logging import enable_debug_logging
51
+
52
+ enable_debug_logging()
53
+ """
54
+
55
+ logger = logging.getLogger(LOGGER_NAME)
56
+
57
+ # Avoid adding duplicate handlers
58
+ if any(isinstance(h, logging.StreamHandler) for h in logger.handlers):
59
+ logger.setLevel(level)
60
+ return
61
+
62
+ handler = logging.StreamHandler()
63
+ formatter = logging.Formatter(
64
+ fmt="%(asctime)s | %(levelname)s | %(name)s | %(message)s",
65
+ datefmt="%Y-%m-%d %H:%M:%S",
66
+ )
67
+ handler.setFormatter(formatter)
68
+
69
+ logger.addHandler(handler)
70
+ logger.setLevel(level)
synapsai/processing.py ADDED
@@ -0,0 +1,100 @@
1
+ from PIL import Image
2
+ import base64
3
+ import os
4
+ import io
5
+
6
+ def process_image_input(image):
7
+ """Process image input (file path, bytes, base64, URL, or lists of those)"""
8
+
9
+ if image is None:
10
+ return None
11
+
12
+ # Handle batched inputs
13
+ if isinstance(image, list):
14
+ return [process_image_input(img) for img in image]
15
+
16
+ # Single input handling
17
+ if isinstance(image, str):
18
+ # URL
19
+ if image.startswith(("http://", "https://")):
20
+ return image
21
+
22
+ # File path
23
+ if os.path.isfile(image):
24
+ try:
25
+ with open(image, "rb") as f:
26
+ image_bytes = f.read()
27
+ except FileNotFoundError:
28
+ raise ValueError("File not found")
29
+ return "data:image/jpeg;base64," + base64.b64encode(image_bytes).decode("utf-8")
30
+
31
+ # Assume base64
32
+ return image
33
+
34
+ if isinstance(image, bytes):
35
+ return "data:image/jpeg;base64," + base64.b64encode(image).decode("utf-8")
36
+
37
+ if isinstance(image, Image.Image):
38
+ buf = io.BytesIO()
39
+ fmt = image.format or "PNG"
40
+ image.save(buf, format=fmt)
41
+ mime = "image/png" if fmt == "PNG" else "image/jpeg"
42
+ return f"data:{mime};base64," + base64.b64encode(buf.getvalue()).decode()
43
+
44
+ raise ValueError(
45
+ "Image must be a file path, bytes, PIL.Image, URL, base64 string, or a list of these"
46
+ )
47
+
48
+ def process_audio_input(file):
49
+ """Process audio file input"""
50
+ if file is None:
51
+ return None
52
+
53
+ # Handle batched inputs
54
+ if isinstance(file, list):
55
+ return [process_audio_input(f) for f in file]
56
+
57
+ if isinstance(file, str):
58
+ # Check if it's a file path
59
+ if os.path.isfile(file):
60
+ try:
61
+ with open(file, "rb") as f:
62
+ audio_bytes = f.read()
63
+ except FileNotFoundError:
64
+ raise ValueError("File not found")
65
+ return "data:audio/wav;base64," + base64.b64encode(audio_bytes).decode("utf-8")
66
+ # Assume it's already base64 or URL
67
+ return file
68
+ elif isinstance(file, bytes):
69
+ return "data:audio/wav;base64," + base64.b64encode(file).decode("utf-8")
70
+ elif isinstance(file, io.IOBase):
71
+ return "data:audio/wav;base64," + base64.b64encode(file.read()).decode("utf-8")
72
+ else:
73
+ raise ValueError("File must be a file path, bytes, or base64 string")
74
+
75
+ def process_video_input(file):
76
+ """Process video file input"""
77
+ if file is None:
78
+ return None
79
+
80
+ # Handle batched inputs
81
+ if isinstance(file, list):
82
+ return [process_video_input(f) for f in file]
83
+
84
+ if isinstance(file, str):
85
+ # Check if it's a file path
86
+ if os.path.isfile(file):
87
+ try:
88
+ with open(file, "rb") as f:
89
+ video_bytes = f.read()
90
+ except FileNotFoundError:
91
+ raise ValueError("File not found")
92
+ return "data:video/mp4;base64," + base64.b64encode(video_bytes).decode("utf-8")
93
+ # Assume it's already base64 or URL
94
+ return file
95
+ elif isinstance(file, bytes):
96
+ return "data:video/mp4;base64," + base64.b64encode(file).decode("utf-8")
97
+ elif isinstance(file, io.IOBase):
98
+ return "data:video/mp4;base64," + base64.b64encode(file.read()).decode("utf-8")
99
+ else:
100
+ raise ValueError("File must be a file path, bytes, or base64 string")
@@ -0,0 +1,59 @@
1
+ # Copyright 2026 SynapsAI Technologies Inc.
2
+ #
3
+ # Licensed under the Apache License, Version 2.0 (the "License");
4
+ # you may not use this file except in compliance with the License.
5
+ # You may obtain a copy of the License at
6
+ #
7
+ # http://www.apache.org/licenses/LICENSE-2.0
8
+ #
9
+ # Unless required by applicable law or agreed to in writing, software
10
+ # distributed under the License is distributed on an "AS IS" BASIS,
11
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
+ # See the License for the specific language governing permissions and
13
+ # limitations under the License.
14
+
15
+ """
16
+ Resource handlers for SynapsAI client library
17
+ """
18
+
19
+ from .chat import ChatResource, AsyncChatResource
20
+ from .images import ImagesResource, AsyncImagesResource
21
+ from .videos import VideosResource, AsyncVideosResource
22
+ from .embeddings import EmbeddingsResource, AsyncEmbeddingsResource
23
+ from .audio import AudioResource, AsyncAudioResource, TranslationsResource, AsyncTranslationsResource
24
+ from .completions import CompletionsResource, AsyncCompletionsResource
25
+ from .classifications import ClassificationsResource, AsyncClassificationsResource
26
+ from .question_answering import QuestionAnsweringResource, AsyncQuestionAnsweringResource
27
+ from .models import ModelsResource, AsyncModelsResource
28
+ from .feature_extraction import FeatureExtractionResource, AsyncFeatureExtractionResource
29
+ from .fill_mask import FillMaskResource, AsyncFillMaskResource
30
+ from .rerank import RerankResource, AsyncRerankResource
31
+
32
+ __all__ = [
33
+ "ChatResource",
34
+ "AsyncChatResource",
35
+ "ImagesResource",
36
+ "AsyncImagesResource",
37
+ "VideosResource",
38
+ "AsyncVideosResource",
39
+ "EmbeddingsResource",
40
+ "AsyncEmbeddingsResource",
41
+ "AudioResource",
42
+ "AsyncAudioResource",
43
+ "TranslationsResource",
44
+ "AsyncTranslationsResource",
45
+ "CompletionsResource",
46
+ "AsyncCompletionsResource",
47
+ "ClassificationsResource",
48
+ "AsyncClassificationsResource",
49
+ "QuestionAnsweringResource",
50
+ "AsyncQuestionAnsweringResource",
51
+ "ModelsResource",
52
+ "AsyncModelsResource",
53
+ "FeatureExtractionResource",
54
+ "AsyncFeatureExtractionResource",
55
+ "FillMaskResource",
56
+ "AsyncFillMaskResource",
57
+ "RerankResource",
58
+ "AsyncRerankResource",
59
+ ]