vlm-projects-multi-lang-final / vlm-projects-multi-lang-final.py
KamisatoAyaka0928's picture
Update vlm-projects-multi-lang-final.py
573ba04 verified
raw
history blame
4.08 kB
# dataset.py
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"),
# These two will render in the Viewer if the underlying files exist in the repo:
"image": datasets.Image(), # path or dict -> file in repo
"image_with_bboxes": datasets.Image(),
# keep as string/URL if it's not a local file:
"rotated_link": datasets.Value("string"),
}),
)
def _split_generators(self, dl_manager):
# Map config name ("English") to folder ("english")
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):
# Read parquet produced by your pipeline
df = pd.read_parquet(filepath)
for i, row in df.iterrows():
ex = row.to_dict()
# If parquet stored relative paths like "images/xyz.png", keep them relative to repo:
for col in ("image", "image_with_bboxes"):
p = ex.get(col)
if isinstance(p, str) and len(p):
# If the path isn't an URL, make it relative to the dataset files
if not (p.startswith("http://") or p.startswith("https://")):
ex[col] = os.path.join(base_dir, p).replace("\\", "/")
# if it *is* a URL, leave as-is (Image will try to download)
yield i, ex