





# 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]






import string

import numpy

def 							SCREAMING_SNAKE_CASE__       (  snake_case__  :int			,							snake_case__  :int     )      ->						int:
  return b if a == 0 else greatest_common_divisor(b % a			,							snake_case__     )





class 				A_				:







       """simple docstring"""





       SCREAMING_SNAKE_CASE_      : Dict      =  string.ascii_uppercase + string.digits
       # This cipher takes alphanumerics into account
       # i.e. a total of 36 characters

       # take x and return x % len(key_string)
       SCREAMING_SNAKE_CASE_      : Dict      =  numpy.vectorize(lambda UpperCAmelCase	: x % 3_6	)

       SCREAMING_SNAKE_CASE_      : List[Any]      =  numpy.vectorize(UpperCAmelCase	)







       def __init__(    self	:	Optional[Any]						,__A	:	numpy.ndarray  )						->					None:
         _lowercase							= self.modulus(__A  )  # mod36 calc's on the encrypt key
         self.check_determinant()  # validate the determinant of the encryption key
         _lowercase							= encrypt_key.shape[0]







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	str  )						->					int:
         return self.key_string.index(__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	int  )						->					str:
         return self.key_string[round(__A  )]







       def    __UpperCAmelCase (    self	:	str  )						->					None:
         _lowercase							= round(numpy.linalg.det(self.encrypt_key  )  )

         if det < 0:
           _lowercase							= det % len(self.key_string  )

         _lowercase							= len(self.key_string  )
         if greatest_common_divisor(__A						,len(self.key_string  )  ) != 1:
           _lowercase							= (
               F"""determinant modular {req_l} of encryption key({det}) """
               F"""is not co prime w.r.t {req_l}.\nTry another key."""
           )
           raise ValueError(__A  )







       def    __UpperCAmelCase (    self	:	Any						,__A	:	str  )						->					str:
         _lowercase							= [char for char in text.upper() if char in self.key_string]

         _lowercase							= chars[-1]
         while len(__A  ) % self.break_key != 0:
           chars.append(__A  )

         return "".join(__A  )







       def    __UpperCAmelCase (    self	:	Optional[int]						,__A	:	str  )						->					str:
         _lowercase							= self.process_text(text.upper()  )
         _lowercase							= ''

         for i in range(0						,len(__A  ) - self.break_key + 1						,self.break_key  ):
           _lowercase							= text[i : i + self.break_key]
           _lowercase							= [self.replace_letters(__A  ) for char in batch]
           _lowercase							= numpy.array([vec]  ).T
           _lowercase							= self.modulus(self.encrypt_key.dot(__A  )  ).T.tolist()[
               0
           ]
           _lowercase							= ''.join(
               self.replace_digits(__A  ) for num in batch_encrypted  )
           encrypted += encrypted_batch

         return encrypted







       def    __UpperCAmelCase (    self	:	List[Any]  )						->					numpy.ndarray:
         _lowercase							= round(numpy.linalg.det(self.encrypt_key  )  )

         if det < 0:
           _lowercase							= det % len(self.key_string  )
         _lowercase							= None
         for i in range(len(self.key_string  )  ):
           if (det * i) % len(self.key_string  ) == 1:
             _lowercase							= i
             break

         _lowercase							= (
             det_inv
             * numpy.linalg.det(self.encrypt_key  )
             * numpy.linalg.inv(self.encrypt_key  )
         )

         return self.to_int(self.modulus(__A  )  )







       def    __UpperCAmelCase (    self	:	Tuple						,__A	:	str  )						->					str:
         _lowercase							= self.make_decrypt_key()
         _lowercase							= self.process_text(text.upper()  )
         _lowercase							= ''

         for i in range(0						,len(__A  ) - self.break_key + 1						,self.break_key  ):
           _lowercase							= text[i : i + self.break_key]
           _lowercase							= [self.replace_letters(__A  ) for char in batch]
           _lowercase							= numpy.array([vec]  ).T
           _lowercase							= self.modulus(decrypt_key.dot(__A  )  ).T.tolist()[0]
           _lowercase							= ''.join(
               self.replace_digits(__A  ) for num in batch_decrypted  )
           decrypted += decrypted_batch

         return decrypted

def 							SCREAMING_SNAKE_CASE__       (  )      ->						None:
  _lowercase							= int(input('Enter the order of the encryption key: '     )     )
  _lowercase							= []

  print('Enter each row of the encryption key with space separated integers'     )
  for _ in range(snake_case__     ):
    _lowercase							= [int(snake_case__     ) for x in input().split()]
    hill_matrix.append(snake_case__     )

  _lowercase							= HillCipher(numpy.array(snake_case__     )     )

  print('Would you like to encrypt or decrypt some text? (1 or 2)'     )
  _lowercase							= input('\n1. Encrypt\n2. Decrypt\n'     )
  if option == "1":
    _lowercase							= input('What text would you like to encrypt?: '     )
    print('Your encrypted text is:'     )
    print(hc.encrypt(snake_case__     )     )
  elif option == "2":
    _lowercase							= input('What text would you like to decrypt?: '     )
    print('Your decrypted text is:'     )
    print(hc.decrypt(snake_case__     )     )


if __name__ == "__main__":
      import doctest

      doctest.testmod()

      main()