docstr: Loads a `FeedbackDataset` from the Hugging Face Hub.
  
  Args:
      repo_id: the ID of the Hugging Face Hub repo to load the `FeedbackDataset` from.
      *args: the args to pass to `datasets.Dataset.load_from_hub`.
      **kwargs: the kwargs to pass to `datasets.Dataset.load_from_hub`.
  
  Returns:
      A `FeedbackDataset` loaded from the Hugging Face Hub.
docstr_tok: ["Loads","a","`","FeedbackDataset","`","from","the","Hugging","Face","Hub",".","Args",":","repo_id",":","the","ID","of","the","Hugging","Face","Hub","repo","to","load","the","`","FeedbackDataset","`","from",".","*","args",":","the","args","to","pass","to","`","datasets.Dataset.load_from_hub","`",".","*","*","kwargs",":","the","kwargs","to","pass","to","`","datasets.Dataset.load_from_hub","`",".","Returns",":","A","`","FeedbackDataset","`","loaded","from","the","Hugging","Face","Hub","."]
code: def from_huggingface(
      cls: Type["FeedbackDataset"],
      repo_id: str,
      show_progress: bool = True,
      *args: Any,
      **kwargs: Any,
  ) -> "FeedbackDataset":
      """Loads a `FeedbackDataset` from the Hugging Face Hub.
  
      Args:
          repo_id: the ID of the Hugging Face Hub repo to load the `FeedbackDataset` from.
          *args: the args to pass to `datasets.Dataset.load_from_hub`.
          **kwargs: the kwargs to pass to `datasets.Dataset.load_from_hub`.
  
      Returns:
          A `FeedbackDataset` loaded from the Hugging Face Hub.
      """
      import huggingface_hub
      from datasets import DatasetDict, load_dataset
      from huggingface_hub import hf_hub_download
      from huggingface_hub.utils import EntryNotFoundError
  
      # https://github.com/argilla-io/argilla/issues/3468
      from argilla.client.feedback.config import (
          DatasetConfig,
          DeprecatedDatasetConfig,
      )
  
      if parse_version(huggingface_hub.__version__) < parse_version(
          "0.14.0"
      ):
          _LOGGER.warning(
              "Recommended `huggingface_hub` version is 0.14.0 or higher, and you have"
              f" {huggingface_hub.__version__}, so in case you have any issue when pushing the dataset to the"
              " Hugging Face Hub upgrade it as `pip install huggingface_hub --upgrade`."
          )
  
      if "token" in kwargs:
          auth = kwargs.pop("token")
      elif "use_auth_token" in kwargs:
          auth = kwargs.pop("use_auth_token")
      else:
          auth = None
  
      hub_auth = (
          {"use_auth_token": auth}
          if parse_version(huggingface_hub.__version__)
          < parse_version("0.11.0")
          else {"token": auth}
      )
  
      try:
          config_path = hf_hub_download(
              repo_id=repo_id,
              filename="argilla.yaml",
              repo_type="dataset",
              **hub_auth,
          )
          with open(config_path, "r") as f:
              config = DatasetConfig.from_yaml(f.read())
              dataset = cls(
                  fields=config.fields,
                  questions=config.questions,
                  guidelines=config.guidelines,
                  metadata_properties=config.metadata_properties,
                  allow_extra_metadata=config.allow_extra_metadata,
                  vectors_settings=config.vectors_settings,
              )
      except EntryNotFoundError:
          # TODO(alvarobartt): here for backwards compatibility, last used in 1.12.0
          warnings.warn(
              "No `argilla.yaml` file found in the Hugging Face Hub repository, which"
              " means that the `DatasetConfig` was dumped using Argilla 1.12.0 or"
              " lower, and the `argilla.yaml` file was not generated. Please consider"
              " re-dumping the `DatasetConfig` using Argilla 1.13.0 or higher, or"
              " manually create the `argilla.yaml` file in the Hugging Face Hub.",
              UserWarning,
          )
          config_path = hf_hub_download(
              repo_id=repo_id,
              filename="argilla.cfg",
              repo_type="dataset",
              **hub_auth,
          )
          with open(config_path, "r") as f:
              config = DeprecatedDatasetConfig.from_json(f.read())
              dataset = cls(
                  fields=config.fields,
                  questions=config.questions,
                  guidelines=config.guidelines,
              )
      except Exception as e:
          raise FileNotFoundError(
              "Neither `argilla.yaml` nor `argilla.cfg` files were found in the"
              " Hugging Face Hub repository. Please make sure to dump the `DatasetConfig`"
              " using `FeedbackDataset.push_to_huggingface` to automatically upload"
              " the `DatasetConfig` as `argilla.yaml` to the Hugging Face Hub."
          ) from e
  
      hfds = load_dataset(
          repo_id, token=auth, *args, **kwargs
      )  # use_auth_token is deprecated
      if isinstance(hfds, DatasetDict) and "split" not in kwargs:
          if len(hfds.keys()) > 1:
              raise ValueError(
                  "Only one dataset can be loaded at a time, use `split` to select a split, available splits"
                  f" are: {', '.join(hfds.keys())}."
              )
          hfds = hfds[list(hfds.keys())[0]]
  
      records = []
      for index in trange(
          0,
          len(hfds),
          desc="Parsing records",
          disable=not show_progress,
      ):
          responses = {}
          suggestions = []
          user_without_id = False
          for question in dataset.questions:
              if (
                  hfds[index][question.name] is not None
                  and len(hfds[index][question.name]) > 0
              ):
                  if (
                      len(
                          [
                              None
                              for response in hfds[index][question.name]
                              if response["user_id"] is None
                          ]
                          if isinstance(
                              hfds[index][question.name], list
                          )
                          else [
                              None
                              for user_id in hfds[index][question.name][
                                  "user_id"
                              ]
                              if user_id is None
                          ]
                      )
                      > 1
                  ):
                      warnings.warn(
                          "Found more than one user without ID in the dataset, so just the"
                          " responses for the first user without ID will be used, the rest"
                          " will be discarded."
                      )
  
                  # Here for backwards compatibility
                  original_responses = []
                  if isinstance(hfds[index][question.name], list):
                      original_responses = hfds[index][question.name]
                  else:
                      for user_id, value, status in zip(
                          hfds[index][question.name]["user_id"],
                          hfds[index][question.name]["value"],
                          hfds[index][question.name]["status"],
                      ):
                          original_responses.append(
                              {
                                  "user_id": user_id,
                                  "value": value,
                                  "status": status,
                              }
                          )
  
                  user_without_id_response = False
                  for response in original_responses:
                      if user_without_id_response:
                          continue
                      user_id = response["user_id"]
                      status = response["status"]
                      if user_id is None:
                          if not user_without_id:
                              user_without_id = True
                              responses["user_without_id"] = {
                                  "user_id": user_id,
                                  "status": status,
                                  "values": {},
                              }
                              user_without_id_response = True
                      if (
                          user_id is not None
                          and user_id not in responses
                      ):
                          responses[user_id] = {
                              "user_id": user_id,
                              "status": status,
                              "values": {},
                          }
                      value = response["value"]
                      if value is not None:
                          if question.type == QuestionTypes.ranking:
                              value = [
                                  {"rank": r, "value": v}
                                  for r, v in zip(
                                      value["rank"], value["value"]
                                  )
                              ]
                          responses[user_id or "user_without_id"][
                              "values"
                          ].update({question.name: {"value": value}})
  
              # First if-condition is here for backwards compatibility
              if (
                  f"{question.name}-suggestion" in hfds[index]
                  and hfds[index][f"{question.name}-suggestion"]
                  is not None
              ):
                  suggestion = {
                      "question_name": question.name,
                      "value": hfds[index][
                          f"{question.name}-suggestion"
                      ],
                  }
                  if (
                      hfds[index][
                          f"{question.name}-suggestion-metadata"
                      ]
                      is not None
                  ):
                      suggestion.update(
                          hfds[index][
                              f"{question.name}-suggestion-metadata"
                          ]
                      )
                  suggestions.append(suggestion)
  
          metadata = None
          if (
              "metadata" in hfds[index]
              and hfds[index]["metadata"] is not None
          ):
              metadata = json.loads(hfds[index]["metadata"])
  
          vectors = {}
          if "vectors" in hfds[index] and hfds[index]["vectors"]:
              for vector_settings in dataset.vectors_settings:
                  if (
                      hfds[index]["vectors"].get(
                          vector_settings.name, None
                      )
                      is not None
                  ):
                      vectors.update(
                          {
                              vector_settings.name: hfds[index][
                                  "vectors"
                              ][vector_settings.name]
                          }
                      )
  
          records.append(
              FeedbackRecord(
                  fields={
                      field.name: hfds[index][field.name]
                      for field in dataset.fields
                  },
                  metadata=metadata or {},
                  responses=list(responses.values()) or [],
                  suggestions=[
                      suggestion
                      for suggestion in suggestions
                      if suggestion["value"] is not None
                  ]
                  or [],
                  vectors=vectors or {},
                  external_id=hfds[index]["external_id"],
              )
          )
      del hfds
  
      dataset.add_records(records)
  
      return dataset
  
file_path: argilla/src/argilla/client/feedback/integrations/huggingface/dataset.py
imports: import json
  import logging
  import tempfile
  import warnings
  from typing import TYPE_CHECKING, Any, Optional, Type, Union
  from packaging.version import parse
  from tqdm import trange
  from argilla.client.feedback.constants import FIELD_TYPE_TO_PYTHON_TYPE
  from argilla.client.feedback.schemas.enums import QuestionTypes
  from argilla.client.feedback.schemas.records import FeedbackRecord
  from argilla.client.feedback.schemas.remote.records import RemoteFeedbackRecord
  from argilla.utils.dependency import requires_dependencies
label_desc: Use image node_id 3 for calling the HuggingFaceDatasetMixin obj's underlying member method code with example usage: obj.from_huggingface(cls, repo_id, show_progress) and returns: dataset