


'''simple docstring'''



import itertools
import random
import unittest

import numpy as np

from transformers import BatchFeature, SpeechTaFeatureExtractor
from transformers.testing_utils import require_torch
from transformers.utils.import_utils import is_torch_available

from ...test_sequence_feature_extraction_common import SequenceFeatureExtractionTestMixin


if is_torch_available():
	import torch


__lowercase	:						Tuple       =	random.Random()






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   Any						,      _SCREAMING_SNAKE_CASE      :   List[str]=1.0						,      _SCREAMING_SNAKE_CASE      :   Any=None						,      _SCREAMING_SNAKE_CASE      :   Optional[int]=None   ):
					if rng is None:
										__a			:       List[Any]					    =  global_rng

					__a			:       str					    =  []
					for batch_idx in range(shape[0]   ):
										values.append([]   )
										for _ in range(shape[1]   ):
															values[-1].append(rng.random() * scale   )

					return values





@require_torch
class 							__UpperCamelCase				(		unittest.TestCase					):




	def __init__(   self						,				__a						,				__a=7						,				__a=400						,				__a=2000						,				__a=1						,				__a=0.0						,				__a=1_6000						,				__a=True						,				__a=80						,				__a=16						,				__a=64						,				__a="hann_window"						,				__a=80						,				__a=7600						,				__a=1E-1_0						,				__a=True						,				):

						'''simple docstring'''





						__a			:       int					    =  parent
						__a			:       Optional[Any]					    =  batch_size
						__a			:       Tuple					    =  min_seq_length
						__a			:       List[Any]					    =  max_seq_length
						__a			:       Any					    =  (self.max_seq_length - self.min_seq_length) // (self.batch_size - 1)
						__a			:       str					    =  feature_size
						__a			:       Optional[Any]					    =  padding_value
						__a			:       Optional[Any]					    =  sampling_rate
						__a			:       Optional[Any]					    =  do_normalize
						__a			:       Dict					    =  num_mel_bins
						__a			:       List[str]					    =  hop_length
						__a			:       Dict					    =  win_length
						__a			:       Dict					    =  win_function
						__a			:       Union[str, Any]					    =  fmin
						__a			:       Optional[Any]					    =  fmax
						__a			:       int					    =  mel_floor
						__a			:       Optional[int]					    =  return_attention_mask




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						return {
						    "feature_size": self.feature_size,
						    "padding_value": self.padding_value,
						    "sampling_rate": self.sampling_rate,
						    "do_normalize": self.do_normalize,
						    "num_mel_bins": self.num_mel_bins,
						    "hop_length": self.hop_length,
						    "win_length": self.win_length,
						    "win_function": self.win_function,
						    "fmin": self.fmin,
						    "fmax": self.fmax,
						    "mel_floor": self.mel_floor,
						    "return_attention_mask": self.return_attention_mask,
						}




	def       __UpperCAmelCase							(   self						,				__a=False						,				__a=False							):

						'''simple docstring'''





						def _flatten(__a							):
											return list(itertools.chain(*__a							)							)

						if equal_length:
											__a			:       Optional[Any]					    =  floats_list((self.batch_size, self.max_seq_length)							)
						else:
											# make sure that inputs increase in size
											__a			:       int					    =  [
											    _flatten(floats_list((x, self.feature_size)							)							)
											    for x in range(self.min_seq_length						,				self.max_seq_length						,				self.seq_length_diff							)
											]

						if numpify:
											__a			:       Tuple					    =  [np.asarray(__a							) for x in speech_inputs]

						return speech_inputs





	def       __UpperCAmelCase							(   self						,				__a=False						,				__a=False							):

						'''simple docstring'''





						if equal_length:
											__a			:       Union[str, Any]					    =  [floats_list((self.max_seq_length, self.num_mel_bins)							) for _ in range(self.batch_size							)]
						else:
											# make sure that inputs increase in size
											__a			:       List[Any]					    =  [
											    floats_list((x, self.num_mel_bins)							)
											    for x in range(self.min_seq_length						,				self.max_seq_length						,				self.seq_length_diff							)
											]

						if numpify:
											__a			:       Any					    =  [np.asarray(__a							) for x in speech_inputs]

						return speech_inputs





@require_torch
class 							__UpperCamelCase				(		lowerCAmelCase_		,      unittest.TestCase					):
	A_				=    SpeechTaFeatureExtractor




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Optional[int]					    =  SpeechTaFeatureExtractionTester(self							)




	def       __UpperCAmelCase							(   self						,				__a							):

						'''simple docstring'''





						self.assertTrue(np.all(np.mean(__a						,				axis=0							) < 1E-3							)							)
						self.assertTrue(np.all(np.abs(np.var(__a						,				axis=0							) - 1							) < 1E-3							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Union[str, Any]					    =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						# create three inputs of length 800, 1000, and 1200
						__a			:       Tuple					    =  [floats_list((1, x)							)[0] for x in range(800						,				1400						,				200							)]
						__a			:       Union[str, Any]					    =  [np.asarray(__a							) for speech_input in speech_inputs]

						# Test not batched input
						__a			:       Any					    =  feat_extract(speech_inputs[0]						,				return_tensors='np'							).input_values
						__a			:       str					    =  feat_extract(np_speech_inputs[0]						,				return_tensors='np'							).input_values
						self.assertTrue(np.allclose(__a						,				__a						,				atol=1E-3							)							)

						# Test batched
						__a			:       List[Any]					    =  feat_extract(__a						,				return_tensors='np'							).input_values
						__a			:       Tuple					    =  feat_extract(__a						,				return_tensors='np'							).input_values
						for enc_seq_a, enc_seq_a in zip(__a						,				__a							):
											self.assertTrue(np.allclose(__a						,				__a						,				atol=1E-3							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						__a			:       List[str]					    =  [floats_list((1, x)							)[0] for x in range(800						,				1400						,				200							)]

						__a			:       List[Any]					    =  ['longest', 'max_length', 'do_not_pad']
						__a			:       str					    =  [None, 1600, None]
						for max_length, padding in zip(__a						,				__a							):
											__a			:       Optional[int]					    =  feat_extract(__a						,				padding=__a						,				max_length=__a						,				return_tensors='np'							)
											__a			:       Union[str, Any]					    =  processed.input_values

											self._check_zero_mean_unit_variance(input_values[0][:800]							)
											self.assertTrue(input_values[0][800:].sum() < 1E-6							)
											self._check_zero_mean_unit_variance(input_values[1][:1000]							)
											self.assertTrue(input_values[0][1000:].sum() < 1E-6							)
											self._check_zero_mean_unit_variance(input_values[2][:1200]							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       int					    =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						__a			:       Any					    =  range(800						,				1400						,				200							)
						__a			:       str					    =  [floats_list((1, x)							)[0] for x in lengths]

						__a			:       Optional[Any]					    =  ['longest', 'max_length', 'do_not_pad']
						__a			:       List[str]					    =  [None, 1600, None]

						for max_length, padding in zip(__a						,				__a							):
											__a			:       Tuple					    =  feat_extract(__a						,				max_length=__a						,				padding=__a							)
											__a			:       int					    =  processed.input_values

											self._check_zero_mean_unit_variance(input_values[0][:800]							)
											self._check_zero_mean_unit_variance(input_values[1][:1000]							)
											self._check_zero_mean_unit_variance(input_values[2][:1200]							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						__a			:       Any					    =  [floats_list((1, x)							)[0] for x in range(800						,				1400						,				200							)]
						__a			:       Any					    =  feat_extract(
						    __a						,				truncation=__a						,				max_length=1000						,				padding='max_length'						,				return_tensors='np'							)
						__a			:       Tuple					    =  processed.input_values

						self._check_zero_mean_unit_variance(input_values[0, :800]							)
						self._check_zero_mean_unit_variance(input_values[1]							)
						self._check_zero_mean_unit_variance(input_values[2]							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Tuple					    =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						__a			:       Optional[Any]					    =  [floats_list((1, x)							)[0] for x in range(800						,				1400						,				200							)]
						__a			:       List[str]					    =  feat_extract(
						    __a						,				truncation=__a						,				max_length=1000						,				padding='longest'						,				return_tensors='np'							)
						__a			:       Dict					    =  processed.input_values

						self._check_zero_mean_unit_variance(input_values[0, :800]							)
						self._check_zero_mean_unit_variance(input_values[1, :1000]							)
						self._check_zero_mean_unit_variance(input_values[2]							)

						# make sure that if max_length < longest -> then pad to max_length
						self.assertTrue(input_values.shape == (3, 1000)							)

						__a			:       Any					    =  [floats_list((1, x)							)[0] for x in range(800						,				1400						,				200							)]
						__a			:       str					    =  feat_extract(
						    __a						,				truncation=__a						,				max_length=2000						,				padding='longest'						,				return_tensors='np'							)
						__a			:       Optional[int]					    =  processed.input_values

						self._check_zero_mean_unit_variance(input_values[0, :800]							)
						self._check_zero_mean_unit_variance(input_values[1, :1000]							)
						self._check_zero_mean_unit_variance(input_values[2]							)

						# make sure that if max_length > longest -> then pad to longest
						self.assertTrue(input_values.shape == (3, 1200)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						__a			:       List[str]					    =  np.random.rand(100							).astype(np.floataa							)
						__a			:       Optional[int]					    =  np_speech_inputs.tolist()

						for inputs in [py_speech_inputs, np_speech_inputs]:
											__a			:       Union[str, Any]					    =  feature_extractor.pad([{'input_values': inputs}]						,				return_tensors='np'							)
											self.assertTrue(np_processed.input_values.dtype == np.floataa							)
											__a			:       Optional[int]					    =  feature_extractor.pad([{'input_values': inputs}]						,				return_tensors='pt'							)
											self.assertTrue(pt_processed.input_values.dtype == torch.floataa							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Union[str, Any]					    =  self.feature_extraction_class(**self.feat_extract_tester.prepare_feat_extract_dict()							)
						# create three inputs of length 800, 1000, and 1200
						__a			:       Any					    =  [floats_list((1, x)							)[0] for x in range(800						,				1400						,				200							)]
						__a			:       Optional[Any]					    =  [np.asarray(__a							) for speech_input in speech_inputs]

						# Test feature size
						__a			:       int					    =  feature_extractor(audio_target=__a						,				padding=__a						,				return_tensors='np'							).input_values
						self.assertTrue(input_values.ndim == 3							)
						self.assertTrue(input_values.shape[-1] == feature_extractor.num_mel_bins							)

						# Test not batched input
						__a			:       Any					    =  feature_extractor(speech_inputs[0]						,				return_tensors='np'							).input_values
						__a			:       str					    =  feature_extractor(np_speech_inputs[0]						,				return_tensors='np'							).input_values
						self.assertTrue(np.allclose(__a						,				__a						,				atol=1E-3							)							)

						# Test batched
						__a			:       str					    =  feature_extractor(__a						,				return_tensors='np'							).input_values
						__a			:       int					    =  feature_extractor(__a						,				return_tensors='np'							).input_values
						for enc_seq_a, enc_seq_a in zip(__a						,				__a							):
											self.assertTrue(np.allclose(__a						,				__a						,				atol=1E-3							)							)

						# Test 2-D numpy arrays are batched.
						__a			:       Optional[Any]					    =  [floats_list((1, x)							)[0] for x in (800, 800, 800)]
						__a			:       Union[str, Any]					    =  np.asarray(__a							)
						__a			:       Any					    =  feature_extractor(__a						,				return_tensors='np'							).input_values
						__a			:       Optional[Any]					    =  feature_extractor(__a						,				return_tensors='np'							).input_values
						for enc_seq_a, enc_seq_a in zip(__a						,				__a							):
											self.assertTrue(np.allclose(__a						,				__a						,				atol=1E-3							)							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       str					    =  self.feat_extract_tester.prepare_inputs_for_target()
						__a			:       Dict					    =  self.feature_extraction_class(**self.feat_extract_dict							)
						__a			:       str					    =  feat_extract.model_input_names[0]

						__a			:       Optional[int]					    =  BatchFeature({input_name: speech_inputs}							)

						self.assertTrue(all(len(__a							) == len(__a							) for x, y in zip(__a						,				processed_features[input_name]							)							)							)

						__a			:       Any					    =  self.feat_extract_tester.prepare_inputs_for_target(equal_length=__a							)
						__a			:       Dict					    =  BatchFeature({input_name: speech_inputs}						,				tensor_type='np'							)

						__a			:       int					    =  processed_features[input_name]

						if len(batch_features_input.shape							) < 3:
											__a			:       Union[str, Any]					    =  batch_features_input[:, :, None]

						self.assertTrue(
						    batch_features_input.shape
						    == (self.feat_extract_tester.batch_size, len(speech_inputs[0]							), self.feat_extract_tester.num_mel_bins)							)




	@require_torch
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Union[str, Any]					    =  self.feat_extract_tester.prepare_inputs_for_target(equal_length=__a							)
						__a			:       Any					    =  self.feature_extraction_class(**self.feat_extract_dict							)
						__a			:       Optional[Any]					    =  feat_extract.model_input_names[0]

						__a			:       int					    =  BatchFeature({input_name: speech_inputs}						,				tensor_type='pt'							)

						__a			:       List[Any]					    =  processed_features[input_name]

						if len(batch_features_input.shape							) < 3:
											__a			:       Tuple					    =  batch_features_input[:, :, None]

						self.assertTrue(
						    batch_features_input.shape
						    == (self.feat_extract_tester.batch_size, len(speech_inputs[0]							), self.feat_extract_tester.num_mel_bins)							)




	@require_torch
	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       str					    =  self.feature_extraction_class(**self.feat_extract_dict							)
						__a			:       Optional[int]					    =  self.feat_extract_tester.prepare_inputs_for_target()
						__a			:       Any					    =  feat_extract.model_input_names[0]

						__a			:       Optional[int]					    =  BatchFeature({input_name: speech_inputs}							)

						__a			:       List[Any]					    =  feat_extract.num_mel_bins  # hack!

						__a			:       str					    =  feat_extract.pad(__a						,				padding='longest'						,				return_tensors='np'							)[input_name]
						__a			:       str					    =  feat_extract.pad(__a						,				padding='longest'						,				return_tensors='pt'							)[input_name]

						self.assertTrue(abs(input_np.astype(np.floataa							).sum() - input_pt.numpy().astype(np.floataa							).sum()							) < 1E-2							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       str					    =  self.feat_extract_dict
						__a			:       Dict					    =  True
						__a			:       Optional[Any]					    =  self.feature_extraction_class(**__a							)
						__a			:       List[str]					    =  self.feat_extract_tester.prepare_inputs_for_target()
						__a			:       Dict					    =  [len(__a							) for x in speech_inputs]
						__a			:       str					    =  feat_extract.model_input_names[0]

						__a			:       Union[str, Any]					    =  BatchFeature({input_name: speech_inputs}							)

						__a			:       Optional[int]					    =  feat_extract.num_mel_bins  # hack!

						__a			:       Tuple					    =  feat_extract.pad(__a						,				padding='longest'						,				return_tensors='np'							)
						self.assertIn('attention_mask'						,				__a							)
						self.assertListEqual(list(processed.attention_mask.shape							)						,				list(processed[input_name].shape[:2]							)							)
						self.assertListEqual(processed.attention_mask.sum(-1							).tolist()						,				__a							)




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Optional[Any]					    =  self.feat_extract_dict
						__a			:       List[str]					    =  True
						__a			:       Tuple					    =  self.feature_extraction_class(**__a							)
						__a			:       List[Any]					    =  self.feat_extract_tester.prepare_inputs_for_target()
						__a			:       Any					    =  [len(__a							) for x in speech_inputs]
						__a			:       List[str]					    =  feat_extract.model_input_names[0]

						__a			:       List[str]					    =  BatchFeature({input_name: speech_inputs}							)
						__a			:       str					    =  min(__a							)

						__a			:       Optional[int]					    =  feat_extract.num_mel_bins  # hack!

						__a			:       Tuple					    =  feat_extract.pad(
						    __a						,				padding='max_length'						,				max_length=__a						,				truncation=__a						,				return_tensors='np'							)
						self.assertIn('attention_mask'						,				__a							)
						self.assertListEqual(
						    list(processed_pad.attention_mask.shape							)						,				[processed_pad[input_name].shape[0], max_length]							)
						self.assertListEqual(
						    processed_pad.attention_mask[:, :max_length].sum(-1							).tolist()						,				[max_length for x in speech_inputs]							)




	def       __UpperCAmelCase							(   self						,				__a							):

						'''simple docstring'''





						from datasets import load_dataset

						__a			:       int					    =  load_dataset('hf-internal-testing/librispeech_asr_dummy'						,				'clean'						,				split='validation'							)
						# automatic decoding with librispeech
						__a			:       List[Any]					    =  ds.sort('id'							).select(range(__a							)							)[:num_samples]['audio']

						return [x["array"] for x in speech_samples]




	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       List[str]					    =  torch.tensor(
						    [2.3_8_0_4E-0_3, 2.0_7_5_2E-0_3, 1.9_8_3_6E-0_3, 2.1_0_5_7E-0_3, 1.6_1_7_4E-0_3,
						     3.0_5_1_8E-0_4, 9.1_5_5_3E-0_5, 3.3_5_6_9E-0_4, 9.7_6_5_6E-0_4, 1.8_3_1_1E-0_3,
						     2.0_1_4_2E-0_3, 2.1_0_5_7E-0_3, 1.7_3_9_5E-0_3, 4.5_7_7_6E-0_4, -3.9_6_7_3E-0_4,
						     4.5_7_7_6E-0_4, 1.0_0_7_1E-0_3, 9.1_5_5_3E-0_5, 4.8_8_2_8E-0_4, 1.1_5_9_7E-0_3,
						     7.3_2_4_2E-0_4, 9.4_6_0_4E-0_4, 1.8_0_0_5E-0_3, 1.8_3_1_1E-0_3, 8.8_5_0_1E-0_4,
						     4.2_7_2_5E-0_4, 4.8_8_2_8E-0_4, 7.3_2_4_2E-0_4, 1.0_9_8_6E-0_3, 2.1_0_5_7E-0_3]							)
						# fmt: on

						__a			:       Optional[int]					    =  self._load_datasamples(1							)
						__a			:       Any					    =  SpeechTaFeatureExtractor()
						__a			:       Dict					    =  feature_extractor(__a						,				return_tensors='pt'							).input_values
						self.assertEquals(input_values.shape						,				(1, 9_3680)							)
						self.assertTrue(torch.allclose(input_values[0, :30]						,				__a						,				atol=1E-6							)							)





	def       __UpperCAmelCase							(   self							):

						'''simple docstring'''





						__a			:       Dict					    =  torch.tensor(
						    [-2.6870, -3.0104, -3.1356, -3.5352, -3.0044, -3.0353, -3.4719, -3.6777,
						     -3.1520, -2.9435, -2.6553, -2.8795, -2.9944, -2.5921, -3.0279, -3.0386,
						     -3.0864, -3.1291, -3.2353, -2.7444, -2.6831, -2.7287, -3.1761, -3.1571,
						     -3.2726, -3.0582, -3.1007, -3.4533, -3.4695, -3.0998]							)
						# fmt: on

						__a			:       Any					    =  self._load_datasamples(1							)
						__a			:       List[Any]					    =  SpeechTaFeatureExtractor()
						__a			:       Dict					    =  feature_extractor(audio_target=__a						,				return_tensors='pt'							).input_values
						self.assertEquals(input_values.shape						,				(1, 366, 80)							)
						self.assertTrue(torch.allclose(input_values[0, 0, :30]						,				__a						,				atol=1E-4							)							)







'''simple docstring'''



import requests
from bsa import BeautifulSoup






def   lowerCamelCase							(_SCREAMING_SNAKE_CASE      :   str = "https://www.worldometers.info/coronavirus"   ):
					__a			:       List[Any]					    =  BeautifulSoup(requests.get(_SCREAMING_SNAKE_CASE   ).text						,      'html.parser'   )
					__a			:       Union[str, Any]					    =  soup.findAll('h1'   )
					__a			:       int					    =  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(_SCREAMING_SNAKE_CASE						,      _SCREAMING_SNAKE_CASE   )}


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



