swarmauri_tool_folium 0.6.0.dev154__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.
@@ -0,0 +1,20 @@
1
+ Metadata-Version: 2.3
2
+ Name: swarmauri_tool_folium
3
+ Version: 0.6.0.dev154
4
+ Summary: This repository includes an example of a First Class Swarmauri Example.
5
+ License: Apache-2.0
6
+ Author: Jacob Stewart
7
+ Author-email: jacob@swarmauri.com
8
+ Requires-Python: >=3.10,<3.13
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: Programming Language :: Python :: 3.10
12
+ Classifier: Programming Language :: Python :: 3.11
13
+ Classifier: Programming Language :: Python :: 3.12
14
+ Requires-Dist: folium (>=0.18.0,<0.19.0)
15
+ Requires-Dist: swarmauri_base (>=0.6.0.dev154,<0.7.0)
16
+ Requires-Dist: swarmauri_core (>=0.6.0.dev154,<0.7.0)
17
+ Project-URL: Repository, http://github.com/swarmauri/swarmauri-sdk
18
+ Description-Content-Type: text/markdown
19
+
20
+ # Swarmauri Example Community Package
@@ -0,0 +1 @@
1
+ # Swarmauri Example Community Package
@@ -0,0 +1,56 @@
1
+ [tool.poetry]
2
+ name = "swarmauri_tool_folium"
3
+ version = "0.6.0.dev154"
4
+ description = "This repository includes an example of a First Class Swarmauri Example."
5
+ authors = ["Jacob Stewart <jacob@swarmauri.com>"]
6
+ license = "Apache-2.0"
7
+ readme = "README.md"
8
+ repository = "http://github.com/swarmauri/swarmauri-sdk"
9
+ classifiers = [
10
+ "License :: OSI Approved :: Apache Software License",
11
+ "Programming Language :: Python :: 3.10",
12
+ "Programming Language :: Python :: 3.11",
13
+ "Programming Language :: Python :: 3.12"
14
+ ]
15
+
16
+ [tool.poetry.dependencies]
17
+ python = ">=3.10,<3.13"
18
+
19
+ # Swarmauri
20
+ swarmauri_core = {version = "^0.6.0.dev154"}
21
+ swarmauri_base = {version = "^0.6.0.dev154"}
22
+
23
+ # Dependencies
24
+ folium = "^0.18.0"
25
+
26
+ [tool.poetry.group.dev.dependencies]
27
+ flake8 = "^7.0"
28
+ pytest = "^8.0"
29
+ pytest-asyncio = ">=0.24.0"
30
+ pytest-xdist = "^3.6.1"
31
+ pytest-json-report = "^1.5.0"
32
+ python-dotenv = "*"
33
+ requests = "^2.32.3"
34
+
35
+ [build-system]
36
+ requires = ["poetry-core>=1.0.0"]
37
+ build-backend = "poetry.core.masonry.api"
38
+
39
+ [tool.pytest.ini_options]
40
+ norecursedirs = ["combined", "scripts"]
41
+
42
+ markers = [
43
+ "test: standard test",
44
+ "unit: Unit tests",
45
+ "integration: Integration tests",
46
+ "acceptance: Acceptance tests",
47
+ "experimental: Experimental tests"
48
+ ]
49
+ log_cli = true
50
+ log_cli_level = "INFO"
51
+ log_cli_format = "%(asctime)s [%(levelname)s] %(message)s"
52
+ log_cli_date_format = "%Y-%m-%d %H:%M:%S"
53
+ asyncio_default_fixture_loop_scope = "function"
54
+
55
+ [tool.poetry.plugins."swarmauri.tools"]
56
+ FoliumTool = "swarmauri_tool_folium.FoliumTool:FoliumTool"
@@ -0,0 +1,78 @@
1
+ # standard/tools/concrete/FoliumTool.py
2
+ import folium
3
+ from typing import List, Tuple, Literal, Dict
4
+ from swarmauri_core.ComponentBase import ComponentBase
5
+ from pydantic import Field
6
+ from swarmauri_base.tools.ToolBase import ToolBase
7
+ from swarmauri_standard.tools.Parameter import Parameter
8
+ import base64
9
+ import io
10
+
11
+
12
+ @ComponentBase.register_type(ToolBase, "FoliumTool")
13
+ class FoliumTool(ToolBase):
14
+ type: Literal["FoliumTool"] = "FoliumTool"
15
+ name: str = Field("FoliumTool", description="Tool to generate maps using Folium.")
16
+ description: str = Field(
17
+ "Generates maps with markers using Folium.",
18
+ description="Description of the FoliumTool",
19
+ )
20
+
21
+ parameters: List[Parameter] = Field(
22
+ default_factory=lambda: [
23
+ Parameter(
24
+ name="map_center",
25
+ type="tuple",
26
+ description="The (latitude, longitude) center of the map.",
27
+ required=True,
28
+ ),
29
+ Parameter(
30
+ name="markers",
31
+ type="list",
32
+ description="A list of (latitude, longitude, popup) tuples for markers.",
33
+ required=False,
34
+ default=[],
35
+ ),
36
+ ]
37
+ )
38
+
39
+ def __call__(
40
+ self,
41
+ map_center: Tuple[float, float],
42
+ markers: List[Tuple[float, float, str]],
43
+ ) -> Dict[str, str]:
44
+ """
45
+ Generate a folium map with markers and return the map as a base64-encoded image.
46
+
47
+ Parameters:
48
+ map_center (Tuple[float, float]): Latitude and longitude for the map's center.
49
+ markers (List[Tuple[float, float, str]]): A list of markers, where each marker is a tuple containing latitude,
50
+ longitude, and popup text.
51
+
52
+ Returns:
53
+ Dict[str, str]: A dictionary containing the base64-encoded image of the generated map, with the key 'image_b64'.
54
+
55
+ Example:
56
+ >>> tool = FoliumTool()
57
+ >>> map_center = (40.7128, -74.0060)
58
+ >>> markers = [(40.7128, -74.0060, "Marker 1"), (40.7328, -74.0010, "Marker 2")]
59
+ >>> result = tool(map_center, markers)
60
+ >>> print(result['image_b64']) # Prints the base64 string of the map image
61
+ """
62
+ # Generate the folium map
63
+ map_ = folium.Map(location=map_center, zoom_start=13)
64
+
65
+ # Add markers to the map
66
+ for lat, lon, popup in markers:
67
+ folium.Marker(location=[lat, lon], popup=popup).add_to(map_)
68
+
69
+ # Save the map to an in-memory BytesIO object
70
+ map_img = io.BytesIO()
71
+ map_.save(map_img, close_file=False)
72
+
73
+ # Encode the map as base64
74
+ map_img.seek(0) # Go to the beginning of the BytesIO object
75
+ map_b64 = base64.b64encode(map_img.getvalue()).decode("utf-8")
76
+
77
+ # Return the encoded map as a base64 string
78
+ return {"image_b64": map_b64}
@@ -0,0 +1,14 @@
1
+ from .FoliumTool import FoliumTool
2
+
3
+ __version__ = "0.6.0.dev26"
4
+ __long_desc__ = """
5
+
6
+ # Swarmauri Folium Plugin
7
+
8
+ This repository includes a Folium of a Swarmauri Plugin.
9
+
10
+ Visit us at: https://swarmauri.com
11
+ Follow us at: https://github.com/swarmauri
12
+ Star us at: https://github.com/swarmauri/swarmauri-sdk
13
+
14
+ """