Abderrahim Habiba commited on
Commit
25930c2
·
verified ·
1 Parent(s): c34ad8f

Update dataset.py

Browse files
Files changed (1) hide show
  1. 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["tunisan_proverb"],
48
- "proverb_arabic_explaination": row["proverb_arabic_explaination"],
49
- "context": row["context"],
50
- "caption": row["caption"],
51
- "caption_formal": row["caption_formal"],
52
- "dynamic": row["dynamic"],
53
- "prompt": row["prompt"],
54
- "image_path_1": safe_image_path(row["image_path_1"]),
55
- "image_path_2": safe_image_path(row["image_path_2"]),
56
- "image_path_3": safe_image_path(row["image_path_3"]),
57
- "image_path_4": safe_image_path(row["image_path_4"]),
58
- "clip_scores": float(row["clip_scores"]) if pd.notna(row["clip_scores"]) else 0.0,
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
+ }