fxn 0.0.20__py3-none-any.whl → 0.0.21__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.
- fxn/api/value.py +19 -14
- fxn/version.py +1 -1
- {fxn-0.0.20.dist-info → fxn-0.0.21.dist-info}/METADATA +1 -1
- {fxn-0.0.20.dist-info → fxn-0.0.21.dist-info}/RECORD +8 -8
- {fxn-0.0.20.dist-info → fxn-0.0.21.dist-info}/LICENSE +0 -0
- {fxn-0.0.20.dist-info → fxn-0.0.21.dist-info}/WHEEL +0 -0
- {fxn-0.0.20.dist-info → fxn-0.0.21.dist-info}/entry_points.txt +0 -0
- {fxn-0.0.20.dist-info → fxn-0.0.21.dist-info}/top_level.txt +0 -0
fxn/api/value.py
CHANGED
@@ -14,7 +14,7 @@ from PIL import Image
|
|
14
14
|
from pydantic import BaseModel
|
15
15
|
from requests import get
|
16
16
|
from tempfile import NamedTemporaryFile
|
17
|
-
from typing import Dict, List, Optional, Union
|
17
|
+
from typing import Any, Dict, List, Optional, Union
|
18
18
|
from urllib.request import urlopen
|
19
19
|
|
20
20
|
from .dtype import Dtype
|
@@ -84,7 +84,7 @@ class Value:
|
|
84
84
|
@classmethod
|
85
85
|
def from_value (
|
86
86
|
cls,
|
87
|
-
value: Union[str, float, int, bool, ndarray, List, Dict[str, any], Path, Image.Image],
|
87
|
+
value: Union[str, float, int, bool, ndarray, List[Any], Dict[str, any], Path, Image.Image],
|
88
88
|
name: str,
|
89
89
|
min_upload_size: int=4096,
|
90
90
|
key: str=None
|
@@ -100,6 +100,7 @@ class Value:
|
|
100
100
|
Returns:
|
101
101
|
Value: Function value.
|
102
102
|
"""
|
103
|
+
value = cls.__try_ensure_serializable(value)
|
103
104
|
# None
|
104
105
|
if value is None:
|
105
106
|
return Value(None, type=Dtype.null)
|
@@ -140,14 +141,6 @@ class Value:
|
|
140
141
|
buffer = BytesIO(value.encode("utf-8"))
|
141
142
|
data = Storage.upload(buffer, UploadType.Value, name=name, data_url_limit=min_upload_size, key=key)
|
142
143
|
return Value(data, type=Dtype.dict)
|
143
|
-
# Pydantic model
|
144
|
-
if isinstance(value, BaseModel):
|
145
|
-
value = value.model_dump(mode="json")
|
146
|
-
return Value.from_value(value, name=name, min_upload_size=min_upload_size, key=key)
|
147
|
-
# Dataclass # https://docs.python.org/3/library/dataclasses.html#dataclasses.is_dataclass
|
148
|
-
if is_dataclass(value) and not isinstance(value, type):
|
149
|
-
value = asdict(value)
|
150
|
-
return Value.from_value(value, name=name, min_upload_size=min_upload_size, key=key)
|
151
144
|
# Image
|
152
145
|
if isinstance(value, Image.Image):
|
153
146
|
buffer = BytesIO()
|
@@ -155,7 +148,7 @@ class Value:
|
|
155
148
|
value.save(buffer, format=format)
|
156
149
|
data = Storage.upload(buffer, UploadType.Value, name=name, data_url_limit=min_upload_size, key=key)
|
157
150
|
return Value(data, type=Dtype.image)
|
158
|
-
#
|
151
|
+
# Binary
|
159
152
|
if isinstance(value, Path):
|
160
153
|
assert value.exists(), "Value does not exist at the given path"
|
161
154
|
assert value.is_file(), "Value path must point to a file, not a directory"
|
@@ -183,11 +176,23 @@ class Value:
|
|
183
176
|
|
184
177
|
@classmethod
|
185
178
|
def __download_value_data (cls, url: str) -> BytesIO:
|
186
|
-
# Check if data URL
|
187
179
|
if url.startswith("data:"):
|
188
180
|
with urlopen(url) as response:
|
189
181
|
return BytesIO(response.read())
|
190
|
-
# Download
|
191
182
|
response = get(url)
|
192
183
|
result = BytesIO(response.content)
|
193
|
-
return result
|
184
|
+
return result
|
185
|
+
|
186
|
+
@classmethod
|
187
|
+
def __try_ensure_serializable (cls, value: Any) -> Any:
|
188
|
+
if value is None:
|
189
|
+
return value
|
190
|
+
if isinstance(value, Value): # passthrough
|
191
|
+
return value
|
192
|
+
if isinstance(value, list):
|
193
|
+
return [cls.__try_ensure_serializable(x) for x in value]
|
194
|
+
if is_dataclass(value) and not isinstance(value, type):
|
195
|
+
return asdict(value)
|
196
|
+
if isinstance(value, BaseModel):
|
197
|
+
return value.model_dump(mode="json")
|
198
|
+
return value
|
fxn/version.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
fxn/__init__.py,sha256=0NzZl5hRQ0MPNN4Wp9-ghqak2NJzhfHvVyBGX-IntKs,320
|
2
2
|
fxn/magic.py,sha256=TRgE68OAo1djmeQRiqxnSJqa72td6zxnwo0s0bkdUKM,1041
|
3
|
-
fxn/version.py,sha256=
|
3
|
+
fxn/version.py,sha256=pS0q_JGq_GGDrxYMd6x6dFCVcxH7u2LZZZT1h2PnK4g,95
|
4
4
|
fxn/api/__init__.py,sha256=UcCERjadfSbqnt7urXYbrdRRFwA0QwpC9uBQYPJC5rE,460
|
5
5
|
fxn/api/api.py,sha256=X2LRjer0s7ifecYsZmdqv5txEwPjA2ekdSCGUaQJ5So,927
|
6
6
|
fxn/api/dtype.py,sha256=z9zjjsOk8X8LTCEpwLuWOTUys6nP_3L6VmZXLt0ilAY,617
|
@@ -11,16 +11,16 @@ fxn/api/profile.py,sha256=76RVnP0wF9eT5kefqbRVj2T7e-6yZbK4bzggDS1CYjY,876
|
|
11
11
|
fxn/api/storage.py,sha256=GxSwYN5xOWovVJh1WfkVkwkWdCoBkeNP9OHTX8KgEiQ,4560
|
12
12
|
fxn/api/tag.py,sha256=g7HuRv5ZCYYDy4iV8P0hR1tEQ1pZjv-HeqbE0-Li1Bs,832
|
13
13
|
fxn/api/user.py,sha256=AMAwfVpsUsu1Q4Pu1LFfS8bReNaj9dNqBLOsF2qEVLQ,1272
|
14
|
-
fxn/api/value.py,sha256=
|
14
|
+
fxn/api/value.py,sha256=ZL1NroqxP4RNkrbrrCaZurXsWp2qdglpnmTozRm8ooA,7625
|
15
15
|
fxn/cli/__init__.py,sha256=5-yqKCUJCiNTA_7EHfCj5GZKthIQSdbPcVAdMnzYNLg,1492
|
16
16
|
fxn/cli/auth.py,sha256=_5rZ9L-blD39U6-SgHV9V2ltyjJ7k32NY3bLvoGsaNc,1659
|
17
17
|
fxn/cli/env.py,sha256=mnyaL27n59pCU-p2Jm1fo03se7btMV2zdoJWWVshF_M,1658
|
18
18
|
fxn/cli/misc.py,sha256=gLEGGWyawUQaLOuy8bfS2wrJuS-tN-bleOrv5A07xck,690
|
19
19
|
fxn/cli/predict.py,sha256=YP7BiqnT39AeeA3A9EXfHmw-6t5vCxOu27_kjinWdGE,3178
|
20
20
|
fxn/cli/predictors.py,sha256=vAL1FioQSseEiu7jbXY0DRiHnnMmThK2csJLThizS7A,3481
|
21
|
-
fxn-0.0.
|
22
|
-
fxn-0.0.
|
23
|
-
fxn-0.0.
|
24
|
-
fxn-0.0.
|
25
|
-
fxn-0.0.
|
26
|
-
fxn-0.0.
|
21
|
+
fxn-0.0.21.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
|
22
|
+
fxn-0.0.21.dist-info/METADATA,sha256=1TAftjeYqJAaSUEgkUioXFghSBPyEK0P_NdPaeDNjSk,2887
|
23
|
+
fxn-0.0.21.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
|
24
|
+
fxn-0.0.21.dist-info/entry_points.txt,sha256=QBwKIRed76CRY98VYQYrQDVEBZtJugxJJmBpilxuios,46
|
25
|
+
fxn-0.0.21.dist-info/top_level.txt,sha256=1ULIEGrnMlhId8nYAkjmRn9g3KEFuHKboq193SEKQkA,4
|
26
|
+
fxn-0.0.21.dist-info/RECORD,,
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|