toolchemy 0.2.185__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.
Files changed (36) hide show
  1. toolchemy/__main__.py +9 -0
  2. toolchemy/ai/clients/__init__.py +20 -0
  3. toolchemy/ai/clients/common.py +429 -0
  4. toolchemy/ai/clients/dummy_model_client.py +61 -0
  5. toolchemy/ai/clients/factory.py +37 -0
  6. toolchemy/ai/clients/gemini_client.py +48 -0
  7. toolchemy/ai/clients/ollama_client.py +58 -0
  8. toolchemy/ai/clients/openai_client.py +76 -0
  9. toolchemy/ai/clients/pricing.py +66 -0
  10. toolchemy/ai/clients/whisper_client.py +141 -0
  11. toolchemy/ai/prompter.py +124 -0
  12. toolchemy/ai/trackers/__init__.py +5 -0
  13. toolchemy/ai/trackers/common.py +216 -0
  14. toolchemy/ai/trackers/mlflow_tracker.py +221 -0
  15. toolchemy/ai/trackers/neptune_tracker.py +135 -0
  16. toolchemy/db/lightdb.py +260 -0
  17. toolchemy/utils/__init__.py +19 -0
  18. toolchemy/utils/at_exit_collector.py +109 -0
  19. toolchemy/utils/cacher/__init__.py +20 -0
  20. toolchemy/utils/cacher/cacher_diskcache.py +121 -0
  21. toolchemy/utils/cacher/cacher_pickle.py +152 -0
  22. toolchemy/utils/cacher/cacher_shelve.py +196 -0
  23. toolchemy/utils/cacher/common.py +174 -0
  24. toolchemy/utils/datestimes.py +77 -0
  25. toolchemy/utils/locations.py +111 -0
  26. toolchemy/utils/logger.py +76 -0
  27. toolchemy/utils/timer.py +23 -0
  28. toolchemy/utils/utils.py +168 -0
  29. toolchemy/vision/__init__.py +5 -0
  30. toolchemy/vision/caption_overlay.py +77 -0
  31. toolchemy/vision/image.py +89 -0
  32. toolchemy-0.2.185.dist-info/METADATA +25 -0
  33. toolchemy-0.2.185.dist-info/RECORD +36 -0
  34. toolchemy-0.2.185.dist-info/WHEEL +4 -0
  35. toolchemy-0.2.185.dist-info/entry_points.txt +3 -0
  36. toolchemy-0.2.185.dist-info/licenses/LICENSE +21 -0
@@ -0,0 +1,77 @@
1
+ import os
2
+ from dataclasses import dataclass
3
+
4
+ from PIL import Image, ImageDraw, ImageFont, ImageFilter
5
+
6
+ from toolchemy.utils.locations import Locations
7
+
8
+
9
+ @dataclass
10
+ class Caption:
11
+ text: str
12
+ y: int
13
+ font: ImageFont.FreeTypeFont | None = None
14
+ font_name: str | None = None
15
+ size: int | None = None
16
+ color: tuple | None = None
17
+
18
+ def __post_init__(self):
19
+ if self.font_name is None:
20
+ self.font_name = "Pacifico.ttf"
21
+ if self.size is None:
22
+ self.size = 60
23
+ self.font = ImageFont.truetype(self.font_name, self.size)
24
+ if self.color is None:
25
+ self.color = (255, 255, 255, 255)
26
+
27
+
28
+
29
+ def add_caption(input_img_path: str, captions: list[Caption], output_img_path: str | None = None):
30
+ # fonts = ["Pacifico.ttf", "Anton.ttf"]
31
+
32
+ if output_img_path is None:
33
+ path_root, path_ext = os.path.splitext(input_img_path)
34
+ output_img_path = f"{path_root}_out{path_ext}"
35
+
36
+ img = Image.open(input_img_path).convert("RGBA")
37
+
38
+ txt = Image.new("RGBA", img.size, (255,255,255,0))
39
+ draw = ImageDraw.Draw(txt)
40
+
41
+ x_start = 50
42
+ for i, caption in enumerate(captions):
43
+ draw.text((x_start, caption.y), caption.text, font=caption.font, fill=caption.color)
44
+
45
+ glow = txt.filter(ImageFilter.GaussianBlur(5))
46
+
47
+ out = Image.alpha_composite(img.convert("RGBA"), glow)
48
+ out = Image.alpha_composite(out, txt)
49
+
50
+ out.convert("RGB").save(output_img_path)
51
+
52
+
53
+ def main():
54
+ std_text = "*bilet uprawnia do jednej soboty lub niedzieli przed kompem, czy coś :)"
55
+ std_y_pos = 1900
56
+ std_font_size = 45
57
+ locations = Locations()
58
+ font_name_pacifico = "/path/to/Pacifico-Regular.ttf"
59
+ font_name_open_sans_italic = "/path/to/OpenSans-Italic-VariableFont_wdth,wght.ttf"
60
+ bottom_font_name = font_name_open_sans_italic
61
+ month_font_name = font_name_open_sans_italic
62
+ add_caption(locations.in_data("kima1.jpg"), captions=[
63
+ Caption(text="Lorem ipsum", y=30, size=100, font_name=font_name_pacifico),
64
+ Caption(text="dolor sit amet, consectetur adipiscing elit, sed do eiusmod", y=210, size=90, font_name=font_name_pacifico),
65
+ Caption(text="tempor incididunt ut labore et dolore magna aliqua.", y=390, size=60, font_name=month_font_name),
66
+ Caption(text=std_text, y=std_y_pos-300, size=std_font_size, font_name=bottom_font_name),
67
+ ])
68
+ add_caption(locations.in_data("kima2.jpg"), captions=[
69
+ Caption(text="Ut enim ad minim veniam,", y=30, size=100, font_name=font_name_pacifico),
70
+ Caption(text="quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.", y=210, size=90,
71
+ font_name=font_name_pacifico),
72
+ Caption(text=std_text, y=std_y_pos, size=std_font_size, font_name=bottom_font_name),
73
+ ])
74
+
75
+
76
+ if __name__ == "__main__":
77
+ main()
@@ -0,0 +1,89 @@
1
+ import base64
2
+ from PIL import Image, UnidentifiedImageError
3
+ from io import BytesIO
4
+
5
+ from toolchemy.utils.logger import get_logger
6
+
7
+
8
+ class UnknownImageFormatError(Exception):
9
+ pass
10
+
11
+
12
+ class ImageProcessor:
13
+ def __init__(self, image_path: str):
14
+ self._logger = get_logger()
15
+ self._img = None
16
+ self._image_path = image_path
17
+
18
+ @property
19
+ def img(self) -> Image.Image:
20
+ self._open()
21
+ return self._img
22
+
23
+ @property
24
+ def base64(self) -> str:
25
+ self._open()
26
+ buffered = BytesIO()
27
+ self._img.save(buffered, format=self._img.format) # Save as JPEG in memory
28
+ img_bytes = buffered.getvalue()
29
+ return base64.b64encode(img_bytes).decode('utf-8')
30
+
31
+ def metadata(self) -> dict:
32
+ self._open()
33
+
34
+ img_file = BytesIO()
35
+ self._img.save(img_file, self._img.format)
36
+
37
+ metadata = {
38
+ "width": self._img.width,
39
+ "height": self._img.height,
40
+ "size_bytes": img_file.tell(),
41
+ "format": self._img.format,
42
+ "format_description": self._img.format_description,
43
+ "filename": self._img.filename,
44
+ }
45
+
46
+ return metadata
47
+
48
+ def scale(self, max_edge_len: int, upscale: bool = False):
49
+ cur_w = self._img.width
50
+ cur_h = self._img.height
51
+
52
+ self._logger.info(f"> size (w, h): ({cur_w}, {cur_h})")
53
+
54
+ if cur_h > cur_w:
55
+ resize_ratio = cur_h / max_edge_len
56
+ else:
57
+ resize_ratio = cur_w / max_edge_len
58
+
59
+ self._logger.info(f"> resize ratio: {resize_ratio}")
60
+
61
+ if resize_ratio <= 1.0 and not upscale:
62
+ self._logger.info(f"upscaling disabled, skipping")
63
+ return
64
+
65
+ new_h = int(cur_h // resize_ratio)
66
+ new_w = int(cur_w // resize_ratio)
67
+
68
+ self._logger.info(f"> new size (w, h): ({new_w}, {new_h})")
69
+
70
+ self._img = self._img.resize((new_w, new_h))
71
+
72
+ def __enter__(self):
73
+ self._open()
74
+ return self
75
+
76
+ def __exit__(self, exc_type, exc_value, traceback):
77
+ self._close()
78
+
79
+ def _open(self):
80
+ if self._img is None:
81
+ try:
82
+ self._img = Image.open(self._image_path)
83
+ except UnidentifiedImageError as e:
84
+ raise UnknownImageFormatError(str(e))
85
+
86
+ def _close(self):
87
+ if self._img:
88
+ self._img.close()
89
+ self._img = None
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: toolchemy
3
+ Version: 0.2.185
4
+ Summary: a set of auxiliary programming tools
5
+ License-File: LICENSE
6
+ Author: Cyprian Nosek
7
+ Author-email: cyprian.nosek@protonmail.com
8
+ Requires-Python: >=3.12,<3.13
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Programming Language :: Python :: 3.12
11
+ Requires-Dist: colorlog (>=6.10.1,<7.0.0)
12
+ Requires-Dist: diskcache (>=5.6.3,<6.0.0)
13
+ Requires-Dist: google-genai (>=1.55.0,<2.0.0)
14
+ Requires-Dist: jsonschema (>=4.26.0,<5.0.0)
15
+ Requires-Dist: mlflow (>=3.8.1,<4.0.0)
16
+ Requires-Dist: neptune-scale (>=0.13.0,<0.14.0)
17
+ Requires-Dist: numpy (==2.0.2)
18
+ Requires-Dist: ollama (>=0.6.0,<0.7.0)
19
+ Requires-Dist: openai (>=1.82.1,<2.0.0)
20
+ Requires-Dist: pillow (>=11.2.1,<12.0.0)
21
+ Requires-Dist: python-dateutil (>=2.9.0.post0,<3.0.0)
22
+ Requires-Dist: tenacity (>=9.1.2,<10.0.0)
23
+ Requires-Dist: tinydb (>=4.8.2,<5.0.0)
24
+ Requires-Dist: torch (>=2.7.0,<3.0.0)
25
+ Requires-Dist: wyoming (>=1.7.1,<2.0.0)
@@ -0,0 +1,36 @@
1
+ toolchemy/__main__.py,sha256=WSJ1UlOGt4ZcWWGB7HRAdeAFcna0Dx7hhiWCi7QjCqM,163
2
+ toolchemy/ai/clients/__init__.py,sha256=MaTGkzEWZL6BVhgAdd2zfFc9bzYD5p8DRYIc2m_hbus,640
3
+ toolchemy/ai/clients/common.py,sha256=Ccb3Y1jNZUxtburSk5kddO8rrnaBjgxKtAADlb1WLV8,18943
4
+ toolchemy/ai/clients/dummy_model_client.py,sha256=hBCVzXFfV61OYdgU4hIJNIxlm9-w63ME-jfQyTo1GFg,2417
5
+ toolchemy/ai/clients/factory.py,sha256=xMGfaagJ3D-yEksKRouwQ4bHMpVMrFergbRDrs7d9QU,1953
6
+ toolchemy/ai/clients/gemini_client.py,sha256=oUnMXtdRqTY-xpIsuFKtyiXmdsIcX92IEIgeVEGUDK4,2486
7
+ toolchemy/ai/clients/ollama_client.py,sha256=_PYI_udyTBmtKZlvRECzeWKrrR-NwTlaGJS_1COMmok,3152
8
+ toolchemy/ai/clients/openai_client.py,sha256=20Yt8azldRzbd8ylKqoD5frIEj8LhScjSYhGCt0WcWk,3611
9
+ toolchemy/ai/clients/pricing.py,sha256=FuAuarQIaLl-e6KLzLbiWawWpqjY_kV4poO_qiTuHfA,1953
10
+ toolchemy/ai/clients/whisper_client.py,sha256=AQcY2FiGLu0JTYw0zzjjH-7WyZ6NbQWrtxFa6iYhR4M,5252
11
+ toolchemy/ai/prompter.py,sha256=vp6IrCu3c8IJmXGzVjFjOWdf3EvnUW0Z1Bn5STHAIbs,4933
12
+ toolchemy/ai/trackers/__init__.py,sha256=FUv2NuGSmCpDrbE7rmeG0VmQr9rJRC-Y_D0MuQa0e-M,214
13
+ toolchemy/ai/trackers/common.py,sha256=Y8_QHD1BAsJcBEHAekO-0Txe2MeBwGqh9TM53Ta49qk,6202
14
+ toolchemy/ai/trackers/mlflow_tracker.py,sha256=fVX3YdNEDs9aS5UhlY4boaAsz2ArKnawrhLKli0AS2s,8627
15
+ toolchemy/ai/trackers/neptune_tracker.py,sha256=vNvPzfrqqi7tRCfBadB-4VWobE5JR1i6ae23SQQC7I0,4639
16
+ toolchemy/db/lightdb.py,sha256=Bp7AimIuOfp2jIORFvBndk8kuKnEV12Ua1hoQXR5brY,9377
17
+ toolchemy/utils/__init__.py,sha256=6Mp65G6Ce_zY86AxvjyzkMjU_e8cbeij7TTHYqLwO0U,574
18
+ toolchemy/utils/at_exit_collector.py,sha256=YXupFjnujFK86n7dxH1Qol_i7FjNXJyo2q5f4SA3OEU,3682
19
+ toolchemy/utils/cacher/__init__.py,sha256=onsfc6z_rPQeo2rA3Ckwf8prtzg7wzEp_JE2cTEgyBI,430
20
+ toolchemy/utils/cacher/cacher_diskcache.py,sha256=mgZwy3lmgK3-22qGOfl35VX3ZFfRy-1JC8dmHK7Hjbc,4714
21
+ toolchemy/utils/cacher/cacher_pickle.py,sha256=totHrA39WrLmuW8AGg584YHx_FYoYSopCvmWyfTxrxg,6531
22
+ toolchemy/utils/cacher/cacher_shelve.py,sha256=9ywARTqVHVlRwKETF0oOQXXnHd6QSekkKBJIl8L0r1M,7352
23
+ toolchemy/utils/cacher/common.py,sha256=xOD6NlYxNJlhSKQAYhwTZmgU8YhzXmG8DjfDrlIPTL4,5028
24
+ toolchemy/utils/datestimes.py,sha256=jt2L26WwuST8tfieDuhajgr24mkA6INC5ae-kYGRfIw,2586
25
+ toolchemy/utils/locations.py,sha256=ql63bI_oPeuqGeUPYnqLCi-TMqO0o2LM3Ibe_S62PIc,3966
26
+ toolchemy/utils/logger.py,sha256=VxR_Chr-3aWnTJ7NtwrN7bvznmlO--NCgy2eWwB-lkE,2463
27
+ toolchemy/utils/timer.py,sha256=sQzGnxlPgAC8bxS0ROHKVCNctUFAP6b5UJcsM9Q-__w,596
28
+ toolchemy/utils/utils.py,sha256=JCRNRBJ4vRWzl-GtbetJs8GM72ImVAbDkPIXrvp3IE0,5167
29
+ toolchemy/vision/__init__.py,sha256=p-sQaVd1FUQ1LMGdF51y28Z9IJvMVWaCdvrL0-jKDgc,141
30
+ toolchemy/vision/caption_overlay.py,sha256=fLxHMD7IPSh5XJC5pvdPf1wZvHidlOvnXt_wgW7UJjk,2825
31
+ toolchemy/vision/image.py,sha256=5q7MRK2SEyqWPB62duuzJqGmqBfQP1Tgphu01nP7O8s,2392
32
+ toolchemy-0.2.185.dist-info/METADATA,sha256=wJElgbNStdDSNOu1GnJR4WyA26XSyBAVsXiCnUxEzzg,942
33
+ toolchemy-0.2.185.dist-info/WHEEL,sha256=3ny-bZhpXrU6vSQ1UPG34FoxZBp3lVcvK0LkgUz6VLk,88
34
+ toolchemy-0.2.185.dist-info/entry_points.txt,sha256=6l1k81pMAx7Ap1FaX8qW8SDwsONnNLOb28QQD9t6gto,66
35
+ toolchemy-0.2.185.dist-info/licenses/LICENSE,sha256=JY5EPk3yvwZqQHk8JrQ-TFARdyfVTK9uUKV6CuKo_Bs,1062
36
+ toolchemy-0.2.185.dist-info/RECORD,,
@@ -0,0 +1,4 @@
1
+ Wheel-Version: 1.0
2
+ Generator: poetry-core 2.3.0
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ prompt-studio=toolchemy.ai.prompter:run_studio
3
+
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 cypis
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
10
+ furnished 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.