Upload artifact.py with huggingface_hub
Browse files- artifact.py +17 -1
artifact.py
CHANGED
@@ -207,7 +207,7 @@ class Artifact(Dataclass):
|
|
207 |
|
208 |
@final
|
209 |
def __pre_init__(self, **kwargs):
|
210 |
-
self._init_dict =
|
211 |
|
212 |
@final
|
213 |
def __post_init__(self):
|
@@ -232,6 +232,22 @@ class Artifact(Dataclass):
|
|
232 |
save_json(path, data)
|
233 |
|
234 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
235 |
class ArtifactList(list, Artifact):
|
236 |
def prepare(self):
|
237 |
for artifact in self:
|
|
|
207 |
|
208 |
@final
|
209 |
def __pre_init__(self, **kwargs):
|
210 |
+
self._init_dict = get_raw(kwargs)
|
211 |
|
212 |
@final
|
213 |
def __post_init__(self):
|
|
|
232 |
save_json(path, data)
|
233 |
|
234 |
|
235 |
+
def get_raw(obj):
|
236 |
+
if isinstance(obj, Artifact):
|
237 |
+
return obj._to_raw_dict()
|
238 |
+
|
239 |
+
if isinstance(obj, tuple) and hasattr(obj, "_fields"): # named tuple
|
240 |
+
return type(obj)(*[get_raw(v) for v in obj])
|
241 |
+
|
242 |
+
if isinstance(obj, (list, tuple)):
|
243 |
+
return type(obj)([get_raw(v) for v in obj])
|
244 |
+
|
245 |
+
if isinstance(obj, dict):
|
246 |
+
return type(obj)({get_raw(k): get_raw(v) for k, v in obj.items()})
|
247 |
+
|
248 |
+
return deepcopy(obj)
|
249 |
+
|
250 |
+
|
251 |
class ArtifactList(list, Artifact):
|
252 |
def prepare(self):
|
253 |
for artifact in self:
|