mixpeek 0.7.2__py3-none-any.whl → 0.8.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.
- mixpeek/client.py +3 -1
- mixpeek/endpoints/index.py +24 -19
- mixpeek/endpoints/register.py +34 -0
- mixpeek/endpoints/tasks.py +26 -0
- mixpeek/endpoints/tools.py +32 -0
- {mixpeek-0.7.2.dist-info → mixpeek-0.8.0.dist-info}/METADATA +2 -1
- mixpeek-0.8.0.dist-info/RECORD +15 -0
- {mixpeek-0.7.2.dist-info → mixpeek-0.8.0.dist-info}/WHEEL +1 -1
- mixpeek-0.7.2.dist-info/RECORD +0 -13
- {mixpeek-0.7.2.dist-info → mixpeek-0.8.0.dist-info}/top_level.txt +0 -0
mixpeek/client.py
CHANGED
@@ -5,6 +5,7 @@ from .endpoints.collections import Collections
|
|
5
5
|
from .endpoints.index import Index
|
6
6
|
from .endpoints.search import Search
|
7
7
|
from .endpoints.tools import Tools
|
8
|
+
from .endpoints.register import Register
|
8
9
|
|
9
10
|
|
10
11
|
class Mixpeek:
|
@@ -20,6 +21,7 @@ class Mixpeek:
|
|
20
21
|
self.collections = Collections(self.base_url, self.headers)
|
21
22
|
self.index = Index(self.base_url, self.headers)
|
22
23
|
self.search = Search(self.base_url, self.headers)
|
24
|
+
self.register = Register(self.base_url, self.headers)
|
23
25
|
|
24
26
|
# tools is all local
|
25
|
-
self.tools = Tools()
|
27
|
+
self.tools = Tools()
|
mixpeek/endpoints/index.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
import requests
|
2
|
+
from .tasks import Task
|
2
3
|
|
3
4
|
class Index:
|
4
5
|
def __init__(self, base_url, headers):
|
@@ -12,33 +13,37 @@ class Index:
|
|
12
13
|
base_data["settings"] = settings
|
13
14
|
return base_data
|
14
15
|
|
15
|
-
# def upload(self, file, collection_id, metadata=None, settings=None):
|
16
|
-
# try:
|
17
|
-
# api_url = f"{self.base_url}index/upload"
|
18
|
-
# files = {"file": file}
|
19
|
-
# data = self._prepare_data({"collection_id": collection_id}, metadata, settings)
|
20
|
-
# response = requests.post(api_url, files=files, data=data, headers=self.headers)
|
21
|
-
# response.raise_for_status()
|
22
|
-
# return response.json()
|
23
|
-
# except requests.RequestException as e:
|
24
|
-
# return {"error": str(e)}
|
25
|
-
|
26
16
|
def url(self, target_url, collection_id, metadata=None, settings=None):
|
27
17
|
try:
|
28
18
|
endpoint = f"{self.base_url}index/url"
|
29
19
|
data = self._prepare_data({"url": target_url, "collection_id": collection_id}, metadata, settings)
|
20
|
+
|
30
21
|
response = requests.post(endpoint, json=data, headers=self.headers)
|
31
22
|
response.raise_for_status()
|
32
|
-
|
23
|
+
task_id = response.json().get("task_id")
|
24
|
+
if task_id:
|
25
|
+
return Task(self.base_url, self.headers, task_id)
|
26
|
+
else:
|
27
|
+
return response.json()
|
33
28
|
except requests.RequestException as e:
|
34
29
|
return {"error": str(e)}
|
35
|
-
|
36
|
-
def
|
30
|
+
|
31
|
+
def upload(self, file_path, collection_id, metadata=None, settings=None):
|
37
32
|
try:
|
38
|
-
|
39
|
-
data = self._prepare_data({"
|
40
|
-
|
33
|
+
endpoint = f"{self.base_url}index/upload"
|
34
|
+
data = self._prepare_data({"collection_id": collection_id}, metadata, settings)
|
35
|
+
|
36
|
+
with open(file_path, 'rb') as file:
|
37
|
+
files = [('file', (file.name, file, 'application/octet-stream'))]
|
38
|
+
response = requests.post(endpoint, headers=self.headers, data=data, files=files)
|
39
|
+
|
41
40
|
response.raise_for_status()
|
42
|
-
|
41
|
+
task_id = response.json().get("task_id")
|
42
|
+
if task_id:
|
43
|
+
return Task(self.base_url, self.headers, task_id)
|
44
|
+
else:
|
45
|
+
return response.json()
|
43
46
|
except requests.RequestException as e:
|
44
|
-
return {"error": str(e)}
|
47
|
+
return {"error": str(e)}
|
48
|
+
except IOError as e:
|
49
|
+
return {"error": f"File error: {str(e)}"}
|
@@ -0,0 +1,34 @@
|
|
1
|
+
import requests
|
2
|
+
from .tasks import Task
|
3
|
+
|
4
|
+
class Register:
|
5
|
+
def __init__(self, base_url, headers):
|
6
|
+
self.base_url = base_url
|
7
|
+
self.headers = headers
|
8
|
+
|
9
|
+
def _prepare_data(self, base_data, metadata=None, settings=None):
|
10
|
+
if metadata is not None:
|
11
|
+
base_data["metadata"] = metadata
|
12
|
+
if settings is not None:
|
13
|
+
base_data["settings"] = settings
|
14
|
+
return base_data
|
15
|
+
|
16
|
+
def faces(self, file_path, collection_id, metadata=None, settings=None):
|
17
|
+
try:
|
18
|
+
endpoint = f"{self.base_url}register/faces"
|
19
|
+
data = self._prepare_data({"collection_id": collection_id}, metadata, settings)
|
20
|
+
|
21
|
+
with open(file_path, 'rb') as file:
|
22
|
+
files = [('file', (file.name, file, 'application/octet-stream'))]
|
23
|
+
response = requests.post(endpoint, headers=self.headers, data=data, files=files)
|
24
|
+
|
25
|
+
response.raise_for_status()
|
26
|
+
task_id = response.json().get("task_id")
|
27
|
+
if task_id:
|
28
|
+
return Task(self.base_url, self.headers, task_id)
|
29
|
+
else:
|
30
|
+
return response.json()
|
31
|
+
except requests.RequestException as e:
|
32
|
+
return {"error": str(e)}
|
33
|
+
except IOError as e:
|
34
|
+
return {"error": f"File error: {str(e)}"}
|
@@ -0,0 +1,26 @@
|
|
1
|
+
import requests
|
2
|
+
import time
|
3
|
+
|
4
|
+
class Task:
|
5
|
+
def __init__(self, base_url, headers, task_id):
|
6
|
+
self.base_url = base_url
|
7
|
+
self.headers = headers
|
8
|
+
self.task_id = task_id
|
9
|
+
|
10
|
+
def get_task_status(self, task_id):
|
11
|
+
try:
|
12
|
+
endpoint = f"{self.base_url}tasks/{task_id}"
|
13
|
+
response = requests.get(endpoint, headers=self.headers)
|
14
|
+
response.raise_for_status()
|
15
|
+
return response.json()
|
16
|
+
except requests.RequestException as e:
|
17
|
+
return {"error": str(e)}
|
18
|
+
|
19
|
+
def wait_for_done(self, sleep_interval=2, callback=None):
|
20
|
+
while True:
|
21
|
+
status = self.get_task_status(self.task_id)
|
22
|
+
if callback:
|
23
|
+
callback(status)
|
24
|
+
if status.get("status") == "DONE":
|
25
|
+
return status
|
26
|
+
time.sleep(sleep_interval)
|
mixpeek/endpoints/tools.py
CHANGED
@@ -5,10 +5,41 @@ import base64
|
|
5
5
|
from urllib.parse import urlparse
|
6
6
|
from urllib.request import urlretrieve
|
7
7
|
from tqdm import tqdm
|
8
|
+
from PIL import Image
|
9
|
+
import io
|
8
10
|
|
9
11
|
class Tools:
|
10
12
|
def __init__(self):
|
11
13
|
self.video = self.Video(self)
|
14
|
+
self.image = self.Image(self)
|
15
|
+
|
16
|
+
class Image:
|
17
|
+
def __init__(self, parent):
|
18
|
+
pass
|
19
|
+
|
20
|
+
def process(self, image_source: str):
|
21
|
+
# Download image if it's a URL
|
22
|
+
if urlparse(image_source).scheme in ('http', 'https'):
|
23
|
+
with tempfile.NamedTemporaryFile(delete=False) as temp_file:
|
24
|
+
urlretrieve(image_source, temp_file.name)
|
25
|
+
image_source = temp_file.name
|
26
|
+
|
27
|
+
# Open and process the image
|
28
|
+
with Image.open(image_source) as img:
|
29
|
+
# Convert image to RGB mode if it's not already
|
30
|
+
if img.mode != 'RGB':
|
31
|
+
img = img.convert('RGB')
|
32
|
+
|
33
|
+
# Convert image to base64
|
34
|
+
buffered = io.BytesIO()
|
35
|
+
img.save(buffered, format="JPEG")
|
36
|
+
base64_string = base64.b64encode(buffered.getvalue()).decode('utf-8')
|
37
|
+
|
38
|
+
# Remove temporary file if it was created
|
39
|
+
if urlparse(image_source).scheme in ('http', 'https'):
|
40
|
+
os.unlink(image_source)
|
41
|
+
|
42
|
+
return base64_string
|
12
43
|
|
13
44
|
class Video:
|
14
45
|
def __init__(self, parent):
|
@@ -25,6 +56,7 @@ class Tools:
|
|
25
56
|
}
|
26
57
|
yield data
|
27
58
|
|
59
|
+
|
28
60
|
class VideoChunker:
|
29
61
|
def __init__(self, video_source, chunk_interval, target_resolution):
|
30
62
|
self.video_source = video_source
|
@@ -1,6 +1,6 @@
|
|
1
1
|
Metadata-Version: 2.1
|
2
2
|
Name: mixpeek
|
3
|
-
Version: 0.
|
3
|
+
Version: 0.8.0
|
4
4
|
Summary: Mixpeek Python SDK
|
5
5
|
Home-page: https://github.com/mixpeek/mixpeek-python
|
6
6
|
Author: Ethan Steininger
|
@@ -14,6 +14,7 @@ Requires-Dist: requests ==2.32.3
|
|
14
14
|
Requires-Dist: pydantic ==2.7.3
|
15
15
|
Requires-Dist: tqdm ==4.66.4
|
16
16
|
Requires-Dist: urllib3 ==2.2.1
|
17
|
+
Requires-Dist: pillow ==10.4.0
|
17
18
|
|
18
19
|
# Mixpeek Python SDK
|
19
20
|
|
@@ -0,0 +1,15 @@
|
|
1
|
+
mixpeek/__init__.py,sha256=XDdcK7wTEOEcF1cp-GeWmgPJ21Ny1R9pB0PPNrdDTMo,28
|
2
|
+
mixpeek/client.py,sha256=FcSjc73WMMKPHzZKye2_XicwJP1bY_iaMWdIv-ft1Rw,906
|
3
|
+
mixpeek/exceptions.py,sha256=Orhdo5UFLn3fcWVJtlgkznW8Iy5ndL96h0qTY8zOlDA,235
|
4
|
+
mixpeek/endpoints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
+
mixpeek/endpoints/collections.py,sha256=ffOBenNHG-mVpjT7kQcOfn78-wjgjdQTVyrloyeAy90,2890
|
6
|
+
mixpeek/endpoints/embed.py,sha256=ybDqyIt0oJiwIdH1QSwuV-CPeJgd-zW0etNAcBdgZYE,2290
|
7
|
+
mixpeek/endpoints/index.py,sha256=kG5bf0ycIWvooicA5xowXrWH4x6nbzP6XdyK-XQHqU0,1976
|
8
|
+
mixpeek/endpoints/register.py,sha256=ZVes4BPxQsPRNk70tGeVe_CYr4eVQKL-CTVmzpJAHM4,1314
|
9
|
+
mixpeek/endpoints/search.py,sha256=u3onbss7Llx0AgcTSRtel6bGO5Ly3jvraXPcA26GzsY,2387
|
10
|
+
mixpeek/endpoints/tasks.py,sha256=GBkscCYVv46JkJ4MVOtM6tL__rymnM3bmt4PrdRK04Y,839
|
11
|
+
mixpeek/endpoints/tools.py,sha256=T8qb9zngY3V_vwtmBBrTqPvqZl1QIL8q3at3UGIj4bg,4709
|
12
|
+
mixpeek-0.8.0.dist-info/METADATA,sha256=xrC5EB9t4qThzh2l8mafI_AAI7Fkk58c6SQhFPFVHWY,10616
|
13
|
+
mixpeek-0.8.0.dist-info/WHEEL,sha256=GV9aMThwP_4oNCtvEC2ec3qUYutgWeAzklro_0m4WJQ,91
|
14
|
+
mixpeek-0.8.0.dist-info/top_level.txt,sha256=EJ8Jc4IhqyUwnUlBwKbs498Ju4O9a-IDh2kXc_lo6Vg,8
|
15
|
+
mixpeek-0.8.0.dist-info/RECORD,,
|
mixpeek-0.7.2.dist-info/RECORD
DELETED
@@ -1,13 +0,0 @@
|
|
1
|
-
mixpeek/__init__.py,sha256=XDdcK7wTEOEcF1cp-GeWmgPJ21Ny1R9pB0PPNrdDTMo,28
|
2
|
-
mixpeek/client.py,sha256=JFQO-hLFe7MESdkNoweuoaGrc4Vnqtl55_JRvgDCspg,804
|
3
|
-
mixpeek/exceptions.py,sha256=Orhdo5UFLn3fcWVJtlgkznW8Iy5ndL96h0qTY8zOlDA,235
|
4
|
-
mixpeek/endpoints/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
5
|
-
mixpeek/endpoints/collections.py,sha256=ffOBenNHG-mVpjT7kQcOfn78-wjgjdQTVyrloyeAy90,2890
|
6
|
-
mixpeek/endpoints/embed.py,sha256=ybDqyIt0oJiwIdH1QSwuV-CPeJgd-zW0etNAcBdgZYE,2290
|
7
|
-
mixpeek/endpoints/index.py,sha256=QgMgys1CCukepCpK351aVXRxEsxBfI2YriX7aaH1NrU,1939
|
8
|
-
mixpeek/endpoints/search.py,sha256=u3onbss7Llx0AgcTSRtel6bGO5Ly3jvraXPcA26GzsY,2387
|
9
|
-
mixpeek/endpoints/tools.py,sha256=QH3X0tYKr-W_9ApENgP7PeuLJi7Qr9W2jrrgQFH4F2A,3567
|
10
|
-
mixpeek-0.7.2.dist-info/METADATA,sha256=d_YN-IkRgs4iNHw6v7dN9qXg1jT46NvpjI74VqPqwKM,10585
|
11
|
-
mixpeek-0.7.2.dist-info/WHEEL,sha256=Mdi9PDNwEZptOjTlUcAth7XJDFtKrHYaQMPulZeBCiQ,91
|
12
|
-
mixpeek-0.7.2.dist-info/top_level.txt,sha256=EJ8Jc4IhqyUwnUlBwKbs498Ju4O9a-IDh2kXc_lo6Vg,8
|
13
|
-
mixpeek-0.7.2.dist-info/RECORD,,
|
File without changes
|