

'''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  )    ->			str:

   '''simple docstring'''





   _lowercase    :   int      =     """secretKey"""
   _lowercase    :   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    :   List[Any]      =     request.POST.get("username"  )
   _lowercase    :   Optional[Any]      =     request.POST.get("password"  )
   _lowercase    :   List[str]      =     request.POST.get("g-recaptcha-response"  )

   # post recaptcha response to Google's recaptcha api
   _lowercase    :   Any      =     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    :   List[str]      =     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"  )









'''simple docstring'''
import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import TvltImageProcessor







def       _A	(			snake_case	,							snake_case=10	,							snake_case=10	,							snake_case=False	,							snake_case=False  )    ->			List[Any]:
   _lowercase    :   Dict      =     []
   for i in range(image_processor_tester.num_frames  ):
      video.append(np.random.randint(2_55	,							size=(image_processor_tester.num_channels, width, height)	,							dtype=np.uinta  )  )

   if not numpify and not torchify:
      # PIL expects the channel dimension as last dimension
      _lowercase    :   Union[str, Any]      =     [Image.fromarray(np.moveaxis(snake_case	,							0	,							-1  )  ) for frame in video]

   if torchify:
      _lowercase    :   Any      =     [torch.from_numpy(snake_case  ) for frame in video]

   return video







def       _A	(			snake_case	,							snake_case=False	,							snake_case=False	,							snake_case=False  )    ->			Tuple:
   assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

   _lowercase    :   Optional[Any]      =     []
   for i in range(image_processor_tester.batch_size  ):
      if equal_resolution:
         _lowercase    :   List[Any]      =     image_processor_tester.max_resolution
      else:
         _lowercase  ,   _lowercase    :   Dict      =     np.random.choice(
             np.arange(image_processor_tester.min_resolution	,							image_processor_tester.max_resolution  )	,							2  )
         _lowercase    :   List[Any]      =     prepare_video(
             image_processor_tester=snake_case	,							width=snake_case	,							height=snake_case	,							numpify=snake_case	,							torchify=snake_case	,							)
      video_inputs.append(snake_case  )

   return video_inputs


class      a__						(							unittest.TestCase						):


   def __init__(				self    ,       _UpperCamelCase    ,       _UpperCamelCase=7    ,       _UpperCamelCase=3    ,       _UpperCamelCase=4    ,       _UpperCamelCase=18    ,       _UpperCamelCase=30    ,       _UpperCamelCase=400    ,       _UpperCamelCase=True    ,       _UpperCamelCase=None    ,       _UpperCamelCase=True    ,       _UpperCamelCase=[0.5, 0.5, 0.5]    ,       _UpperCamelCase=[0.5, 0.5, 0.5]    ,       _UpperCamelCase=True    ,       _UpperCamelCase=None    ,       ):





      """simple docstring"""





      _lowercase    :   List[str]      =     size if size is not None else {"shortest_edge": 18}
      _lowercase    :   Any      =     crop_size if crop_size is not None else {"height": 18, "width": 18}

      _lowercase    :   Dict      =     parent
      _lowercase    :   Optional[Any]      =     batch_size
      _lowercase    :   List[Any]      =     num_channels
      _lowercase    :   Optional[Any]      =     num_frames
      _lowercase    :   int      =     image_size
      _lowercase    :   Optional[int]      =     min_resolution
      _lowercase    :   Optional[int]      =     max_resolution
      _lowercase    :   Optional[Any]      =     do_resize
      _lowercase    :   Dict      =     size
      _lowercase    :   Any      =     do_normalize
      _lowercase    :   Tuple      =     image_mean
      _lowercase    :   Union[str, Any]      =     image_std
      _lowercase    :   Tuple      =     do_center_crop
      _lowercase    :   str      =     crop_size






   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      return {
          "image_mean": self.image_mean,
          "image_std": self.image_std,
          "do_normalize": self.do_normalize,
          "do_resize": self.do_resize,
          "size": self.size,
          "do_center_crop": self.do_center_crop,
          "crop_size": self.crop_size,
      }




@require_torch
@require_vision
class      a__						(							lowerCamelCase_						,   unittest.TestCase						):
   _SCREAMING_SNAKE_CASE					:  List[str]			 =							TvltImageProcessor if is_vision_available() else None


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Optional[Any]      =     TvltImageProcessorTester(self						)


   @property
   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      return self.image_processor_tester.prepare_image_processor_dict()


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   int      =     self.image_processing_class(**self.image_processor_dict						)
      self.assertTrue(hasattr(_UpperCamelCase    ,       "image_mean"						)						)
      self.assertTrue(hasattr(_UpperCamelCase    ,       "image_std"						)						)
      self.assertTrue(hasattr(_UpperCamelCase    ,       "do_normalize"						)						)
      self.assertTrue(hasattr(_UpperCamelCase    ,       "do_resize"						)						)
      self.assertTrue(hasattr(_UpperCamelCase    ,       "do_center_crop"						)						)
      self.assertTrue(hasattr(_UpperCamelCase    ,       "size"						)						)


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Any      =     self.image_processing_class(**self.image_processor_dict						)
      # create random PIL videos
      _lowercase    :   Any      =     prepare_video_inputs(self.image_processor_tester    ,       equal_resolution=_UpperCamelCase						)
      for video in video_inputs:
         self.assertIsInstance(_UpperCamelCase    ,       _UpperCamelCase						)
         self.assertIsInstance(video[0]    ,       Image.Image						)

      # Test not batched input
      _lowercase    :   Any      =     image_processor(video_inputs[0]    ,       return_tensors="pt"						).pixel_values
      self.assertEqual(
          encoded_videos.shape    ,       (
              1,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )    ,       )

      # Test batched
      _lowercase    :   Union[str, Any]      =     image_processor(_UpperCamelCase    ,       return_tensors="pt"						).pixel_values
      self.assertEqual(
          encoded_videos.shape    ,       (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )    ,       )


   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Optional[Any]      =     self.image_processing_class(**self.image_processor_dict						)
      # create random numpy tensors
      _lowercase    :   List[str]      =     prepare_video_inputs(self.image_processor_tester    ,       equal_resolution=_UpperCamelCase    ,       numpify=_UpperCamelCase						)
      for video in video_inputs:
         self.assertIsInstance(_UpperCamelCase    ,       _UpperCamelCase						)
         self.assertIsInstance(video[0]    ,       np.ndarray						)

      # Test not batched input
      _lowercase    :   Optional[int]      =     image_processor(video_inputs[0]    ,       return_tensors="pt"						).pixel_values
      self.assertEqual(
          encoded_videos.shape    ,       (
              1,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )    ,       )

      # Test batched
      _lowercase    :   List[Any]      =     image_processor(_UpperCamelCase    ,       return_tensors="pt"						).pixel_values
      self.assertEqual(
          encoded_videos.shape    ,       (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )    ,       )






   def 		_lowerCamelCase     (				self						):





      """simple docstring"""





      _lowercase    :   Dict      =     self.image_processing_class(**self.image_processor_dict						)
      # create random PyTorch tensors
      _lowercase    :   Optional[int]      =     prepare_video_inputs(self.image_processor_tester    ,       equal_resolution=_UpperCamelCase    ,       torchify=_UpperCamelCase						)
      for video in video_inputs:
         self.assertIsInstance(_UpperCamelCase    ,       _UpperCamelCase						)
         self.assertIsInstance(video[0]    ,       torch.Tensor						)

      # Test not batched input
      _lowercase    :   int      =     image_processor(video_inputs[0]    ,       return_tensors="pt"						).pixel_values
      self.assertEqual(
          encoded_videos.shape    ,       (
              1,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )    ,       )

      # Test batched
      _lowercase    :   List[Any]      =     image_processor(_UpperCamelCase    ,       return_tensors="pt"						).pixel_values
      self.assertEqual(
          encoded_videos.shape    ,       (
              self.image_processor_tester.batch_size,
              self.image_processor_tester.num_frames,
              self.image_processor_tester.num_channels,
              self.image_processor_tester.crop_size["height"],
              self.image_processor_tester.crop_size["width"],
          )    ,       )






