CannaTech commited on
Commit
ef82d94
·
1 Parent(s): 1d76789

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -24
app.py CHANGED
@@ -78,24 +78,24 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
78
  self.log_file = Path(self.dataset_dir) / "data.csv"
79
  self.infos_file = Path(self.dataset_dir) / "dataset_infos.json"
80
 
81
- def flag(
82
- self,
83
- flag_data: List[Any],
84
- flag_option: str | None = None,
85
- flag_index: int | None = None,
86
- username: str | None = None,
87
  ) -> int:
88
  self.repo.git_pull(lfs=True)
89
 
90
  is_new = not Path(self.log_file).exists()
91
 
92
  with open(self.log_file, "a", newline="", encoding="utf-8") as csvfile:
93
- writer = csv.writer(csvfile)
94
-
95
- # File previews for certain input and output types
96
- infos, file_preview_types, headers = _get_dataset_features_info(
97
  is_new, self.components
98
- )
99
 
100
  # Generate the headers and dataset_infos
101
  if is_new:
@@ -112,23 +112,19 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
112
  if isinstance(component, tuple(file_preview_types)):
113
  csv_data.append(
114
  "{}/resolve/main/{}".format(self.path_to_dataset_repo, filepath)
115
- )
116
-
117
- # Truncate flagged output to first 100 characters
118
- flagged_output = csv_data[-1][:100] if csv_data else ""
119
- csv_data.append(flagged_output)
120
- csv_data.append(flag_option if flag_option is not None else "")
121
- writer.writerow(utils.sanitize_list_for_csv(csv_data))
122
 
123
- if is_new:
124
- json.dump(infos, open(self.infos_file, "w"))
125
 
126
- with open(self.log_file, "r", encoding="utf-8") as csvfile:
127
- line_count = len([None for row in csv.reader(csvfile)]) - 1
128
 
129
- self.repo.push_to_hub(commit_message="Flagged sample #{}".format(line_count))
130
 
131
- return line_count
132
 
133
  ##################
134
 
 
78
  self.log_file = Path(self.dataset_dir) / "data.csv"
79
  self.infos_file = Path(self.dataset_dir) / "dataset_infos.json"
80
 
81
+ def flag(
82
+ self,
83
+ flag_data: List[Any],
84
+ flag_option: str | None = None,
85
+ flag_index: int | None = None,
86
+ username: str | None = None,
87
  ) -> int:
88
  self.repo.git_pull(lfs=True)
89
 
90
  is_new = not Path(self.log_file).exists()
91
 
92
  with open(self.log_file, "a", newline="", encoding="utf-8") as csvfile:
93
+ writer = csv.writer(csvfile)
94
+
95
+ # File previews for certain input and output types
96
+ infos, file_preview_types, headers = _get_dataset_features_info(
97
  is_new, self.components
98
+ )
99
 
100
  # Generate the headers and dataset_infos
101
  if is_new:
 
112
  if isinstance(component, tuple(file_preview_types)):
113
  csv_data.append(
114
  "{}/resolve/main/{}".format(self.path_to_dataset_repo, filepath)
115
+ )
116
+ csv_data.append(flag_option if flag_option is not None else "")
117
+ writer.writerow(utils.sanitize_list_for_csv(csv_data))
 
 
 
 
118
 
119
+ if is_new:
120
+ json.dump(infos, open(self.infos_file, "w"))
121
 
122
+ with open(self.log_file, "r", encoding="utf-8") as csvfile:
123
+ line_count = len([None for row in csv.reader(csvfile)]) - 1
124
 
125
+ self.repo.push_to_hub(commit_message="Flagged sample #{}".format(line_count))
126
 
127
+ return line_count
128
 
129
  ##################
130