Download scripts/push_hf.py from KeremTT/hemato: direct link, hf CLI and curl.
- Browser
- Download file 1.55 kB
-
https://huggingface.co/datasets/KeremTT/hemato/resolve/main/scripts/push_hf.py
- Command line
-
hf download hf://datasets/KeremTT/hemato/scripts/push_hf.py
-
curl -L -o push_hf.py https://huggingface.co/datasets/KeremTT/hemato/resolve/main/scripts/push_hf.py
1.55 kB
| """Push HEMATO configs (cls, all, malaria) to one Hugging Face repo as Parquet; HF_TOKEN from env.""" | |
| import csv, os, sys | |
| from datasets import Dataset, Features, Value, ClassLabel, Image | |
| REPO = 'KeremTT/hemato' | |
| R = list(csv.DictReader(open('meta/manifest.csv', encoding='utf-8-sig'))) | |
| for cfg in sys.argv[1:] or ['cls', 'all', 'malaria']: | |
| rs = [r for r in R if r['config'] == cfg] | |
| names = sorted({r['label'] for r in rs}) | |
| feats = Features({'image': Image(), 'label': ClassLabel(names=names), 'label_tr': Value('string'), 'source': Value('string'), | |
| 'original_label': Value('string'), 'patient_id': Value('string'), 'source_license': Value('string'), 'file': Value('string')}) | |
| def gen(split): | |
| for r in rs: | |
| if r['split'] == split: | |
| yield {'image': os.path.join('dataset', r['file']), 'label': r['label'], 'label_tr': r['label_tr'], 'source': r['source'], | |
| 'original_label': r['original_label'], 'patient_id': r['patient_id'], 'source_license': r['source_license'], | |
| 'file': r['file'].split('/', 1)[1]} | |
| for hf_split, split in (('train', 'train'), ('validation', 'val'), ('test', 'test')): | |
| ds = Dataset.from_generator(gen, gen_kwargs={'split': split}, features=feats, cache_dir='hf_cache') | |
| ds.push_to_hub(REPO, config_name=cfg, split=hf_split, private=False, max_shard_size='500MB', | |
| commit_message=f'HEMATO v1.0: {cfg}/{hf_split}') | |
| print('PUSHED', cfg, hf_split, len(ds), flush=True) | |