

'''simple docstring'''
import shutil
import tempfile
import unittest

import pytest

from transformers import WhisperTokenizer, is_speech_available
from transformers.testing_utils import require_sentencepiece, require_torch, require_torchaudio

from .test_feature_extraction_whisper import floats_list


if is_speech_available():
    from transformers import WhisperFeatureExtractor, WhisperProcessor


_snake_case     						=						50_358
_snake_case     						=						50_362


@require_torch
@require_torchaudio
@require_sentencepiece
class      a__						(							unittest.TestCase						):


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   List[str]      =     "openai/whisper-small.en"
      _lowercase    :   Tuple      =     tempfile.mkdtemp()


   def 		_lowerCamelCase     (				self    ,       **_UpperCamelCase						):





      """simple docstring"""





      return WhisperTokenizer.from_pretrained(self.checkpoint    ,       **_UpperCamelCase						)


   def 		_lowerCamelCase     (				self    ,       **_UpperCamelCase						):





      """simple docstring"""





      return WhisperFeatureExtractor.from_pretrained(self.checkpoint    ,       **_UpperCamelCase						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      shutil.rmtree(self.tmpdirname						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   str      =     self.get_tokenizer()
      _lowercase    :   Dict      =     self.get_feature_extractor()

      _lowercase    :   Any      =     WhisperProcessor(tokenizer=_UpperCamelCase    ,       feature_extractor=_UpperCamelCase						)

      processor.save_pretrained(self.tmpdirname						)
      _lowercase    :   List[Any]      =     WhisperProcessor.from_pretrained(self.tmpdirname						)

      self.assertEqual(processor.tokenizer.get_vocab()    ,       tokenizer.get_vocab()						)
      self.assertIsInstance(processor.tokenizer    ,       _UpperCamelCase						)

      self.assertEqual(processor.feature_extractor.to_json_string()    ,       feature_extractor.to_json_string()						)
      self.assertIsInstance(processor.feature_extractor    ,       _UpperCamelCase						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Tuple      =     WhisperProcessor(tokenizer=self.get_tokenizer()    ,       feature_extractor=self.get_feature_extractor()						)
      processor.save_pretrained(self.tmpdirname						)

      _lowercase    :   Union[str, Any]      =     self.get_tokenizer(bos_token="(BOS)"    ,       eos_token="(EOS)"						)
      _lowercase    :   List[str]      =     self.get_feature_extractor(do_normalize=_UpperCamelCase    ,       padding_value=1.0						)

      _lowercase    :   Union[str, Any]      =     WhisperProcessor.from_pretrained(
          self.tmpdirname    ,       bos_token="(BOS)"    ,       eos_token="(EOS)"    ,       do_normalize=_UpperCamelCase    ,       padding_value=1.0						)

      self.assertEqual(processor.tokenizer.get_vocab()    ,       tokenizer_add_kwargs.get_vocab()						)
      self.assertIsInstance(processor.tokenizer    ,       _UpperCamelCase						)

      self.assertEqual(processor.feature_extractor.to_json_string()    ,       feature_extractor_add_kwargs.to_json_string()						)
      self.assertIsInstance(processor.feature_extractor    ,       _UpperCamelCase						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   List[str]      =     self.get_feature_extractor()
      _lowercase    :   Optional[Any]      =     self.get_tokenizer()

      _lowercase    :   int      =     WhisperProcessor(tokenizer=_UpperCamelCase    ,       feature_extractor=_UpperCamelCase						)

      _lowercase    :   Any      =     floats_list((3, 1000)						)

      _lowercase    :   Dict      =     feature_extractor(_UpperCamelCase    ,       return_tensors="np"						)
      _lowercase    :   Dict      =     processor(_UpperCamelCase    ,       return_tensors="np"						)

      for key in input_feat_extract.keys():
         self.assertAlmostEqual(input_feat_extract[key].sum()    ,       input_processor[key].sum()    ,       delta=1E-2						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   List[str]      =     self.get_feature_extractor()
      _lowercase    :   str      =     self.get_tokenizer()

      _lowercase    :   Dict      =     WhisperProcessor(tokenizer=_UpperCamelCase    ,       feature_extractor=_UpperCamelCase						)

      _lowercase    :   Any      =     "This is a test string"

      _lowercase    :   str      =     processor(text=_UpperCamelCase						)

      _lowercase    :   Union[str, Any]      =     tokenizer(_UpperCamelCase						)

      for key in encoded_tok.keys():
         self.assertListEqual(encoded_tok[key]    ,       encoded_processor[key]						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   List[str]      =     self.get_feature_extractor()
      _lowercase    :   List[Any]      =     self.get_tokenizer()

      _lowercase    :   Optional[Any]      =     WhisperProcessor(tokenizer=_UpperCamelCase    ,       feature_extractor=_UpperCamelCase						)

      _lowercase    :   int      =     [[1, 4, 5, 8, 1, 0, 8], [3, 4, 3, 1, 1, 8, 9]]

      _lowercase    :   Optional[int]      =     processor.batch_decode(_UpperCamelCase						)
      _lowercase    :   Optional[int]      =     tokenizer.batch_decode(_UpperCamelCase						)

      self.assertListEqual(_UpperCamelCase    ,       _UpperCamelCase						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Optional[Any]      =     self.get_feature_extractor()
      _lowercase    :   Union[str, Any]      =     self.get_tokenizer()

      _lowercase    :   Dict      =     WhisperProcessor(tokenizer=_UpperCamelCase    ,       feature_extractor=_UpperCamelCase						)

      self.assertListEqual(
          processor.model_input_names    ,       feature_extractor.model_input_names    ,       msg="`processor` and `feature_extractor` model input names do not match"    ,       )


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Dict      =     self.get_feature_extractor()
      _lowercase    :   Any      =     self.get_tokenizer()

      _lowercase    :   Dict      =     WhisperProcessor(tokenizer=_UpperCamelCase    ,       feature_extractor=_UpperCamelCase						)
      _lowercase    :   Tuple      =     processor.get_decoder_prompt_ids(task="transcribe"    ,       no_timestamps=_UpperCamelCase						)

      self.assertIsInstance(_UpperCamelCase    ,       _UpperCamelCase						)
      for ids in forced_decoder_ids:
         self.assertIsInstance(_UpperCamelCase    ,       (list, tuple)						)

      _lowercase    :   int      =     [TRANSCRIBE, NOTIMESTAMPS]
      self.assertListEqual([ids[-1] for ids in forced_decoder_ids]    ,       _UpperCamelCase						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   List[str]      =     WhisperProcessor(tokenizer=self.get_tokenizer()    ,       feature_extractor=self.get_feature_extractor()						)
      _lowercase    :   Any      =     processor.get_prompt_ids("Mr. Quilter"						)
      _lowercase    :   int      =     processor.tokenizer.decode(_UpperCamelCase						)

      self.assertListEqual(prompt_ids.tolist()    ,       [50360, 1770, 13, 2264, 346, 353]						)
      self.assertEqual(_UpperCamelCase    ,       "<|startofprev|> Mr. Quilter"						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Optional[Any]      =     WhisperProcessor(tokenizer=self.get_tokenizer()    ,       feature_extractor=self.get_feature_extractor()						)
      _lowercase    :   Optional[Any]      =     processor.get_prompt_ids(""						)
      _lowercase    :   Tuple      =     processor.tokenizer.decode(_UpperCamelCase						)

      self.assertListEqual(prompt_ids.tolist()    ,       [50360, 220]						)
      self.assertEqual(_UpperCamelCase    ,       "<|startofprev|> "						)






   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Optional[Any]      =     WhisperProcessor(tokenizer=self.get_tokenizer()    ,       feature_extractor=self.get_feature_extractor()						)

      def _test_prompt_error_raised_helper(_UpperCamelCase    ,       _UpperCamelCase						):
         with pytest.raises(_UpperCamelCase						) as excinfo:
            processor.get_prompt_ids(_UpperCamelCase						)
         _lowercase    :   Any      =     f'''Encountered text in the prompt corresponding to disallowed special token: {special_token}.'''
         self.assertEqual(_UpperCamelCase    ,       str(excinfo.value						)						)

      _test_prompt_error_raised_helper("<|startofprev|> test"    ,       "<|startofprev|>"						)
      _test_prompt_error_raised_helper("test <|notimestamps|>"    ,       "<|notimestamps|>"						)
      _test_prompt_error_raised_helper("test <|zh|> test <|transcribe|>"    ,       "<|zh|>"						)








'''simple docstring'''
import requests

try:
    from django.contrib.auth import authenticate, login
    from django.shortcuts import redirect, render
except ImportError:
    _snake_case     						=						_snake_case     						=						_snake_case     						=						_snake_case     						=						print







def       _A	(			snake_case  )    ->			Any:
   # Enter your recaptcha secret key here
   _lowercase    :   Optional[Any]      =     "secretKey"
   _lowercase    :   Union[str, Any]      =     "https://www.google.com/recaptcha/api/siteverify"

   # when method is not POST, direct user to login page
   if request.method != "POST":
      return render(snake_case	,							"login.html"  )

   # from the frontend, get username, password, and client_key
   _lowercase    :   Optional[int]      =     request.POST.get("username"  )
   _lowercase    :   Tuple      =     request.POST.get("password"  )
   _lowercase    :   Tuple      =     request.POST.get("g-recaptcha-response"  )

   # post recaptcha response to Google's recaptcha api
   _lowercase    :   str      =     requests.post(snake_case	,							data={"secret": secret_key, "response": client_key}  )
   # if the recaptcha api verified our keys
   if response.json().get("success"	,							snake_case  ):
      # authenticate the user
      _lowercase    :   Tuple      =     authenticate(snake_case	,							username=snake_case	,							password=snake_case  )
      if user_in_database:
         login(snake_case	,							snake_case  )
         return redirect("/your-webpage"  )
   return render(snake_case	,							"login.html"  )






