Abderrahim Habiba
commited on
Update dataset.py
Browse files- dataset.py +20 -19
dataset.py
CHANGED
@@ -37,24 +37,25 @@ class TunisianProverbsDataset(GeneratorBasedBuilder):
|
|
37 |
|
38 |
def _generate_examples(self, csv_path, image_dir):
|
39 |
df = pd.read_csv(csv_path)
|
40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
41 |
for idx, row in df.iterrows():
|
42 |
-
def safe_image_path(path):
|
43 |
-
full_path = os.path.join(image_dir, path) if pd.notna(path) else None
|
44 |
-
return full_path if full_path and os.path.exists(full_path) else None
|
45 |
-
|
46 |
yield idx, {
|
47 |
-
"tunisan_proverb": row
|
48 |
-
"proverb_arabic_explaination": row
|
49 |
-
"context": row
|
50 |
-
"caption": row
|
51 |
-
"caption_formal": row
|
52 |
-
"dynamic": row
|
53 |
-
"prompt": row
|
54 |
-
"image_path_1": safe_image_path(row
|
55 |
-
"image_path_2": safe_image_path(row
|
56 |
-
"image_path_3": safe_image_path(row
|
57 |
-
"image_path_4": safe_image_path(row
|
58 |
-
"clip_scores": float(row["clip_scores"]) if pd.notna(row
|
59 |
-
}
|
60 |
-
|
|
|
37 |
|
38 |
def _generate_examples(self, csv_path, image_dir):
|
39 |
df = pd.read_csv(csv_path)
|
40 |
+
|
41 |
+
def safe_image_path(path):
|
42 |
+
if pd.isna(path) or not isinstance(path, str) or not path.strip():
|
43 |
+
return None
|
44 |
+
full_path = os.path.join(image_dir, path.strip())
|
45 |
+
return full_path if os.path.isfile(full_path) else None
|
46 |
+
|
47 |
for idx, row in df.iterrows():
|
|
|
|
|
|
|
|
|
48 |
yield idx, {
|
49 |
+
"tunisan_proverb": row.get("tunisan_proverb", ""),
|
50 |
+
"proverb_arabic_explaination": row.get("proverb_arabic_explaination", ""),
|
51 |
+
"context": row.get("context", ""),
|
52 |
+
"caption": row.get("caption", ""),
|
53 |
+
"caption_formal": row.get("caption_formal", ""),
|
54 |
+
"dynamic": row.get("dynamic", ""),
|
55 |
+
"prompt": row.get("prompt", ""),
|
56 |
+
"image_path_1": safe_image_path(row.get("image_path_1")),
|
57 |
+
"image_path_2": safe_image_path(row.get("image_path_2")),
|
58 |
+
"image_path_3": safe_image_path(row.get("image_path_3")),
|
59 |
+
"image_path_4": safe_image_path(row.get("image_path_4")),
|
60 |
+
"clip_scores": float(row["clip_scores"]) if pd.notna(row.get("clip_scores")) else 0.0,
|
61 |
+
}
|
|