



import inspect
import unittest

from huggingface_hub import hf_hub_download

from transformers import ASTConfig
from transformers.testing_utils import require_torch, require_torchaudio, slow, torch_device
from transformers.utils import cached_property, is_torch_available, is_torchaudio_available

from ...test_configuration_common import ConfigTester
from ...test_modeling_common import ModelTesterMixin, floats_tensor, ids_tensor
from ...test_pipeline_mixin import PipelineTesterMixin


if is_torch_available():
					import torch
					from torch import nn

					from transformers import ASTForAudioClassification, ASTModel
					from transformers.models.audio_spectrogram_transformer.modeling_audio_spectrogram_transformer import (
					    AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST,
					)


if is_torchaudio_available():
					import torchaudio

					from transformers import ASTFeatureExtractor



class 	lowerCamelCase__      :




		'''simple docstring'''



		def __init__(self		,__lowerCamelCase		,__lowerCamelCase=13		,__lowerCamelCase=2		,__lowerCamelCase=24		,__lowerCamelCase=16		,__lowerCamelCase=True		,__lowerCamelCase=True		,__lowerCamelCase=32		,__lowerCamelCase=5		,__lowerCamelCase=4		,__lowerCamelCase=37		,__lowerCamelCase="gelu"		,__lowerCamelCase=0.1		,__lowerCamelCase=0.1		,__lowerCamelCase=10		,__lowerCamelCase=0.02		,__lowerCamelCase=None		,__lowerCamelCase=2		,__lowerCamelCase=2		,)					->      Dict:

						"""simple docstring"""






						lowerCAmelCase__					:    Tuple												=					parent
						lowerCAmelCase__					:    Union[str, Any]												=					batch_size
						lowerCAmelCase__					:    Tuple												=					patch_size
						lowerCAmelCase__					:    str												=					max_length
						lowerCAmelCase__					:    Union[str, Any]												=					num_mel_bins
						lowerCAmelCase__					:    Union[str, Any]												=					is_training
						lowerCAmelCase__					:    Union[str, Any]												=					use_labels
						lowerCAmelCase__					:    List[str]												=					hidden_size
						lowerCAmelCase__					:    List[Any]												=					num_hidden_layers
						lowerCAmelCase__					:    Dict												=					num_attention_heads
						lowerCAmelCase__					:    int												=					intermediate_size
						lowerCAmelCase__					:    Optional[int]												=					hidden_act
						lowerCAmelCase__					:    Optional[int]												=					hidden_dropout_prob
						lowerCAmelCase__					:    Tuple												=					attention_probs_dropout_prob
						lowerCAmelCase__					:    Optional[int]												=					type_sequence_label_size
						lowerCAmelCase__					:    Any												=					initializer_range
						lowerCAmelCase__					:    Optional[int]												=					scope
						lowerCAmelCase__					:    Union[str, Any]												=					frequency_stride
						lowerCAmelCase__					:    Union[str, Any]												=					time_stride

						# in AST, the seq length equals the number of patches + 2 (we add 2 for the [CLS] and distillation tokens)
						lowerCAmelCase__					:    Dict												=					(self.num_mel_bins - self.patch_size) // self.frequency_stride + 1
						lowerCAmelCase__					:    Tuple												=					(self.max_length - self.patch_size) // self.time_stride + 1
						lowerCAmelCase__					:    List[Any]												=					frequency_out_dimension * time_out_dimension
						lowerCAmelCase__					:    Dict												=					num_patches + 2



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    int												=					floats_tensor([self.batch_size, self.max_length, self.num_mel_bins]			)

						lowerCAmelCase__					:    Tuple												=					None
						if self.use_labels:
										lowerCAmelCase__					:    Union[str, Any]												=					ids_tensor([self.batch_size]		,self.type_sequence_label_size			)

						lowerCAmelCase__					:    str												=					self.get_config()

						return config, input_values, labels



		def 		lowerCAmelCase__				(self			)					->      List[str]:

						"""simple docstring"""






						return ASTConfig(
						    patch_size=self.patch_size		,max_length=self.max_length		,num_mel_bins=self.num_mel_bins		,hidden_size=self.hidden_size		,num_hidden_layers=self.num_hidden_layers		,num_attention_heads=self.num_attention_heads		,intermediate_size=self.intermediate_size		,hidden_act=self.hidden_act		,hidden_dropout_prob=self.hidden_dropout_prob		,attention_probs_dropout_prob=self.attention_probs_dropout_prob		,is_decoder=__lowerCamelCase		,initializer_range=self.initializer_range		,frequency_stride=self.frequency_stride		,time_stride=self.time_stride		,)



		def 		lowerCAmelCase__				(self		,__lowerCamelCase		,__lowerCamelCase		,__lowerCamelCase			)					->      Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__					:    Union[str, Any]												=					ASTModel(config=__lowerCamelCase			)
						model.to(__lowerCamelCase			)
						model.eval()
						lowerCAmelCase__					:    Any												=					model(__lowerCamelCase			)
						self.parent.assertEqual(result.last_hidden_state.shape		,(self.batch_size, self.seq_length, self.hidden_size)			)



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    List[str]												=					self.prepare_config_and_inputs()
						(
						    lowerCAmelCase__		
						)					:    Dict												=					config_and_inputs
						lowerCAmelCase__					:    List[Any]												=					{'''input_values''': input_values}
						return config, inputs_dict



@require_torch
class 	lowerCamelCase__      (							lowerCamelCase__				,    lowerCamelCase__				,    unittest.TestCase):




		'''simple docstring'''



		snake_case_     =(
		    (
		        ASTModel,
		        ASTForAudioClassification,
		    )
		    if is_torch_available()
		    else ()
		)
		snake_case_     =(
		    {"""audio-classification""": ASTForAudioClassification, """feature-extraction""": ASTModel}
		    if is_torch_available()
		    else {}
		)
		snake_case_     =False
		snake_case_     =False
		snake_case_     =False
		snake_case_     =False



		def 		lowerCAmelCase__				(self		,__lowerCamelCase		,__lowerCamelCase		,__lowerCamelCase		,__lowerCamelCase		,__lowerCamelCase			)					->      Optional[Any]:

						"""simple docstring"""






						if pipeline_test_casse_name == "AudioClassificationPipelineTests":
										return True

						return False



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						lowerCAmelCase__					:    str												=					ASTModelTester(self			)
						lowerCAmelCase__					:    Tuple												=					ConfigTester(self		,config_class=__lowerCamelCase		,has_text_modality=__lowerCamelCase		,hidden_size=37			)



		def 		lowerCAmelCase__				(self			)					->      int:

						"""simple docstring"""






						self.config_tester.run_common_tests()



		@unittest.skip(reason='''AST does not use inputs_embeds'''			)
		def 		lowerCAmelCase__				(self			)					->      List[str]:

						"""simple docstring"""






						pass



		def 		lowerCAmelCase__				(self			)					->      Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    int												=					self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										lowerCAmelCase__					:    Optional[Any]												=					model_class(__lowerCamelCase			)
										self.assertIsInstance(model.get_input_embeddings()		,(nn.Module)			)
										lowerCAmelCase__					:    Dict												=					model.get_output_embeddings()
										self.assertTrue(x is None or isinstance(__lowerCamelCase		,nn.Linear			)			)



		def 		lowerCAmelCase__				(self			)					->      Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__					:    Any												=					self.model_tester.prepare_config_and_inputs_for_common()

						for model_class in self.all_model_classes:
										lowerCAmelCase__					:    Optional[Any]												=					model_class(__lowerCamelCase			)
										lowerCAmelCase__					:    Any												=					inspect.signature(model.forward			)
										# signature.parameters is an OrderedDict => so arg_names order is deterministic
										lowerCAmelCase__					:    Optional[Any]												=					[*signature.parameters.keys()]

										lowerCAmelCase__					:    Optional[int]												=					['''input_values''']
										self.assertListEqual(arg_names[:1]		,__lowerCamelCase			)



		def 		lowerCAmelCase__				(self			)					->      Dict:

						"""simple docstring"""






						lowerCAmelCase__					:    Optional[int]												=					self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*__lowerCamelCase			)



		@slow
		def 		lowerCAmelCase__				(self			)					->      Union[str, Any]:

						"""simple docstring"""






						for model_name in AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCAmelCase__					:    Optional[int]												=					ASTModel.from_pretrained(__lowerCamelCase			)
										self.assertIsNotNone(__lowerCamelCase			)






def      lowerCAmelCase__		(   ):





				'''simple docstring'''

				lowerCAmelCase__					:    int												=					hf_hub_download(
				    repo_id='''nielsr/audio-spectogram-transformer-checkpoint'''	,filename='''sample_audio.flac'''	,repo_type='''dataset''')

				lowerCAmelCase__					:    int												=					torchaudio.load(lowerCamelCase_)

				return audio, sampling_rate



@require_torch
@require_torchaudio
class 	lowerCamelCase__      (							unittest.TestCase):




		'''simple docstring'''



		@cached_property
		def 		lowerCAmelCase__				(self			)					->      Union[str, Any]:

						"""simple docstring"""






						return (
						    ASTFeatureExtractor.from_pretrained('''MIT/ast-finetuned-audioset-10-10-0.4593'''			)
						    if is_torchaudio_available()
						    else None
						)



		@slow
		def 		lowerCAmelCase__				(self			)					->      Optional[int]:

						"""simple docstring"""






						lowerCAmelCase__					:    int												=					self.default_feature_extractor
						lowerCAmelCase__					:    List[str]												=					ASTForAudioClassification.from_pretrained('''MIT/ast-finetuned-audioset-10-10-0.4593'''			).to(__lowerCamelCase			)

						lowerCAmelCase__					:    List[str]												=					self.default_feature_extractor
						lowerCAmelCase__					:    int												=					prepare_audio()
						lowerCAmelCase__					:    Optional[int]												=					audio.squeeze().numpy()
						lowerCAmelCase__					:    List[Any]												=					feature_extractor(__lowerCamelCase		,sampling_rate=__lowerCamelCase		,return_tensors='''pt'''			).to(__lowerCamelCase			)

						# forward pass
						with torch.no_grad():
										lowerCAmelCase__					:    str												=					model(**__lowerCamelCase			)

						# verify the logits
						lowerCAmelCase__					:    Union[str, Any]												=					torch.Size((1, 5_27)			)
						self.assertEqual(outputs.logits.shape		,__lowerCamelCase			)

						lowerCAmelCase__					:    List[str]												=					torch.tensor([-0.8760, -7.0042, -8.6602]			).to(__lowerCamelCase			)

						self.assertTrue(torch.allclose(outputs.logits[0, :3]		,__lowerCamelCase		,atol=1e-4			)			)






from math import factorial






def      lowerCAmelCase__		(   lowerCamelCase_		:		int = 100):





				'''simple docstring'''

				return sum(map(lowerCamelCase_	,str(factorial(lowerCamelCase_))))


if __name__ == "__main__":
							print(solution(int(input('Enter the Number: ').strip())))

