Spaces:
Paused
Paused
Download data_sampler.py from VIDraft/ACE-Singer: direct link, hf CLI and curl.
- Browser
- Download file 572 Bytes
-
https://huggingface.co/spaces/VIDraft/ACE-Singer/resolve/54881671a9564cdc1cee1da72ddb64c0b43ed77d/data_sampler.py
- Command line
-
hf download hf://spaces/VIDraft/ACE-Singer@54881671a9564cdc1cee1da72ddb64c0b43ed77d/data_sampler.py
-
curl -L -o data_sampler.py https://huggingface.co/spaces/VIDraft/ACE-Singer/resolve/54881671a9564cdc1cee1da72ddb64c0b43ed77d/data_sampler.py
572 Bytes
| import json | |
| from pathlib import Path | |
| import random | |
| DEFAULT_ROOT_DIR = "examples/input_params" | |
| class DataSampler: | |
| def __init__(self, root_dir=DEFAULT_ROOT_DIR): | |
| self.root_dir = root_dir | |
| # glob | |
| self.input_params_files = list(Path(self.root_dir).glob("*.json")) | |
| def load_json(self, file_path): | |
| with open(file_path, "r", encoding="utf-8") as f: | |
| return json.load(f) | |
| def sample(self): | |
| json_path = random.choice(self.input_params_files) | |
| json_data = self.load_json(json_path) | |
| return json_data | |