

# Copyright 2023 The HuggingFace Inc. team. All rights reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from ..models.whisper import WhisperForConditionalGeneration, WhisperProcessor
from .base import PipelineTool





class 				A_				(      UpperCAmelCase	):







       """simple docstring"""





       SCREAMING_SNAKE_CASE_      : Dict      =  '''openai/whisper-base'''
       SCREAMING_SNAKE_CASE_      : List[Any]      =  (
           '''This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the '''
           '''transcribed text.'''
       )
       SCREAMING_SNAKE_CASE_      : List[Any]      =  '''transcriber'''
       SCREAMING_SNAKE_CASE_      : List[Any]      =  WhisperProcessor
       SCREAMING_SNAKE_CASE_      : Any      =  WhisperForConditionalGeneration

       SCREAMING_SNAKE_CASE_      : Dict      =  ['''audio''']
       SCREAMING_SNAKE_CASE_      : Any      =  ['''text''']







       def    __UpperCAmelCase (    self	:	int						,__A	:	List[Any]  )						->					List[Any]:
         return self.pre_processor(__A						,return_tensors='pt'  ).input_features







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	List[Any]  )						->					Dict:
         return self.model.generate(inputs=__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	Dict  )						->					Union[str, Any]:
         return self.pre_processor.batch_decode(__A						,skip_special_tokens=__A  )[0]






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

import yaml





class 				A_				(      yaml.SafeLoader	):







       """simple docstring"""





       def    __UpperCAmelCase (    self	:	Dict						,__A	:	List[Any]  )						->					Any:
         _lowercase							= [self.constructed_objects[key_node] for key_node, _ in node.value]
         _lowercase							= [tuple(__A  ) if isinstance(__A						,__A  ) else key for key in keys]
         _lowercase							= Counter(__A  )
         _lowercase							= [key for key in counter if counter[key] > 1]
         if duplicate_keys:
           raise TypeError(F"""Got duplicate yaml keys: {duplicate_keys}"""  )







       def    __UpperCAmelCase (    self	:	Any						,__A	:	int						,__A	:	Dict=False  )						->					Union[str, Any]:
         _lowercase							= super().construct_mapping(__A						,deep=__A  )
         self._check_no_duplicates_on_constructed_node(__A  )
         return mapping

def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :str     )      ->						Tuple[Optional[str], str]:
  _lowercase							= list(readme_content.splitlines()     )
  if full_content and full_content[0] == "---" and "---" in full_content[1:]:
    _lowercase							= full_content[1:].index('---'     ) + 1
    _lowercase							= '\n'.join(full_content[1:sep_idx]     )
    return yamlblock, "\n".join(full_content[sep_idx + 1 :]     )

  return None, "\n".join(snake_case__     )





class 				A_				(      UpperCAmelCase	):







       """simple docstring"""





       SCREAMING_SNAKE_CASE_      : Any      =  {'''train_eval_index'''}  # train-eval-index in the YAML metadata







       @classmethod
       def    __UpperCAmelCase (    cls	:	List[Any]						,__A	:	Path  )						->					"DatasetMetadata":
         with open(__A						,encoding='utf-8'  ) as readme_file:
           _lowercase						,		_lowercase							= _split_yaml_from_readme(readme_file.read()  )
         if yaml_string is not None:
           return cls.from_yaml_string(__A  )
         else:
           return cls()







       def    __UpperCAmelCase (    self	:	Union[str, Any]						,__A	:	Path  )						->					Optional[Any]:
         if path.exists():
           with open(__A						,encoding='utf-8'  ) as readme_file:
             _lowercase							= readme_file.read()
         else:
           _lowercase							= None
         _lowercase							= self._to_readme(__A  )
         with open(__A						,'w'						,encoding='utf-8'  ) as readme_file:
           readme_file.write(__A  )







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	Optional[str] = None  )						->					str:
         if readme_content is not None:
           _lowercase						,		_lowercase							= _split_yaml_from_readme(__A  )
           _lowercase							= '---\n' + self.to_yaml_string() + '---\n' + content
         else:
           _lowercase							= '---\n' + self.to_yaml_string() + '---\n'
         return full_content







       @classmethod
       def    __UpperCAmelCase (    cls	:	List[Any]						,__A	:	str  )						->					"DatasetMetadata":
         _lowercase							= yaml.load(__A						,Loader=_NoDuplicateSafeLoader  ) or {}

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







       def    __UpperCAmelCase (    self	:	Optional[int]  )						->					str:
         return yaml.safe_dump(
             {
                 (key.replace('_'						,'-'  ) if key in self._FIELDS_WITH_DASHES else key): value
                 for key, value in self.items()
             }						,sort_keys=__A						,allow_unicode=__A						,encoding='utf-8'						,).decode('utf-8'  )
snake_case 				=       {
    """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

      snake_case 				=       ArgumentParser(usage="""Validate the yaml metadata block of a README.md file.""")
      ap.add_argument("""readme_filepath""")
      snake_case 				=       ap.parse_args()

      snake_case 				=       Path(args.readme_filepath)
      snake_case 				=       DatasetMetadata.from_readme(readme_filepath)
      print(dataset_metadata)
      dataset_metadata.to_readme(readme_filepath)