Update vlm-projects-multi-lang-final.py
Browse files- vlm-projects-multi-lang-final.py +58 -14
vlm-projects-multi-lang-final.py
CHANGED
|
@@ -1,14 +1,18 @@
|
|
| 1 |
-
|
| 2 |
-
import datasets
|
| 3 |
import os
|
| 4 |
import pandas as pd
|
|
|
|
| 5 |
|
| 6 |
_DESCRIPTION = "A multilingual medical imaging dataset with questions and answers, structured by language."
|
| 7 |
_HOMEPAGE = "https://huggingface.co/datasets/tungvu3196/vlm-projects-multi-lang-final"
|
| 8 |
_LICENSE = "apache-2.0"
|
| 9 |
-
_CITATION = ""
|
| 10 |
|
| 11 |
-
LANGUAGES = [
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
class VlmProjectsMultiLangFinal(datasets.GeneratorBasedBuilder):
|
| 14 |
BUILDER_CONFIGS = [
|
|
@@ -21,33 +25,73 @@ class VlmProjectsMultiLangFinal(datasets.GeneratorBasedBuilder):
|
|
| 21 |
]
|
| 22 |
|
| 23 |
def _info(self):
|
| 24 |
-
# Use the exact features we extracted from the Parquet file
|
| 25 |
return datasets.DatasetInfo(
|
| 26 |
description=_DESCRIPTION,
|
| 27 |
-
features={'A1': Value('string'), 'A2': Value('string'), 'A3': Value('string'), 'A4': Value('string'), 'Bbox coordinates normalized (X, Y, W, H)': Value('string'), 'Column 9': Value('float64'), 'Deliverable': Value('string'), 'Doctor': Value('string'), 'Google Drive Link': Value('string'), 'No.': Value('int64'), 'Notes': Value('string'), 'Original': Value('string'), 'Patient ID': Value('string'), 'Q1': Value('string'), 'Q2': Value('string'), 'Q3': Value('string'), 'Q4': Value('string'), 'Remove Status': Value('string'), 'Slide': Value('string'), 'Start date': Value('float64'), 'Status': Value('string'), '__index_level_0__': Value('int64'), 'image': Image(mode=None, decode=True), 'image_with_bboxes': Image(mode=None, decode=True), 'rotated_link': Value('string')},
|
| 28 |
homepage=_HOMEPAGE,
|
| 29 |
license=_LICENSE,
|
| 30 |
citation=_CITATION,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
)
|
| 32 |
|
| 33 |
def _split_generators(self, dl_manager):
|
| 34 |
-
#
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
return [
|
| 39 |
datasets.SplitGenerator(
|
| 40 |
name=datasets.Split.TRAIN,
|
| 41 |
-
gen_kwargs={"filepath": os.path.join(
|
|
|
|
| 42 |
),
|
| 43 |
datasets.SplitGenerator(
|
| 44 |
name=datasets.Split.TEST,
|
| 45 |
-
gen_kwargs={"filepath": os.path.join(
|
|
|
|
| 46 |
),
|
| 47 |
]
|
| 48 |
|
| 49 |
-
def _generate_examples(self, filepath):
|
|
|
|
| 50 |
df = pd.read_parquet(filepath)
|
|
|
|
| 51 |
for i, row in df.iterrows():
|
| 52 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
|
|
|
|
|
|
| 1 |
+
# dataset.py
|
|
|
|
| 2 |
import os
|
| 3 |
import pandas as pd
|
| 4 |
+
import datasets
|
| 5 |
|
| 6 |
_DESCRIPTION = "A multilingual medical imaging dataset with questions and answers, structured by language."
|
| 7 |
_HOMEPAGE = "https://huggingface.co/datasets/tungvu3196/vlm-projects-multi-lang-final"
|
| 8 |
_LICENSE = "apache-2.0"
|
| 9 |
+
_CITATION = ""
|
| 10 |
|
| 11 |
+
LANGUAGES = [
|
| 12 |
+
"English","Vietnamese","French","German","Spanish","Russian","Korean",
|
| 13 |
+
"Mandarin","Japanese","Thai","Indonesian","Malay","Arabic","Hindi",
|
| 14 |
+
"Turkish","Portuguese"
|
| 15 |
+
]
|
| 16 |
|
| 17 |
class VlmProjectsMultiLangFinal(datasets.GeneratorBasedBuilder):
|
| 18 |
BUILDER_CONFIGS = [
|
|
|
|
| 25 |
]
|
| 26 |
|
| 27 |
def _info(self):
|
|
|
|
| 28 |
return datasets.DatasetInfo(
|
| 29 |
description=_DESCRIPTION,
|
|
|
|
| 30 |
homepage=_HOMEPAGE,
|
| 31 |
license=_LICENSE,
|
| 32 |
citation=_CITATION,
|
| 33 |
+
features=datasets.Features({
|
| 34 |
+
"A1": datasets.Value("string"),
|
| 35 |
+
"A2": datasets.Value("string"),
|
| 36 |
+
"A3": datasets.Value("string"),
|
| 37 |
+
"A4": datasets.Value("string"),
|
| 38 |
+
"Bbox coordinates normalized (X, Y, W, H)": datasets.Value("string"),
|
| 39 |
+
"Column 9": datasets.Value("float64"),
|
| 40 |
+
"Deliverable": datasets.Value("string"),
|
| 41 |
+
"Doctor": datasets.Value("string"),
|
| 42 |
+
"Google Drive Link": datasets.Value("string"),
|
| 43 |
+
"No.": datasets.Value("int64"),
|
| 44 |
+
"Notes": datasets.Value("string"),
|
| 45 |
+
"Original": datasets.Value("string"),
|
| 46 |
+
"Patient ID": datasets.Value("string"),
|
| 47 |
+
"Q1": datasets.Value("string"),
|
| 48 |
+
"Q2": datasets.Value("string"),
|
| 49 |
+
"Q3": datasets.Value("string"),
|
| 50 |
+
"Q4": datasets.Value("string"),
|
| 51 |
+
"Remove Status": datasets.Value("string"),
|
| 52 |
+
"Slide": datasets.Value("string"),
|
| 53 |
+
"Start date": datasets.Value("float64"),
|
| 54 |
+
"Status": datasets.Value("string"),
|
| 55 |
+
"__index_level_0__": datasets.Value("int64"),
|
| 56 |
+
# These two will render in the Viewer if the underlying files exist in the repo:
|
| 57 |
+
"image": datasets.Image(), # path or dict -> file in repo
|
| 58 |
+
"image_with_bboxes": datasets.Image(),
|
| 59 |
+
# keep as string/URL if it's not a local file:
|
| 60 |
+
"rotated_link": datasets.Value("string"),
|
| 61 |
+
}),
|
| 62 |
)
|
| 63 |
|
| 64 |
def _split_generators(self, dl_manager):
|
| 65 |
+
# Map config name ("English") to folder ("english")
|
| 66 |
+
lang_dir = self.config.name.lower()
|
| 67 |
+
base = os.path.join(self.config.data_dir or "data", lang_dir)
|
|
|
|
| 68 |
return [
|
| 69 |
datasets.SplitGenerator(
|
| 70 |
name=datasets.Split.TRAIN,
|
| 71 |
+
gen_kwargs={"filepath": os.path.join(base, "train.parquet"),
|
| 72 |
+
"base_dir": base},
|
| 73 |
),
|
| 74 |
datasets.SplitGenerator(
|
| 75 |
name=datasets.Split.TEST,
|
| 76 |
+
gen_kwargs={"filepath": os.path.join(base, "test.parquet"),
|
| 77 |
+
"base_dir": base},
|
| 78 |
),
|
| 79 |
]
|
| 80 |
|
| 81 |
+
def _generate_examples(self, filepath, base_dir):
|
| 82 |
+
# Read parquet produced by your pipeline
|
| 83 |
df = pd.read_parquet(filepath)
|
| 84 |
+
|
| 85 |
for i, row in df.iterrows():
|
| 86 |
+
ex = row.to_dict()
|
| 87 |
+
|
| 88 |
+
# If parquet stored relative paths like "images/xyz.png", keep them relative to repo:
|
| 89 |
+
for col in ("image", "image_with_bboxes"):
|
| 90 |
+
p = ex.get(col)
|
| 91 |
+
if isinstance(p, str) and len(p):
|
| 92 |
+
# If the path isn't an URL, make it relative to the dataset files
|
| 93 |
+
if not (p.startswith("http://") or p.startswith("https://")):
|
| 94 |
+
ex[col] = os.path.join(base_dir, p).replace("\\", "/")
|
| 95 |
+
# if it *is* a URL, leave as-is (Image will try to download)
|
| 96 |
|
| 97 |
+
yield i, ex
|