Upload artifact.py with huggingface_hub
Browse files- artifact.py +7 -3
artifact.py
CHANGED
|
@@ -8,7 +8,7 @@ from copy import deepcopy
|
|
| 8 |
from functools import lru_cache
|
| 9 |
from typing import Dict, List, Union, final
|
| 10 |
|
| 11 |
-
from .dataclass import Dataclass, Field, fields
|
| 12 |
from .logging_utils import get_logger
|
| 13 |
from .text_utils import camel_to_snake_case, is_camel_case
|
| 14 |
from .type_utils import issubtype
|
|
@@ -102,6 +102,8 @@ class Artifact(Dataclass):
|
|
| 102 |
|
| 103 |
_class_register = {}
|
| 104 |
|
|
|
|
|
|
|
| 105 |
@classmethod
|
| 106 |
def is_artifact_dict(cls, d):
|
| 107 |
return isinstance(d, dict) and "type" in d
|
|
@@ -191,9 +193,11 @@ class Artifact(Dataclass):
|
|
| 191 |
return cls._recursive_load(d)
|
| 192 |
|
| 193 |
@classmethod
|
| 194 |
-
def load(cls, path):
|
| 195 |
d = load_json(path)
|
| 196 |
-
|
|
|
|
|
|
|
| 197 |
|
| 198 |
def prepare(self):
|
| 199 |
pass
|
|
|
|
| 8 |
from functools import lru_cache
|
| 9 |
from typing import Dict, List, Union, final
|
| 10 |
|
| 11 |
+
from .dataclass import Dataclass, Field, InternalField, fields
|
| 12 |
from .logging_utils import get_logger
|
| 13 |
from .text_utils import camel_to_snake_case, is_camel_case
|
| 14 |
from .type_utils import issubtype
|
|
|
|
| 102 |
|
| 103 |
_class_register = {}
|
| 104 |
|
| 105 |
+
artifact_identifier: str = InternalField(default=None, required=False)
|
| 106 |
+
|
| 107 |
@classmethod
|
| 108 |
def is_artifact_dict(cls, d):
|
| 109 |
return isinstance(d, dict) and "type" in d
|
|
|
|
| 193 |
return cls._recursive_load(d)
|
| 194 |
|
| 195 |
@classmethod
|
| 196 |
+
def load(cls, path, artifact_identifier=None):
|
| 197 |
d = load_json(path)
|
| 198 |
+
new_artifact = cls.from_dict(d)
|
| 199 |
+
new_artifact.artifact_identifier = artifact_identifier
|
| 200 |
+
return new_artifact
|
| 201 |
|
| 202 |
def prepare(self):
|
| 203 |
pass
|