






'''simple docstring'''





from collections import Counter
from pathlib import Path
from typing import Optional, Tuple

import yaml
class 				lowercase       (							yaml.SafeLoader      ):


    '''simple docstring'''

    def    a__				(					self     :     Optional[Any]				,     __lowerCamelCase     :     Optional[int]     )							->							Any:

          '''simple docstring'''




          lowerCamelCase__  =     [self.constructed_objects[key_node] for key_node, _ in node.value]
          lowerCamelCase__  =     [tuple(__lowerCamelCase     ) if isinstance(__lowerCamelCase				,     __lowerCamelCase     ) else key for key in keys]
          lowerCamelCase__  =     Counter(__lowerCamelCase     )
          lowerCamelCase__  =     [key for key in counter if counter[key] > 1]
          if duplicate_keys:
                raise TypeError(f'''Got duplicate yaml keys: {duplicate_keys}'''     )




    def    a__				(					self     :     Any				,     __lowerCamelCase     :     Union[str, Any]				,     __lowerCamelCase     :     Any=False     )							->							Tuple:

          '''simple docstring'''




          lowerCamelCase__  =     super().construct_mapping(__lowerCamelCase				,     deep=__lowerCamelCase     )
          self._check_no_duplicates_on_constructed_node(__lowerCamelCase     )
          return mapping






def    lowerCamelCase_     (    lowercase__):
      lowerCamelCase__  =     list(readme_content.splitlines())
      if full_content and full_content[0] == "---" and "---" in full_content[1:]:
            lowerCamelCase__  =     full_content[1:].index("---") + 1
            lowerCamelCase__  =     "\n".join(full_content[1:sep_idx])
            return yamlblock, "\n".join(full_content[sep_idx + 1 :])

      return None, "\n".join(lowerCamelCase__)
class 				lowercase       (							_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							{"""train_eval_index"""}  # train-eval-index in the YAML metadata

    @classmethod
    def    a__				(					cls     :     Dict				,     __lowerCamelCase     :     Path     )							->							"DatasetMetadata":

          '''simple docstring'''




          with open(__lowerCamelCase				,     encoding="utf-8"     ) as readme_file:
                lowerCamelCase__  ,	lowerCamelCase__  =     _split_yaml_from_readme(readme_file.read()     )
          if yaml_string is not None:
                return cls.from_yaml_string(__lowerCamelCase     )
          else:
                return cls()

    def    a__				(					self     :     Any				,     __lowerCamelCase     :     Path     )							->							Union[str, Any]:

          '''simple docstring'''




          if path.exists():
                with open(__lowerCamelCase				,     encoding="utf-8"     ) as readme_file:
                      lowerCamelCase__  =     readme_file.read()
          else:
                lowerCamelCase__  =     None
          lowerCamelCase__  =     self._to_readme(__lowerCamelCase     )
          with open(__lowerCamelCase				,     "w"				,     encoding="utf-8"     ) as readme_file:
                readme_file.write(__lowerCamelCase     )

    def    a__				(					self     :     Tuple				,     __lowerCamelCase     :     Optional[str] = None     )							->							str:

          '''simple docstring'''




          if readme_content is not None:
                lowerCamelCase__  ,	lowerCamelCase__  =     _split_yaml_from_readme(__lowerCamelCase     )
                lowerCamelCase__  =     "---\n" + self.to_yaml_string() + "---\n" + content
          else:
                lowerCamelCase__  =     "---\n" + self.to_yaml_string() + "---\n"
          return full_content

    @classmethod
    def    a__				(					cls     :     Optional[int]				,     __lowerCamelCase     :     str     )							->							"DatasetMetadata":

          '''simple docstring'''




          lowerCamelCase__  =     yaml.load(__lowerCamelCase				,     Loader=_NoDuplicateSafeLoader     ) or {}

          # Convert the YAML keys to DatasetMetadata fields
          lowerCamelCase__  =     {
              (key.replace("-"				,     "_"     ) if key.replace("-"				,     "_"     ) in cls._FIELDS_WITH_DASHES else key): value
              for key, value in metadata_dict.items()
          }
          return cls(**__lowerCamelCase     )




    def    a__				(					self     :     Optional[Any]     )							->							str:

          '''simple docstring'''




          return yaml.safe_dump(
              {
                  (key.replace("_"				,     "-"     ) if key in self._FIELDS_WITH_DASHES else key): value
                  for key, value in self.items()
              }				,     sort_keys=__lowerCamelCase				,     allow_unicode=__lowerCamelCase				,     encoding="utf-8"				,     ).decode("utf-8"     )
__A							:							List[Any]  							=		{
    """image-classification""": [],
    """translation""": [],
    """image-segmentation""": [],
    """fill-mask""": [],
    """automatic-speech-recognition""": [],
    """token-classification""": [],
    """sentence-similarity""": [],
    """audio-classification""": [],
    """question-answering""": [],
    """summarization""": [],
    """zero-shot-classification""": [],
    """table-to-text""": [],
    """feature-extraction""": [],
    """other""": [],
    """multiple-choice""": [],
    """text-classification""": [],
    """text-to-image""": [],
    """text2text-generation""": [],
    """zero-shot-image-classification""": [],
    """tabular-classification""": [],
    """tabular-regression""": [],
    """image-to-image""": [],
    """tabular-to-text""": [],
    """unconditional-image-generation""": [],
    """text-retrieval""": [],
    """text-to-speech""": [],
    """object-detection""": [],
    """audio-to-audio""": [],
    """text-generation""": [],
    """conversational""": [],
    """table-question-answering""": [],
    """visual-question-answering""": [],
    """image-to-text""": [],
    """reinforcement-learning""": [],
    """voice-activity-detection""": [],
    """time-series-forecasting""": [],
    """document-question-answering""": [],
}


if __name__ == "__main__":
 from argparse import ArgumentParser

 __A							:							Any  							=		ArgumentParser(usage="""Validate the yaml metadata block of a README.md file.""")
 ap.add_argument("""readme_filepath""")
 __A							:							Union[str, Any]  							=		ap.parse_args()

 __A							:							List[str]  							=		Path(args.readme_filepath)
 __A							:							List[str]  							=		DatasetMetadata.from_readme(readme_filepath)
 print(dataset_metadata)
 dataset_metadata.to_readme(readme_filepath)









'''simple docstring'''





from ..utils import DummyObject, requires_backends
class 				lowercase       (							metaclass=_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							["flax", "transformers"]

    def __init__(					self     :     List[str]				,     *__lowerCamelCase     :     int				,     **__lowerCamelCase     :     Any     )							->							Optional[int]:

     '''simple docstring'''




     requires_backends(self				,     ["flax", "transformers"]     )

    @classmethod
    def    a__				(					cls     :     Any				,     *__lowerCamelCase     :     Optional[int]				,     **__lowerCamelCase     :     Dict     )							->							str:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )




    @classmethod
    def    a__				(					cls     :     str				,     *__lowerCamelCase     :     str				,     **__lowerCamelCase     :     Any     )							->							str:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )
class 				lowercase       (							metaclass=_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							["flax", "transformers"]

    def __init__(					self     :     str				,     *__lowerCamelCase     :     List[Any]				,     **__lowerCamelCase     :     int     )							->							List[str]:

     '''simple docstring'''




     requires_backends(self				,     ["flax", "transformers"]     )

    @classmethod
    def    a__				(					cls     :     Dict				,     *__lowerCamelCase     :     Any				,     **__lowerCamelCase     :     str     )							->							Optional[int]:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )




    @classmethod
    def    a__				(					cls     :     Any				,     *__lowerCamelCase     :     int				,     **__lowerCamelCase     :     Dict     )							->							int:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )
class 				lowercase       (							metaclass=_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							["flax", "transformers"]

    def __init__(					self     :     Dict				,     *__lowerCamelCase     :     str				,     **__lowerCamelCase     :     List[Any]     )							->							str:

     '''simple docstring'''




     requires_backends(self				,     ["flax", "transformers"]     )

    @classmethod
    def    a__				(					cls     :     Optional[int]				,     *__lowerCamelCase     :     Optional[int]				,     **__lowerCamelCase     :     Optional[Any]     )							->							Dict:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )




    @classmethod
    def    a__				(					cls     :     Optional[int]				,     *__lowerCamelCase     :     Dict				,     **__lowerCamelCase     :     List[str]     )							->							Dict:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )
class 				lowercase       (							metaclass=_lowerCamelCase      ):


    '''simple docstring'''

    lowerCAmelCase__      				=							["flax", "transformers"]

    def __init__(					self     :     int				,     *__lowerCamelCase     :     List[str]				,     **__lowerCamelCase     :     int     )							->							Optional[int]:

     '''simple docstring'''




     requires_backends(self				,     ["flax", "transformers"]     )

    @classmethod
    def    a__				(					cls     :     Any				,     *__lowerCamelCase     :     Tuple				,     **__lowerCamelCase     :     str     )							->							List[str]:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )




    @classmethod
    def    a__				(					cls     :     List[Any]				,     *__lowerCamelCase     :     List[str]				,     **__lowerCamelCase     :     List[Any]     )							->							int:

     '''simple docstring'''




     requires_backends(cls				,     ["flax", "transformers"]     )

