code: 
  
  """simple docstring"""
  import inspect
  import unittest
  
  from transformers import SwinaSRConfig
  from transformers.testing_utils import require_torch, require_vision, slow, torch_device
  from transformers.utils import is_torch_available, is_vision_available
  
  from ...test_configuration_common import ConfigTester
  from ...test_modeling_common import ModelTesterMixin, _config_zero_init, floats_tensor, ids_tensor
  from ...test_pipeline_mixin import PipelineTesterMixin
  
  
  if is_torch_available():
      import torch
      from torch import nn
  
      from transformers import SwinaSRForImageSuperResolution, SwinaSRModel
      from transformers.models.swinasr.modeling_swinasr import SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST
  
  if is_vision_available():
      from PIL import Image
  
      from transformers import SwinaSRImageProcessor
  
  class 			lowerCamelCase  :
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def __init__(self       ,					_lowerCamelCase       ,					_lowerCamelCase=13       ,					_lowerCamelCase=32       ,					_lowerCamelCase=1       ,					_lowerCamelCase=3       ,					_lowerCamelCase=16       ,					_lowerCamelCase=[1, 2, 1]       ,					_lowerCamelCase=[2, 2, 4]       ,					_lowerCamelCase=2       ,					_lowerCamelCase=2.0       ,					_lowerCamelCase=True       ,					_lowerCamelCase=0.0       ,					_lowerCamelCase=0.0       ,					_lowerCamelCase=0.1       ,					_lowerCamelCase="gelu"       ,					_lowerCamelCase=False       ,					_lowerCamelCase=True       ,					_lowerCamelCase=0.02       ,					_lowerCamelCase=1e-5       ,					_lowerCamelCase=True       ,					_lowerCamelCase=None       ,					_lowerCamelCase=False       ,					_lowerCamelCase=2       ,					):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Optional[Any]						=						parent
          UpperCAmelCase__ :       Any						=						batch_size
          UpperCAmelCase__ :       List[Any]						=						image_size
          UpperCAmelCase__ :       Union[str, Any]						=						patch_size
          UpperCAmelCase__ :       List[Any]						=						num_channels
          UpperCAmelCase__ :       Optional[Any]						=						embed_dim
          UpperCAmelCase__ :       List[str]						=						depths
          UpperCAmelCase__ :       List[str]						=						num_heads
          UpperCAmelCase__ :       Any						=						window_size
          UpperCAmelCase__ :       int						=						mlp_ratio
          UpperCAmelCase__ :       Tuple						=						qkv_bias
          UpperCAmelCase__ :       Union[str, Any]						=						hidden_dropout_prob
          UpperCAmelCase__ :       str						=						attention_probs_dropout_prob
          UpperCAmelCase__ :       Tuple						=						drop_path_rate
          UpperCAmelCase__ :       int						=						hidden_act
          UpperCAmelCase__ :       Optional[Any]						=						use_absolute_embeddings
          UpperCAmelCase__ :       Union[str, Any]						=						patch_norm
          UpperCAmelCase__ :       str						=						layer_norm_eps
          UpperCAmelCase__ :       Union[str, Any]						=						initializer_range
          UpperCAmelCase__ :       str						=						is_training
          UpperCAmelCase__ :       List[Any]						=						scope
          UpperCAmelCase__ :       Optional[int]						=						use_labels
          UpperCAmelCase__ :       List[Any]						=						upscale
  
          # here we set some attributes to make tests pass
          UpperCAmelCase__ :       Optional[int]						=						len(_lowerCamelCase  )
          UpperCAmelCase__ :       Union[str, Any]						=						embed_dim
          UpperCAmelCase__ :       Union[str, Any]						=						(image_size // patch_size) ** 2
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       int						=						floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]  )
  
          UpperCAmelCase__ :       List[str]						=						None
          if self.use_labels:
                UpperCAmelCase__ :       Optional[int]						=						ids_tensor([self.batch_size]       ,					self.type_sequence_label_size  )
  
          UpperCAmelCase__ :       List[str]						=						self.get_config()
  
          return config, pixel_values, labels
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          return SwinaSRConfig(
              image_size=self.image_size       ,					patch_size=self.patch_size       ,					num_channels=self.num_channels       ,					embed_dim=self.embed_dim       ,					depths=self.depths       ,					num_heads=self.num_heads       ,					window_size=self.window_size       ,					mlp_ratio=self.mlp_ratio       ,					qkv_bias=self.qkv_bias       ,					hidden_dropout_prob=self.hidden_dropout_prob       ,					attention_probs_dropout_prob=self.attention_probs_dropout_prob       ,					drop_path_rate=self.drop_path_rate       ,					hidden_act=self.hidden_act       ,					use_absolute_embeddings=self.use_absolute_embeddings       ,					path_norm=self.patch_norm       ,					layer_norm_eps=self.layer_norm_eps       ,					initializer_range=self.initializer_range       ,					upscale=self.upscale       ,					)
  
  
  
    def    _a			(self       ,					_lowerCamelCase       ,					_lowerCamelCase       ,					_lowerCamelCase  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Dict						=						SwinaSRModel(config=_lowerCamelCase  )
          model.to(_lowerCamelCase  )
          model.eval()
          UpperCAmelCase__ :       List[str]						=						model(_lowerCamelCase  )
  
          self.parent.assertEqual(
              result.last_hidden_state.shape       ,					(self.batch_size, self.embed_dim, self.image_size, self.image_size)  )
  
  
  
    def    _a			(self       ,					_lowerCamelCase       ,					_lowerCamelCase       ,					_lowerCamelCase  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Tuple						=						SwinaSRForImageSuperResolution(_lowerCamelCase  )
          model.to(_lowerCamelCase  )
          model.eval()
          UpperCAmelCase__ :       Any						=						model(_lowerCamelCase  )
  
          UpperCAmelCase__ :       Union[str, Any]						=						self.image_size * self.upscale
          self.parent.assertEqual(
              result.reconstruction.shape       ,					(self.batch_size, self.num_channels, expected_image_size, expected_image_size)  )
  
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       str						=						self.prepare_config_and_inputs()
          UpperCAmelCase__ :       Union[str, Any]						=						config_and_inputs
          UpperCAmelCase__ :       List[str]						=						{"""pixel_values""": pixel_values}
          return config, inputs_dict
  
  
  
  
  @require_torch
  class 			lowerCamelCase  (					lowerCAmelCase__				,				lowerCAmelCase__				,				unittest.TestCase      ):
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    SCREAMING_SNAKE_CASE							=     (SwinaSRModel, SwinaSRForImageSuperResolution) if is_torch_available() else ()
    SCREAMING_SNAKE_CASE							=     {'feature-extraction': SwinaSRModel} if is_torch_available() else {}
  
    SCREAMING_SNAKE_CASE							=     False
    SCREAMING_SNAKE_CASE							=     False
    SCREAMING_SNAKE_CASE							=     False
    SCREAMING_SNAKE_CASE							=     False
    SCREAMING_SNAKE_CASE							=     False
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Union[str, Any]						=						SwinaSRModelTester(self  )
          UpperCAmelCase__ :       List[Any]						=						ConfigTester(self       ,					config_class=_lowerCamelCase       ,					embed_dim=37  )
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          self.config_tester.create_and_test_config_to_json_string()
          self.config_tester.create_and_test_config_to_json_file()
          self.config_tester.create_and_test_config_from_and_save_pretrained()
          self.config_tester.create_and_test_config_with_num_labels()
          self.config_tester.check_config_can_be_init_without_params()
          self.config_tester.check_config_arguments_init()
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       List[str]						=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_model(*_lowerCamelCase  )
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Optional[Any]						=						self.model_tester.prepare_config_and_inputs()
          self.model_tester.create_and_check_for_image_super_resolution(*_lowerCamelCase  )
  
  
  
    @unittest.skip(reason="""Got `CUDA error: misaligned address` with PyTorch 2.0.0."""  )
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          pass
  
  
  
    @unittest.skip(reason="""Swin2SR does not use inputs_embeds"""  )
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          pass
  
  
  
    @unittest.skip(reason="""Swin2SR does not support training yet"""  )
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          pass
  
  
  
    @unittest.skip(reason="""Swin2SR does not support training yet"""  )
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          pass
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Tuple						=						self.model_tester.prepare_config_and_inputs_for_common()
  
          for model_class in self.all_model_classes:
                UpperCAmelCase__ :       List[Any]						=						model_class(_lowerCamelCase  )
                self.assertIsInstance(model.get_input_embeddings()       ,					(nn.Module)  )
                UpperCAmelCase__ :       str						=						model.get_output_embeddings()
                self.assertTrue(x is None or isinstance(_lowerCamelCase       ,					nn.Linear  )  )
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Optional[Any]						=						self.model_tester.prepare_config_and_inputs_for_common()
  
          for model_class in self.all_model_classes:
                UpperCAmelCase__ :       str						=						model_class(_lowerCamelCase  )
                UpperCAmelCase__ :       Tuple						=						inspect.signature(model.forward  )
                # signature.parameters is an OrderedDict => so arg_names order is deterministic
                UpperCAmelCase__ :       Optional[int]						=						[*signature.parameters.keys()]
  
                UpperCAmelCase__ :       str						=						["""pixel_values"""]
                self.assertListEqual(arg_names[:1]       ,					_lowerCamelCase  )
  
  
  
    @slow
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          for model_name in SWIN2SR_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
                UpperCAmelCase__ :       str						=						SwinaSRModel.from_pretrained(_lowerCamelCase  )
                self.assertIsNotNone(_lowerCamelCase  )
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       List[str]						=						self.model_tester.prepare_config_and_inputs_for_common()
  
          UpperCAmelCase__ :       List[Any]						=						_config_zero_init(_lowerCamelCase  )
          for model_class in self.all_model_classes:
                UpperCAmelCase__ :       Dict						=						model_class(config=_lowerCamelCase  )
                for name, param in model.named_parameters():
                      if "logit_scale" in name:
                            continue
                      if param.requires_grad:
                            self.assertIn(
                                ((param.data.mean() * 1e9).round() / 1e9).item()       ,					[0.0, 1.0]       ,					msg=F"""Parameter {name} of model {model_class} seems not properly initialized"""       ,					)
  
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       Any						=						self.model_tester.prepare_config_and_inputs_for_common()
          UpperCAmelCase__ :       List[Any]						=						True
  
          for model_class in self.all_model_classes:
                UpperCAmelCase__ :       str						=						True
                UpperCAmelCase__ :       Optional[Any]						=						False
                UpperCAmelCase__ :       Any						=						True
                UpperCAmelCase__ :       List[Any]						=						model_class(_lowerCamelCase  )
                model.to(_lowerCamelCase  )
                model.eval()
                with torch.no_grad():
                      UpperCAmelCase__ :       Union[str, Any]						=						model(**self._prepare_for_class(_lowerCamelCase       ,					_lowerCamelCase  )  )
                UpperCAmelCase__ :       List[str]						=						outputs.attentions
                UpperCAmelCase__ :       str						=						len(self.model_tester.depths  )
                self.assertEqual(len(_lowerCamelCase  )       ,					_lowerCamelCase  )
  
                # check that output_attentions also work using config
                del inputs_dict["output_attentions"]
                UpperCAmelCase__ :       List[str]						=						True
                UpperCAmelCase__ :       Any						=						config.window_size**2
                UpperCAmelCase__ :       Any						=						model_class(_lowerCamelCase  )
                model.to(_lowerCamelCase  )
                model.eval()
                with torch.no_grad():
                      UpperCAmelCase__ :       Any						=						model(**self._prepare_for_class(_lowerCamelCase       ,					_lowerCamelCase  )  )
                UpperCAmelCase__ :       List[str]						=						outputs.attentions
                self.assertEqual(len(_lowerCamelCase  )       ,					_lowerCamelCase  )
  
                self.assertListEqual(
                    list(attentions[0].shape[-3:]  )       ,					[self.model_tester.num_heads[0], window_size_squared, window_size_squared]       ,					)
                UpperCAmelCase__ :       Optional[Any]						=						len(_lowerCamelCase  )
  
                # Check attention is always last and order is fine
                UpperCAmelCase__ :       Union[str, Any]						=						True
                UpperCAmelCase__ :       Tuple						=						True
                UpperCAmelCase__ :       Tuple						=						model_class(_lowerCamelCase  )
                model.to(_lowerCamelCase  )
                model.eval()
                with torch.no_grad():
                      UpperCAmelCase__ :       int						=						model(**self._prepare_for_class(_lowerCamelCase       ,					_lowerCamelCase  )  )
  
                self.assertEqual(out_len + 1       ,					len(_lowerCamelCase  )  )
  
                UpperCAmelCase__ :       Dict						=						outputs.attentions
  
                self.assertEqual(len(_lowerCamelCase  )       ,					_lowerCamelCase  )
  
                self.assertListEqual(
                    list(self_attentions[0].shape[-3:]  )       ,					[self.model_tester.num_heads[0], window_size_squared, window_size_squared]       ,					)
  
  
  
  
  @require_vision
  @require_torch
  @slow
  class 			lowerCamelCase  (					unittest.TestCase      ):
  
  
    '''simple docstring'''
  
  
  
  
  
  
  
    def    _a			(self  ):
  
  
          """simple docstring"""
  
          UpperCAmelCase__ :       str						=						SwinaSRImageProcessor()
          UpperCAmelCase__ :       Any						=						SwinaSRForImageSuperResolution.from_pretrained("""caidas/swin2SR-classical-sr-x2-64"""  ).to(_lowerCamelCase  )
  
          UpperCAmelCase__ :       Optional[int]						=						Image.open("""./tests/fixtures/tests_samples/COCO/000000039769.png"""  )
          UpperCAmelCase__ :       Dict						=						processor(images=_lowerCamelCase       ,					return_tensors="""pt"""  ).to(_lowerCamelCase  )
  
          # forward pass
          with torch.no_grad():
                UpperCAmelCase__ :       Optional[int]						=						model(**_lowerCamelCase  )
  
          # verify the logits
          UpperCAmelCase__ :       Tuple						=						torch.Size([1, 3, 976, 1296]  )
          self.assertEqual(outputs.reconstruction.shape       ,					_lowerCamelCase  )
          UpperCAmelCase__ :       Optional[Any]						=						torch.tensor(
              [[0.5_458, 0.5_546, 0.5_638], [0.5_526, 0.5_565, 0.5_651], [0.5_396, 0.5_426, 0.5_621]]  ).to(_lowerCamelCase  )
          self.assertTrue(torch.allclose(outputs.reconstruction[0, 0, :3, :3]       ,					_lowerCamelCase       ,					atol=1e-4  )  )
  
  
style_context: 
  
  """simple docstring"""
  import requests
  
  try:
      from django.contrib.auth import authenticate, login
      from django.shortcuts import redirect, render
  except ImportError:
      _A						=     _A						=     _A						=     _A						=     print
  
  
  
  
  def 				a__	(	lowerCAmelCase						)  ->   str:
        # Enter your recaptcha secret key here
        UpperCAmelCase__ :       int						=						"""secretKey"""
        UpperCAmelCase__ :       Any						=						"""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__ :       List[Any]						=						request.POST.get("""username"""						)
        UpperCAmelCase__ :       Optional[Any]						=						request.POST.get("""password"""						)
        UpperCAmelCase__ :       List[str]						=						request.POST.get("""g-recaptcha-response"""						)
  
        # post recaptcha response to Google's recaptcha api
        UpperCAmelCase__ :       Any						=						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__ :       List[str]						=						authenticate(lowerCAmelCase ,  username=lowerCAmelCase ,  password=lowerCAmelCase						)
              if user_in_database:
                    login(lowerCAmelCase ,  lowerCAmelCase						)
                    return redirect("""/your-webpage"""						)
        return render(lowerCAmelCase ,  """login.html"""						)
  
  