


'''simple docstring'''




from __future__ import annotations

import inspect
import unittest
from typing import List, Tuple

from transformers import RegNetConfig
from transformers.testing_utils import require_tf, require_vision, slow
from transformers.utils import cached_property, is_tf_available, is_vision_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_tf_common import TFModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_tf_available():
 import tensorflow as tf

 from transformers import TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST, TFRegNetForImageClassification, TFRegNetModel


if is_vision_available():
 from PIL import Image

 from transformers import AutoImageProcessor







class 					a			:
 '''simple docstring'''




 def __init__(    self		,      lowerCamelCase_		,      lowerCamelCase_=3		,      lowerCamelCase_=3_2		,      lowerCamelCase_=3		,      lowerCamelCase_=1_0		,      lowerCamelCase_=[1_0, 2_0, 3_0, 4_0]		,      lowerCamelCase_=[1, 1, 2, 1]		,      lowerCamelCase_=True		,      lowerCamelCase_=True		,      lowerCamelCase_="relu"		,      lowerCamelCase_=3		,      lowerCamelCase_=None		,      )      ->    Dict:
    _a					:  Dict						=  parent
    _a					:  Optional[int]						=  batch_size
    _a					:  str						=  image_size
    _a					:  Optional[Any]						=  num_channels
    _a					:  str						=  embeddings_size
    _a					:  str						=  hidden_sizes
    _a					:  Dict						=  depths
    _a					:  int						=  is_training
    _a					:  Any						=  use_labels
    _a					:  Optional[Any]						=  hidden_act
    _a					:  Optional[Any]						=  num_labels
    _a					:  str						=  scope
    _a					:  int						=  len(lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    List[str]:
    _a					:  Any						=  floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]      )

    _a					:  List[str]						=  None
    if self.use_labels:
       _a					:  Optional[Any]						=  ids_tensor([self.batch_size]		,      self.num_labels      )

    _a					:  Optional[int]						=  self.get_config()
    return config, pixel_values, labels




 def   __UpperCamelCase   (    self      )      ->    int:
    return RegNetConfig(
        num_channels=self.num_channels		,      embeddings_size=self.embeddings_size		,      hidden_sizes=self.hidden_sizes		,      depths=self.depths		,      hidden_act=self.hidden_act		,      num_labels=self.num_labels		,      )




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_      )      ->    Dict:
    _a					:  Dict						=  TFRegNetModel(config=lowerCamelCase_      )
    _a					:  Any						=  model(lowerCamelCase_		,      training=lowerCamelCase_      )
    # expected last hidden states: B, C, H // 32, W // 32
    self.parent.assertEqual(
        result.last_hidden_state.shape		,      (self.batch_size, self.hidden_sizes[-1], self.image_size // 3_2, self.image_size // 3_2)		,      )




 def   __UpperCamelCase   (    self		,      lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_      )      ->    Union[str, Any]:
    _a					:  Optional[int]						=  self.num_labels
    _a					:  Optional[Any]						=  TFRegNetForImageClassification(lowerCamelCase_      )
    _a					:  Optional[int]						=  model(lowerCamelCase_		,      labels=lowerCamelCase_		,      training=lowerCamelCase_      )
    self.parent.assertEqual(result.logits.shape		,      (self.batch_size, self.num_labels)      )




 def   __UpperCamelCase   (    self      )      ->    str:
    _a					:  Union[str, Any]						=  self.prepare_config_and_inputs()
    _a		,						_a		,						_a					:  Optional[Any]						=  config_and_inputs
    _a					:  Tuple						=  {'pixel_values': pixel_values}
    return config, inputs_dict







@require_tf
class 					a			(				snake_case__			,							snake_case__			,							unittest.TestCase  ):
 '''simple docstring'''




 __lowerCAmelCase						: Optional[int]							  =		(TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else ()
 __lowerCAmelCase						: Tuple							  =		(
     {"""feature-extraction""": TFRegNetModel, """image-classification""": TFRegNetForImageClassification}
     if is_tf_available()
     else {}
 )

 __lowerCAmelCase						: Optional[int]							  =		False
 __lowerCAmelCase						: Dict							  =		False
 __lowerCAmelCase						: Any							  =		False
 __lowerCAmelCase						: Dict							  =		False
 __lowerCAmelCase						: List[str]							  =		False




 def   __UpperCamelCase   (    self      )      ->    Any:
    _a					:  Any						=  TFRegNetModelTester(self      )
    _a					:  Tuple						=  ConfigTester(self		,      config_class=lowerCamelCase_		,      has_text_modality=lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    Any:
    return




 @unittest.skip(reason='RegNet does not use inputs_embeds'      )
 def   __UpperCamelCase   (    self      )      ->    int:
    pass




 @unittest.skipIf(
     not is_tf_available() or len(tf.config.list_physical_devices('GPU'      )      ) == 0		,      reason='TF does not support backprop for grouped convolutions on CPU.'		,      )
 @slow
 def   __UpperCamelCase   (    self      )      ->    Optional[Any]:
    super().test_keras_fit()




 @unittest.skip(reason='RegNet does not support input and output embeddings'      )
 def   __UpperCamelCase   (    self      )      ->    Dict:
    pass




 def   __UpperCamelCase   (    self      )      ->    List[Any]:
    _a		,						_a					:  List[Any]						=  self.model_tester.prepare_config_and_inputs_for_common()

    for model_class in self.all_model_classes:
       _a					:  Dict						=  model_class(lowerCamelCase_      )
       _a					:  Optional[Any]						=  inspect.signature(model.call      )
       # signature.parameters is an OrderedDict => so arg_names order is deterministic
       _a					:  List[Any]						=  [*signature.parameters.keys()]

       _a					:  List[Any]						=  ['pixel_values']
       self.assertListEqual(arg_names[:1]		,      lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    List[Any]:
    _a					:  List[str]						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_model(*lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    Optional[Any]:
    def check_hidden_states_output(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_      ):
       _a					:  Union[str, Any]						=  model_class(lowerCamelCase_      )
       _a					:  Optional[int]						=  model(**self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_      )		,      training=lowerCamelCase_      )

       _a					:  Any						=  outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

       _a					:  Dict						=  self.model_tester.num_stages
       self.assertEqual(len(lowerCamelCase_      )		,      expected_num_stages + 1      )

       # RegNet's feature maps are of shape (batch_size, num_channels, height, width)
       self.assertListEqual(
           list(hidden_states[0].shape[-2:]      )		,      [self.model_tester.image_size // 2, self.model_tester.image_size // 2]		,      )

    _a		,						_a					:  str						=  self.model_tester.prepare_config_and_inputs_for_common()
    _a					:  Tuple						=  ['basic', 'bottleneck']
    for model_class in self.all_model_classes:
       for layer_type in layers_type:
          _a					:  str						=  layer_type
          _a					:  List[str]						=  True
          check_hidden_states_output(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_      )

          # check that output_hidden_states also work using config
          del inputs_dict["output_hidden_states"]
          _a					:  List[Any]						=  True

          check_hidden_states_output(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_      )




 def   __UpperCamelCase   (    self      )      ->    int:
    _a		,						_a					:  str						=  self.model_tester.prepare_config_and_inputs_for_common()

    def check_equivalence(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_={}      ):
       _a					:  Dict						=  model(lowerCamelCase_		,      return_dict=lowerCamelCase_		,      **lowerCamelCase_      )
       _a					:  List[Any]						=  model(lowerCamelCase_		,      return_dict=lowerCamelCase_		,      **lowerCamelCase_      ).to_tuple()

       def recursive_check(lowerCamelCase_		,      lowerCamelCase_      ):
          if isinstance(lowerCamelCase_		,      (List, Tuple)      ):
             for tuple_iterable_value, dict_iterable_value in zip(lowerCamelCase_		,      lowerCamelCase_      ):
                recursive_check(lowerCamelCase_		,      lowerCamelCase_      )
          elif tuple_object is None:
             return
          else:
             self.assertTrue(
                 all(tf.equal(lowerCamelCase_		,      lowerCamelCase_      )      )		,      msg=(
                     'Tuple and dict output are not equal. Difference:'
                     F''' {tf.math.reduce_max(tf.abs(tuple_object - dict_object      )      )}'''
                 )		,      )

          recursive_check(lowerCamelCase_		,      lowerCamelCase_      )

    for model_class in self.all_model_classes:
       _a					:  Tuple						=  model_class(lowerCamelCase_      )

       _a					:  str						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_      )
       _a					:  Optional[int]						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_      )
       check_equivalence(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_      )

       _a					:  Optional[Any]						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_		,      return_labels=lowerCamelCase_      )
       _a					:  Tuple						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_		,      return_labels=lowerCamelCase_      )
       check_equivalence(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_      )

       _a					:  Union[str, Any]						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_      )
       _a					:  List[str]						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_      )
       check_equivalence(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_		,      {'output_hidden_states': True}      )

       _a					:  str						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_		,      return_labels=lowerCamelCase_      )
       _a					:  Any						=  self._prepare_for_class(lowerCamelCase_		,      lowerCamelCase_		,      return_labels=lowerCamelCase_      )
       check_equivalence(lowerCamelCase_		,      lowerCamelCase_		,      lowerCamelCase_		,      {'output_hidden_states': True}      )




 def   __UpperCamelCase   (    self      )      ->    int:
    _a					:  int						=  self.model_tester.prepare_config_and_inputs()
    self.model_tester.create_and_check_for_image_classification(*lowerCamelCase_      )




 @slow
 def   __UpperCamelCase   (    self      )      ->    str:
    for model_name in TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
       _a					:  Tuple						=  TFRegNetModel.from_pretrained(lowerCamelCase_      )
       self.assertIsNotNone(lowerCamelCase_      )





def    UpperCAmelCase_  (       ):
   '''simple docstring'''





   _a					:  Dict						=  Image.open('./tests/fixtures/tests_samples/COCO/000000039769.png'      )
   return image







@require_tf
@require_vision
class 					a			(				unittest.TestCase  ):
 '''simple docstring'''




 @cached_property
 def   __UpperCamelCase   (    self      )      ->    Optional[int]:
    return (
        AutoImageProcessor.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]      )
        if is_vision_available()
        else None
    )




 @slow
 def   __UpperCamelCase   (    self      )      ->    Optional[Any]:
    _a					:  Union[str, Any]						=  TFRegNetForImageClassification.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]      )

    _a					:  List[str]						=  self.default_image_processor
    _a					:  Optional[int]						=  prepare_img()
    _a					:  Union[str, Any]						=  image_processor(images=lowerCamelCase_		,      return_tensors='tf'      )

    # forward pass
    _a					:  Dict						=  model(**lowerCamelCase_		,      training=lowerCamelCase_      )

    # verify the logits
    _a					:  Tuple						=  tf.TensorShape((1, 1_0_0_0)      )
    self.assertEqual(outputs.logits.shape		,      lowerCamelCase_      )

    _a					:  Any						=  tf.constant([-0.4180, -1.5051, -3.4836]      )

    tf.debugging.assert_near(outputs.logits[0, :3]		,      lowerCamelCase_		,      atol=1e-4      )






'''simple docstring'''




import requests
from bsa import BeautifulSoup


def    UpperCAmelCase_  (       A = "https://www.worldometers.info/coronavirus"      ):
   '''simple docstring'''





   _a					:  Union[str, Any]						=  BeautifulSoup(requests.get(A      ).text		,	'html.parser'      )
   _a					:  int						=  soup.findAll('h1'      )
   _a					:  Union[str, Any]						=  soup.findAll('div'		,	{'class': 'maincounter-number'}      )
   keys += soup.findAll('span'		,	{'class': 'panel-title'}      )
   values += soup.findAll('div'		,	{'class': 'number-table-main'}      )
   return {key.text.strip(): value.text.strip() for key, value in zip(A		,	A      )}


if __name__ == "__main__":
 print("\033[1m" + "COVID-19 Status of the World" + "\033[0m\n")
 for key, value in world_covidaa_stats().items():
  print(f'''{key}\n{value}\n''')


