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: Params:
  flagging_dir (str): local directory where the dataset is cloned,
  updated, and pushed from.
code: def setup(self, components: list[Component], flagging_dir: str):
      """
      Params:
      flagging_dir (str): local directory where the dataset is cloned,
      updated, and pushed from.
      """
      # Setup dataset on the Hub
      self.dataset_id = huggingface_hub.create_repo(
          repo_id=self.dataset_id,
          token=self.hf_token,
          private=self.dataset_private,
          repo_type="dataset",
          exist_ok=True,
      ).repo_id
      path_glob = "**/*.jsonl" if self.separate_dirs else "data.csv"
      huggingface_hub.metadata_update(
          repo_id=self.dataset_id,
          repo_type="dataset",
          metadata={
              "configs": [
                  {
                      "config_name": "default",
                      "data_files": [
                          {"split": "train", "path": path_glob}
                      ],
                  }
              ]
          },
          overwrite=True,
          token=self.hf_token,
      )
  
      # Setup flagging dir
      self.components = components
      self.dataset_dir = (
          Path(flagging_dir).absolute() / self.dataset_id.split("/")[-1]
      )
      self.dataset_dir.mkdir(parents=True, exist_ok=True)
      self.infos_file = self.dataset_dir / self.info_filename
  
      # Download remote files to local
      remote_files = [self.info_filename]
      if not self.separate_dirs:
          # No separate dirs => means all data is in the same CSV file => download it to get its current content
          remote_files.append("data.csv")
  
      for filename in remote_files:
          try:
              huggingface_hub.hf_hub_download(
                  repo_id=self.dataset_id,
                  repo_type="dataset",
                  filename=filename,
                  local_dir=self.dataset_dir,
                  token=self.hf_token,
              )
          except huggingface_hub.utils.EntryNotFoundError:
              pass
  
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 2 for calling the HuggingFaceDatasetSaver obj's underlying member method code with example usage: obj.setup(components, flagging_dir) without return types