Upload collections.py with huggingface_hub
Browse files- collections.py +8 -3
collections.py
CHANGED
@@ -1,10 +1,11 @@
|
|
|
|
1 |
import typing
|
2 |
from dataclasses import field
|
3 |
from typing import Dict, List
|
4 |
|
5 |
from .artifact import Artifact
|
6 |
from .dataclass import AbstractField
|
7 |
-
from .random_utils import
|
8 |
|
9 |
|
10 |
class Collection(Artifact):
|
@@ -52,9 +53,13 @@ class ItemPicker(Artifact):
|
|
52 |
|
53 |
|
54 |
class RandomPicker(Artifact):
|
|
|
|
|
|
|
|
|
55 |
def __call__(self, collection: Collection):
|
56 |
if isinstance(collection, ListCollection):
|
57 |
-
return
|
58 |
if isinstance(collection, DictCollection):
|
59 |
-
return
|
60 |
return None
|
|
|
1 |
+
import random
|
2 |
import typing
|
3 |
from dataclasses import field
|
4 |
from typing import Dict, List
|
5 |
|
6 |
from .artifact import Artifact
|
7 |
from .dataclass import AbstractField
|
8 |
+
from .random_utils import new_random_generator
|
9 |
|
10 |
|
11 |
class Collection(Artifact):
|
|
|
53 |
|
54 |
|
55 |
class RandomPicker(Artifact):
|
56 |
+
random_generator: random.Random = field(
|
57 |
+
default_factory=lambda: new_random_generator(sub_seed="random_picker")
|
58 |
+
)
|
59 |
+
|
60 |
def __call__(self, collection: Collection):
|
61 |
if isinstance(collection, ListCollection):
|
62 |
+
return self.random_generator.choice(list(collection.items))
|
63 |
if isinstance(collection, DictCollection):
|
64 |
+
return self.random_generator.choice(list(collection.items.values()))
|
65 |
return None
|