class_docstr: A callback that saves each flagged sample (both the input and output data) to a HuggingFace dataset.
  
  Example:
      import gradio as gr
      hf_writer = gr.HuggingFaceDatasetSaver(HF_API_TOKEN, "image-classification-mistakes")
      def image_classifier(inp):
          return {'cat': 0.3, 'dog': 0.7}
      demo = gr.Interface(fn=image_classifier, inputs="image", outputs="label",
                          allow_flagging="manual", flagging_callback=hf_writer)
  Guides: using-flagging
class_docstr_tok: ["A","callback","that","saves","each","flagged","sample","(","both","the","input","and","output","data",")","to","a","HuggingFace","dataset",".","Example",":","import","gradio","as","gr","hf_writer","=","gr.HuggingFaceDatasetSaver","(","HF_API_TOKEN",",","``","image-classification-mistakes","''",")","def","image_classifier","(","inp",")",":","return","{","'cat","'",":","0.3",",","'dog","'",":","0.7","}","demo","=","gr.Interface","(","fn=image_classifier",",","inputs=","''","image","''",",","outputs=","''","label","''",",","allow_flagging=","''","manual","''",",","flagging_callback=hf_writer",")","Guides",":","using-flagging"]
docstr: Save data as CSV and return the sample name (row number).
code: def _save_as_csv(
      data_file: Path, headers: list[str], row: list[Any]
  ) -> int:
      """Save data as CSV and return the sample name (row number)."""
      is_new = not data_file.exists()
  
      with data_file.open("a", newline="", encoding="utf-8") as csvfile:
          writer = csv.writer(csvfile)
  
          # Write CSV headers if new file
          if is_new:
              writer.writerow(utils.sanitize_list_for_csv(headers))
  
          # Write CSV row for flagged sample
          writer.writerow(utils.sanitize_list_for_csv(row))
  
      with data_file.open(encoding="utf-8") as csvfile:
          return sum(1 for _ in csv.reader(csvfile)) - 1
  
imports: from __future__ import annotations
  import csv
  import datetime
  import json
  import os
  import time
  import uuid
  from abc import ABC, abstractmethod
  from collections import OrderedDict
  from pathlib import Path
  from typing import TYPE_CHECKING, Any
  import filelock
  import huggingface_hub
  from gradio_client import utils
  from gradio_client.documentation import document, set_documentation_group
  import gradio
  from gradio import utils
label_desc: Use image node_id 5 for calling the HuggingFaceDatasetSaver obj's underlying member method code with example usage: obj._save_as_csv(data_file, headers, row) and returns: unknown