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: Parameters:
      hf_token: The HuggingFace token to use to create (and write the flagged sample to) the HuggingFace dataset (defaults to the registered one).
      dataset_name: The repo_id of the dataset to save the data to, e.g. "image-classifier-1" or "username/image-classifier-1".
      private: Whether the dataset should be private (defaults to False).
      info_filename: The name of the file to save the dataset info (defaults to "dataset_infos.json").
      separate_dirs: If True, each flagged item will be saved in a separate directory. This makes the flagging more robust to concurrent editing, but may be less convenient to use.
code: def __init__(
      self,
      hf_token: str,
      dataset_name: str,
      private: bool = False,
      info_filename: str = "dataset_info.json",
      separate_dirs: bool = False,
  ):
      """
      Parameters:
          hf_token: The HuggingFace token to use to create (and write the flagged sample to) the HuggingFace dataset (defaults to the registered one).
          dataset_name: The repo_id of the dataset to save the data to, e.g. "image-classifier-1" or "username/image-classifier-1".
          private: Whether the dataset should be private (defaults to False).
          info_filename: The name of the file to save the dataset info (defaults to "dataset_infos.json").
          separate_dirs: If True, each flagged item will be saved in a separate directory. This makes the flagging more robust to concurrent editing, but may be less convenient to use.
      """
      self.hf_token = hf_token
      self.dataset_id = dataset_name  # TODO: rename parameter (but ensure backward compatibility somehow)
      self.dataset_private = private
      self.info_filename = info_filename
      self.separate_dirs = separate_dirs
  
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 1 to create a new HuggingFaceDatasetSaver object from inherited base classes: FlaggingCallback with example: obj = HuggingFaceDatasetSaver(hf_token, dataset_name, private, info_filename, separate_dirs)