fxn 0.0.19__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 CHANGED
@@ -11,9 +11,10 @@ from json import loads, dumps
11
11
  from numpy import array, float32, frombuffer, int32, ndarray
12
12
  from pathlib import Path
13
13
  from PIL import Image
14
+ from pydantic import BaseModel
14
15
  from requests import get
15
16
  from tempfile import NamedTemporaryFile
16
- from typing import Dict, List, Optional, Union
17
+ from typing import Any, Dict, List, Optional, Union
17
18
  from urllib.request import urlopen
18
19
 
19
20
  from .dtype import Dtype
@@ -83,7 +84,7 @@ class Value:
83
84
  @classmethod
84
85
  def from_value (
85
86
  cls,
86
- 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],
87
88
  name: str,
88
89
  min_upload_size: int=4096,
89
90
  key: str=None
@@ -99,6 +100,7 @@ class Value:
99
100
  Returns:
100
101
  Value: Function value.
101
102
  """
103
+ value = cls.__try_ensure_serializable(value)
102
104
  # None
103
105
  if value is None:
104
106
  return Value(None, type=Dtype.null)
@@ -139,10 +141,6 @@ class Value:
139
141
  buffer = BytesIO(value.encode("utf-8"))
140
142
  data = Storage.upload(buffer, UploadType.Value, name=name, data_url_limit=min_upload_size, key=key)
141
143
  return Value(data, type=Dtype.dict)
142
- # Dataclass # https://docs.python.org/3/library/dataclasses.html#dataclasses.is_dataclass
143
- if is_dataclass(value) and not isinstance(value, type):
144
- value = asdict(value)
145
- return Value.from_value(value, name=name, min_upload_size=min_upload_size, key=key)
146
144
  # Image
147
145
  if isinstance(value, Image.Image):
148
146
  buffer = BytesIO()
@@ -150,7 +148,7 @@ class Value:
150
148
  value.save(buffer, format=format)
151
149
  data = Storage.upload(buffer, UploadType.Value, name=name, data_url_limit=min_upload_size, key=key)
152
150
  return Value(data, type=Dtype.image)
153
- # Path
151
+ # Binary
154
152
  if isinstance(value, Path):
155
153
  assert value.exists(), "Value does not exist at the given path"
156
154
  assert value.is_file(), "Value path must point to a file, not a directory"
@@ -178,11 +176,23 @@ class Value:
178
176
 
179
177
  @classmethod
180
178
  def __download_value_data (cls, url: str) -> BytesIO:
181
- # Check if data URL
182
179
  if url.startswith("data:"):
183
180
  with urlopen(url) as response:
184
181
  return BytesIO(response.read())
185
- # Download
186
182
  response = get(url)
187
183
  result = BytesIO(response.content)
188
- 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
@@ -3,4 +3,4 @@
3
3
  # Copyright © 2023 NatML Inc. All Rights Reserved.
4
4
  #
5
5
 
6
- __version__ = "0.0.19"
6
+ __version__ = "0.0.21"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: fxn
3
- Version: 0.0.19
3
+ Version: 0.0.21
4
4
  Summary: Run on-device and cloud AI prediction functions in Python. Register at https://fxn.ai.
5
5
  Home-page: https://fxn.ai
6
6
  Author: NatML Inc.
@@ -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=GCMjMV1cBFB1mMTqQG9CXzy7johctmVmFm7nSEwAVs0,95
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=Vx7Vb3viTzT2k_e0Mmdq8WnQSiyUGNoUsdsiZyev-9o,7346
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.19.dist-info/LICENSE,sha256=QwcOLU5TJoTeUhuIXzhdCEEDDvorGiC6-3YTOl4TecE,11356
22
- fxn-0.0.19.dist-info/METADATA,sha256=_VYuxKo2ICRgnwQY-OLy_86vwpAWElTXrP68Wk2ORDs,2887
23
- fxn-0.0.19.dist-info/WHEEL,sha256=yQN5g4mg4AybRjkgi-9yy4iQEFibGQmlz78Pik5Or-A,92
24
- fxn-0.0.19.dist-info/entry_points.txt,sha256=QBwKIRed76CRY98VYQYrQDVEBZtJugxJJmBpilxuios,46
25
- fxn-0.0.19.dist-info/top_level.txt,sha256=1ULIEGrnMlhId8nYAkjmRn9g3KEFuHKboq193SEKQkA,4
26
- fxn-0.0.19.dist-info/RECORD,,
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