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"]
code: def flag(
      self,
      flag_data: list[Any],
      flag_option: str = "",
      username: str | None = None,
  ) -> int:
      if self.separate_dirs:
          # JSONL files to support dataset preview on the Hub
          unique_id = str(uuid.uuid4())
          components_dir = self.dataset_dir / unique_id
          data_file = components_dir / "metadata.jsonl"
          path_in_repo = (
              unique_id  # upload in sub folder (safer for concurrency)
          )
      else:
          # Unique CSV file
          components_dir = self.dataset_dir
          data_file = components_dir / "data.csv"
          path_in_repo = None  # upload at root level
  
      return self._flag_in_dir(
          data_file=data_file,
          components_dir=components_dir,
          path_in_repo=path_in_repo,
          flag_data=flag_data,
          flag_option=flag_option,
          username=username or "",
      )
  
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 3 for calling the HuggingFaceDatasetSaver obj's underlying member method code with example usage: obj.flag(flag_data, flag_option, username) and returns: self