"""simple docstring"""






import unittest

from transformers import (
    MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING,
    PreTrainedTokenizer,
    is_vision_available,
)
from transformers.pipelines import ImageClassificationPipeline, pipeline
from transformers.testing_utils import (
    is_pipeline_test,
    nested_simplify,
    require_tf,
    require_torch,
    require_torch_or_tf,
    require_vision,
    slow,
)

from .test_pipelines_common import ANY


if is_vision_available():
						from PIL import Image
else:
						class 							snake_case			:




											"""simple docstring"""

											@staticmethod
											def 						__lowerCAmelCase		(							*lowerCamelCase__  :      Optional[int]       ,**lowerCamelCase__  :      List[Any]     ):
															pass
@is_pipeline_test
@require_torch_or_tf
@require_vision
class 							snake_case			(					unittest.TestCase							):




					"""simple docstring"""

					snake_case__							       =					MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING
					snake_case__							       =					TF_MODEL_FOR_IMAGE_CLASSIFICATION_MAPPING







					def 						__lowerCAmelCase		(							self  :      Dict       ,lowerCamelCase__  :      Optional[Any]       ,lowerCamelCase__  :      Optional[int]       ,lowerCamelCase__  :      Union[str, Any]     ):
									UpperCAmelCase__			 =				ImageClassificationPipeline(model=lowerCamelCase__       ,image_processor=lowerCamelCase__       ,top_k=2     )
									UpperCAmelCase__			 =				[
									    Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     ),
									    'http://images.cocodataset.org/val2017/000000039769.jpg',
									]
									return image_classifier, examples







					def 						__lowerCAmelCase		(							self  :      Optional[Any]       ,lowerCamelCase__  :      Dict       ,lowerCamelCase__  :      Optional[int]     ):
									UpperCAmelCase__			 =				image_classifier('./tests/fixtures/tests_samples/COCO/000000039769.png'     )

									self.assertEqual(
									    lowerCamelCase__       ,[
									        {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									        {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									    ]       ,)

									import datasets

									UpperCAmelCase__			 =				datasets.load_dataset('hf-internal-testing/fixtures_image_utils'       ,'image'       ,split='test'     )

									# Accepts URL + PIL.Image + lists
									UpperCAmelCase__			 =				image_classifier(
									    [
									        Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'     ),
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									        # RGBA
									        dataset[0]['file'],
									        # LA
									        dataset[1]['file'],
									        # L
									        dataset[2]['file'],
									    ]     )
									self.assertEqual(
									    lowerCamelCase__       ,[
									        [
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									        ],
									        [
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									        ],
									        [
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									        ],
									        [
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									        ],
									        [
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									            {'score': ANY(lowerCamelCase__     ), 'label': ANY(lowerCamelCase__     )},
									        ],
									    ]       ,)







					@require_torch
					def 						__lowerCAmelCase		(							self  :      Any     ):
									UpperCAmelCase__			 =				'hf-internal-testing/tiny-random-vit'
									UpperCAmelCase__			 =				pipeline('image-classification'       ,model=lowerCamelCase__     )

									UpperCAmelCase__			 =				image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
									self.assertEqual(
									    nested_simplify(lowerCamelCase__       ,decimals=4     )       ,[{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}]       ,)

									UpperCAmelCase__			 =				image_classifier(
									    [
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									    ]       ,top_k=2       ,)
									self.assertEqual(
									    nested_simplify(lowerCamelCase__       ,decimals=4     )       ,[
									        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
									        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
									    ]       ,)







					@require_tf
					def 						__lowerCAmelCase		(							self  :      Optional[Any]     ):
									UpperCAmelCase__			 =				'hf-internal-testing/tiny-random-vit'
									UpperCAmelCase__			 =				pipeline('image-classification'       ,model=lowerCamelCase__       ,framework='tf'     )

									UpperCAmelCase__			 =				image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
									self.assertEqual(
									    nested_simplify(lowerCamelCase__       ,decimals=4     )       ,[{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}]       ,)

									UpperCAmelCase__			 =				image_classifier(
									    [
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									        'http://images.cocodataset.org/val2017/000000039769.jpg',
									    ]       ,top_k=2       ,)
									self.assertEqual(
									    nested_simplify(lowerCamelCase__       ,decimals=4     )       ,[
									        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
									        [{'label': 'LABEL_1', 'score': 0.5_7_4}, {'label': 'LABEL_0', 'score': 0.4_2_6}],
									    ]       ,)







					def 						__lowerCAmelCase		(							self  :      Optional[Any]     ):
									UpperCAmelCase__			 =				PreTrainedTokenizer()

									# Assert that the pipeline can be initialized with a feature extractor that is not in any mapping
									UpperCAmelCase__			 =				pipeline(
									    'image-classification'       ,model='hf-internal-testing/tiny-random-vit'       ,tokenizer=lowerCamelCase__     )

									self.assertIs(image_classifier.tokenizer       ,lowerCamelCase__     )







					@slow
					@require_torch
					def 						__lowerCAmelCase		(							self  :      str     ):
									# Perceiver is not tested by `run_pipeline_test` properly.
									# That is because the type of feature_extractor and model preprocessor need to be kept
									# in sync, which is not the case in the current design
									UpperCAmelCase__			 =				pipeline('image-classification'       ,model='deepmind/vision-perceiver-conv'     )
									UpperCAmelCase__			 =				image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
									self.assertEqual(
									    nested_simplify(lowerCamelCase__       ,decimals=4     )       ,[
									        {'score': 0.4_3_8_5, 'label': 'tabby, tabby cat'},
									        {'score': 0.3_2_1, 'label': 'tiger cat'},
									        {'score': 0.0_5_0_2, 'label': 'Egyptian cat'},
									        {'score': 0.0_1_3_7, 'label': 'crib, cot'},
									        {'score': 0.0_0_7, 'label': 'radiator'},
									    ]       ,)

									UpperCAmelCase__			 =				pipeline('image-classification'       ,model='deepmind/vision-perceiver-fourier'     )
									UpperCAmelCase__			 =				image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
									self.assertEqual(
									    nested_simplify(lowerCamelCase__       ,decimals=4     )       ,[
									        {'score': 0.5_6_5_8, 'label': 'tabby, tabby cat'},
									        {'score': 0.1_3_0_9, 'label': 'tiger cat'},
									        {'score': 0.0_7_2_2, 'label': 'Egyptian cat'},
									        {'score': 0.0_7_0_7, 'label': 'remote control, remote'},
									        {'score': 0.0_0_8_2, 'label': 'computer keyboard, keypad'},
									    ]       ,)

									UpperCAmelCase__			 =				pipeline('image-classification'       ,model='deepmind/vision-perceiver-learned'     )
									UpperCAmelCase__			 =				image_classifier('http://images.cocodataset.org/val2017/000000039769.jpg'     )
									self.assertEqual(
									    nested_simplify(lowerCamelCase__       ,decimals=4     )       ,[
									        {'score': 0.3_0_2_2, 'label': 'tabby, tabby cat'},
									        {'score': 0.2_3_6_2, 'label': 'Egyptian cat'},
									        {'score': 0.1_8_5_6, 'label': 'tiger cat'},
									        {'score': 0.0_3_2_4, 'label': 'remote control, remote'},
									        {'score': 0.0_0_9_6, 'label': 'quilt, comforter, comfort, puff'},
									    ]       ,)




"""simple docstring"""






import requests

try:
						from django.contrib.auth import authenticate, login
						from django.shortcuts import redirect, render
except ImportError:
						lowerCAmelCase__    :    Union[str, Any]			=      print



def     a_		(   lowerCamelCase			):
				# Enter your recaptcha secret key here
				UpperCAmelCase__			 =				'secretKey'
				UpperCAmelCase__			 =				'https://www.google.com/recaptcha/api/siteverify'

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

				# from the frontend, get username, password, and client_key
				UpperCAmelCase__			 =				request.POST.get('username'			)
				UpperCAmelCase__			 =				request.POST.get('password'			)
				UpperCAmelCase__			 =				request.POST.get('g-recaptcha-response'			)

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



