Spaces:
Build error
Build error
Update app.py
Browse files
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 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
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 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
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 |
-
|
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 |
-
|
124 |
-
|
125 |
|
126 |
-
|
127 |
-
|
128 |
|
129 |
-
|
130 |
|
131 |
-
|
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 |
|