|
|
|
import os |
|
import pandas as pd |
|
import datasets |
|
|
|
_DESCRIPTION = "A multilingual medical imaging dataset with questions and answers, structured by language." |
|
_HOMEPAGE = "https://huggingface.co/datasets/tungvu3196/vlm-projects-multi-lang-final" |
|
_LICENSE = "apache-2.0" |
|
_CITATION = "" |
|
|
|
LANGUAGES = [ |
|
"English","Vietnamese","French","German","Spanish","Russian","Korean", |
|
"Mandarin","Japanese","Thai","Indonesian","Malay","Arabic","Hindi", |
|
"Turkish","Portuguese" |
|
] |
|
|
|
class VlmProjectsMultiLangFinal(datasets.GeneratorBasedBuilder): |
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig( |
|
name=lang_name, |
|
version=datasets.Version("1.0.0"), |
|
description=f"Dataset in {lang_name}", |
|
) |
|
for lang_name in LANGUAGES |
|
] |
|
|
|
def _info(self): |
|
return datasets.DatasetInfo( |
|
description=_DESCRIPTION, |
|
homepage=_HOMEPAGE, |
|
license=_LICENSE, |
|
citation=_CITATION, |
|
features=datasets.Features({ |
|
"A1": datasets.Value("string"), |
|
"A2": datasets.Value("string"), |
|
"A3": datasets.Value("string"), |
|
"A4": datasets.Value("string"), |
|
"Bbox coordinates normalized (X, Y, W, H)": datasets.Value("string"), |
|
"Column 9": datasets.Value("float64"), |
|
"Deliverable": datasets.Value("string"), |
|
"Doctor": datasets.Value("string"), |
|
"Google Drive Link": datasets.Value("string"), |
|
"No.": datasets.Value("int64"), |
|
"Notes": datasets.Value("string"), |
|
"Original": datasets.Value("string"), |
|
"Patient ID": datasets.Value("string"), |
|
"Q1": datasets.Value("string"), |
|
"Q2": datasets.Value("string"), |
|
"Q3": datasets.Value("string"), |
|
"Q4": datasets.Value("string"), |
|
"Remove Status": datasets.Value("string"), |
|
"Slide": datasets.Value("string"), |
|
"Start date": datasets.Value("float64"), |
|
"Status": datasets.Value("string"), |
|
"__index_level_0__": datasets.Value("int64"), |
|
|
|
"image": datasets.Image(), |
|
"image_with_bboxes": datasets.Image(), |
|
|
|
"rotated_link": datasets.Value("string"), |
|
}), |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
lang_dir = self.config.name.lower() |
|
base = os.path.join(self.config.data_dir or "data", lang_dir) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
gen_kwargs={"filepath": os.path.join(base, "train.parquet"), |
|
"base_dir": base}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
gen_kwargs={"filepath": os.path.join(base, "test.parquet"), |
|
"base_dir": base}, |
|
), |
|
] |
|
|
|
def _generate_examples(self, filepath, base_dir): |
|
|
|
df = pd.read_parquet(filepath) |
|
|
|
for i, row in df.iterrows(): |
|
ex = row.to_dict() |
|
|
|
|
|
for col in ("image", "image_with_bboxes"): |
|
p = ex.get(col) |
|
if isinstance(p, str) and len(p): |
|
|
|
if not (p.startswith("http://") or p.startswith("https://")): |
|
ex[col] = os.path.join(base_dir, p).replace("\\", "/") |
|
|
|
|
|
yield i, ex |
|
|