Upload collections.py with huggingface_hub
Browse files1234567789101141 unmodified lines535455565758596061576263596465import randomimport typingfrom dataclasses import fieldfrom typing import Dict, List
from .artifact import Artifactfrom .dataclass import AbstractFieldfrom .random_utils import get_randomfrom .random_utils import new_random_generator
class Collection(Artifact):41 unmodified lines
class RandomPicker(Artifact): random_generator: random.Random = field( default_factory=lambda: new_random_generator(sub_seed="random_picker") )
def __call__(self, collection: Collection): if isinstance(collection, ListCollection): return get_random().choice(list(collection.items)) return self.random_generator.choice(list(collection.items)) if isinstance(collection, DictCollection): return get_random().choice(list(collection.items.values())) return self.random_generator.choice(list(collection.items.values())) return Nonecollections.py+8-3