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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -29
app.py CHANGED
@@ -84,41 +84,41 @@ class HuggingFaceDatasetSaver(FlaggingCallback):
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:
102
- writer.writerow(utils.sanitize_list_for_csv(headers))
103
 
104
- # Generate the row corresponding to the flagged sample
105
- csv_data = []
106
- for component, sample in zip(self.components, flag_data):
107
- save_dir = Path(
108
- self.dataset_dir
109
- ) / utils.strip_invalid_filename_characters(component.label or "")
110
- filepath = component.deserialize(sample, save_dir, None)
111
- csv_data.append(filepath)
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"))
 
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:
102
+ writer.writerow(utils.sanitize_list_for_csv(headers))
103
 
104
+ # Generate the row corresponding to the flagged sample
105
+ csv_data = []
106
+ for component, sample in zip(self.components, flag_data):
107
+ save_dir = Path(
108
+ self.dataset_dir
109
+ ) / utils.strip_invalid_filename_characters(component.label or "")
110
+ filepath = component.deserialize(sample, save_dir, None)
111
+ csv_data.append(filepath)
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"))