


# 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 _lowerCamelCase(						_a   ):
       lowercase_ :	int     =			"""openai/whisper-base"""
       lowercase_ :	Union[str, Any]     =			(
           """This is a tool that transcribes an audio into text. It takes an input named `audio` and returns the """
           """transcribed text."""
       )
       lowercase_ :	Any     =			"""transcriber"""
       lowercase_ :	List[Any]     =			WhisperProcessor
       lowercase_ :	List[str]     =			WhisperForConditionalGeneration

       lowercase_ :	Any     =			["""audio"""]
       lowercase_ :	Union[str, Any]     =			["""text"""]
       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   Tuple:




           """simple docstring"""

           return self.pre_processor(lowerCamelCase,      return_tensors='pt').input_features
       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   List[str]:




           """simple docstring"""

           return self.model.generate(inputs=lowerCamelCase)




       def 			UpperCamelCase     (					self,      lowerCamelCase)       ->   Optional[Any]:




           """simple docstring"""

           return self.pre_processor.batch_decode(lowerCamelCase,      skip_special_tokens=lowerCamelCase)[0]




"""simple docstring"""




import os
import unittest

from transformers.models.cpmant.tokenization_cpmant import VOCAB_FILES_NAMES, CpmAntTokenizer
from transformers.testing_utils import require_jieba, tooslow

from ...test_tokenization_common import TokenizerTesterMixin

@require_jieba
class 		a__						(      a_,			unittest.TestCase						):
   __lowerCAmelCase            =				CpmAntTokenizer
   __lowerCAmelCase            =				False
   def 			__magic_name__			(			self				):
          super().setUp()

          lowercase    :				List[str]       		=							[
              "<d>",
              "</d>",
              "<s>",
              "</s>",
              "</_>",
              "<unk>",
              "<pad>",
              "</n>",
              "我",
              "是",
              "C",
              "P",
              "M",
              "A",
              "n",
              "t",
          ]
          lowercase    :				Dict       		=							os.path.join(self.tmpdirname	,    VOCAB_FILES_NAMES["vocab_file"]				)
          with open(self.vocab_file	,    "w"	,    encoding="utf-8"				) as vocab_writer:
                 vocab_writer.write("".join([x + "\n" for x in vocab_tokens]				)				)

   @tooslow
   def 			__magic_name__			(			self				):
          lowercase    :				Tuple       		=							CpmAntTokenizer.from_pretrained("openbmb/cpm-ant-10b"				)
          lowercase    :				str       		=							"今天天气真好！"
          lowercase    :				Optional[int]       		=							["今天", "天气", "真", "好", "！"]
          lowercase    :				int       		=							tokenizer.tokenize(_a				)
          self.assertListEqual(_a	,    _a				)
          lowercase    :				Any       		=							"今天天气真好！"
          lowercase    :				int       		=							[tokenizer.bos_token] + tokens

          lowercase    :				List[str]       		=							[6, 9_802, 14_962, 2_082, 831, 244]
          self.assertListEqual(tokenizer.convert_tokens_to_ids(_a				)	,    _a				)

          lowercase    :				str       		=							tokenizer.decode(_a				)
          self.assertEqual(_a	,    _a				)


