File size: 4,076 Bytes
573ba04
58ff2a7
 
573ba04
58ff2a7
 
 
 
573ba04
58ff2a7
573ba04
 
 
 
 
58ff2a7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
573ba04
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
58ff2a7
 
 
573ba04
 
 
58ff2a7
 
 
573ba04
 
58ff2a7
 
 
573ba04
 
58ff2a7
 
 
573ba04
 
58ff2a7
573ba04
58ff2a7
573ba04
 
 
 
 
 
 
 
 
 
58ff2a7
573ba04
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# 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