microsoft-fluentui-emoji-768 / EmojiDataset.py
Norod78's picture
Upload EmojiDataset.py
8e3b45d
raw
history blame contribute delete
940 Bytes
import datasets
from datasets import Dataset
import sys
import os
from pathlib import Path
from tqdm import tqdm
from PIL import Image
from collections import defaultdict
#for i in *.svg; do rsvg-convert -w 768 -h 768 "${i}" -o "${i%svg}png"; done
def main():
files = list(Path('png768/').rglob("*.png"))
data = defaultdict(list)
print("Loading dataset...")
for file in tqdm(files):
emoji_name = file.stem.replace("_"," ").replace("-"," ").replace("medium", "")
data['text'].append(emoji_name)
image = Image.open(str(file))
data['image'].append(image)
dataset = Dataset.from_dict(data)
print("Dataset loaded.")
print(dataset)
print(dataset[0])
print(dataset[42])
dataset.save_to_disk("microsoft-fluentui-emoji-768")
print("Dataset saved to disk.")
dataset.push_to_hub("Norod78/microsoft-fluentui-emoji-768")
if __name__ == "__main__":
main()