picarta 0.1__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.
picarta/__init__.py ADDED
@@ -0,0 +1 @@
1
+ from .picarta import Picarta
picarta/picarta.py ADDED
@@ -0,0 +1,47 @@
1
+
2
+ import requests
3
+ import base64
4
+
5
+ from urllib.parse import urlparse
6
+
7
+
8
+ class Picarta:
9
+ def __init__(self, api_token, url="https://picarta.ai/classify", top_k=10):
10
+ self.api_token = api_token
11
+ self.url = url
12
+ self.top_k = top_k
13
+ self.headers = {"Content-Type": "application/json"}
14
+
15
+ def is_valid_url(self, input_str):
16
+ try:
17
+ result = urlparse(input_str)
18
+ return all([result.scheme, result.netloc])
19
+ except ValueError:
20
+ return False
21
+
22
+ def read_image(self, image_path):
23
+ with open(image_path, "rb") as image_file:
24
+ return base64.b64encode(image_file.read()).decode('utf-8')
25
+
26
+ def localize(self, img_path, center_latitude=None, center_longitude=None, radius=None):
27
+ if self.is_valid_url(img_path):
28
+ image_data = img_path
29
+ else:
30
+ image_data = self.read_image(img_path)
31
+
32
+ payload = {
33
+ "TOKEN": self.api_token,
34
+ "IMAGE": image_data,
35
+ "TOP_K": self.top_k,
36
+ "Center_LATITUDE": center_latitude,
37
+ "Center_LONGITUDE": center_longitude,
38
+ "RADIUS": radius
39
+ }
40
+
41
+ response = requests.post(self.url, headers=self.headers, json=payload)
42
+
43
+ if response.status_code == 200:
44
+ return response.json()
45
+ else:
46
+ response.raise_for_status()
47
+
@@ -0,0 +1,26 @@
1
+ Metadata-Version: 2.1
2
+ Name: picarta
3
+ Version: 0.1
4
+ Summary: A package to geolocate images from URL or local files using Picarta AI
5
+ Home-page: https://picarta.ai
6
+ Author: Picarta
7
+ Author-email: info@picarta.ai
8
+ License: UNKNOWN
9
+ Platform: UNKNOWN
10
+ Classifier: Programming Language :: Python :: 3
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Requires-Python: >=3.6
14
+ Description-Content-Type: text/markdown
15
+ Requires-Dist: requests
16
+
17
+ # Picarta
18
+
19
+ A Python package to geolocate images from URL or local files using Picarta AI.
20
+
21
+ ## Installation
22
+
23
+ ```bash
24
+ pip install picarta
25
+
26
+
@@ -0,0 +1,9 @@
1
+ picarta/__init__.py,sha256=8j7OqyVDTRbPJf9uTIFPt5t_CS3BtL8yqsm5ytPF-NM,29
2
+ picarta/picarta.py,sha256=i6S9dBWv4E8MIfMeJ5SyUB1ySSFAa_ojujjSDXdop7M,1394
3
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
4
+ tests/test_picarta.py,sha256=NnuJZZk7MoHpQLnerOybz1xJ637fzg-V1xX_u2_yuGw,771
5
+ picarta-0.1.dist-info/METADATA,sha256=yfUATHOE3UrAvATlJ_hfA0C0hTTAH9YRYrLeuxfapic,612
6
+ picarta-0.1.dist-info/WHEEL,sha256=G16H4A3IeoQmnOrYV4ueZGKSjhipXx8zc8nu9FGlvMA,92
7
+ picarta-0.1.dist-info/entry_points.txt,sha256=vfJc75l2HrbCOKwKxB0gq-rRA6mQ0eS4gneaU-vtgT8,57
8
+ picarta-0.1.dist-info/top_level.txt,sha256=Bfbv0JW0vh4serES-2RwM-RIQRhnZNYelvB3Oc1vFsA,14
9
+ picarta-0.1.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: bdist_wheel (0.37.1)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,3 @@
1
+ [console_scripts]
2
+ localize-image = picarta.picarta:main
3
+
@@ -0,0 +1,2 @@
1
+ picarta
2
+ tests
tests/__init__.py ADDED
File without changes
tests/test_picarta.py ADDED
@@ -0,0 +1,22 @@
1
+ import unittest
2
+ from picarta import Picarta
3
+
4
+ class TestPicarta(unittest.TestCase):
5
+ def setUp(self):
6
+ self.api_token = "YOUR_API_TOKEN"
7
+ self.localizer = Picarta(self.api_token)
8
+
9
+ def test_is_valid_url(self):
10
+ self.assertTrue(self.localizer.is_valid_url("https://example.com/image.jpg"))
11
+ self.assertFalse(self.localizer.is_valid_url("not_a_url"))
12
+
13
+ def test_localize_image_url(self):
14
+ result = self.localizer.localize("https://upload.wikimedia.org/wikipedia/commons/8/83/San_Gimignano_03.jpg")
15
+ self.assertIsNotNone(result)
16
+
17
+ def test_localize_image_local(self):
18
+ result = self.localizer.localize("path/to/local/image.jpg")
19
+ self.assertIsNotNone(result)
20
+
21
+ if __name__ == "__main__":
22
+ unittest.main()