



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 				_snake_case			:




				def __init__(						self					:						int,					__lowercase					:						int,					__lowercase					:						Any=13,					__lowercase					:						Optional[int]=2,					__lowercase					:						str=24,					__lowercase					:						int=16,					__lowercase					:						str=True,					__lowercase					:						str=True,					__lowercase					:						List[Any]=32,					__lowercase					:						List[str]=5,					__lowercase					:						Union[str, Any]=4,					__lowercase					:						Optional[int]=37,					__lowercase					:						int="gelu",					__lowercase					:						Dict=0.1,					__lowercase					:						int=0.1,					__lowercase					:						List[str]=10,					__lowercase					:						List[Any]=0.02,					__lowercase					:						int=None,					__lowercase					:						Optional[int]=2,					__lowercase					:						Optional[Any]=2,					):
							lowercase__					  =				parent
							lowercase__					  =				batch_size
							lowercase__					  =				patch_size
							lowercase__					  =				max_length
							lowercase__					  =				num_mel_bins
							lowercase__					  =				is_training
							lowercase__					  =				use_labels
							lowercase__					  =				hidden_size
							lowercase__					  =				num_hidden_layers
							lowercase__					  =				num_attention_heads
							lowercase__					  =				intermediate_size
							lowercase__					  =				hidden_act
							lowercase__					  =				hidden_dropout_prob
							lowercase__					  =				attention_probs_dropout_prob
							lowercase__					  =				type_sequence_label_size
							lowercase__					  =				initializer_range
							lowercase__					  =				scope
							lowercase__					  =				frequency_stride
							lowercase__					  =				time_stride

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




				def 							A__      (						self					:						str						):
							lowercase__					  =				floats_tensor([self.batch_size, self.max_length, self.num_mel_bins]						)

							lowercase__					  =				None
							if self.use_labels:
										lowercase__					  =				ids_tensor([self.batch_size],					self.type_sequence_label_size						)

							lowercase__					  =				self.get_config()

							return config, input_values, labels




				def 							A__      (						self					:						int						):
							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=__lowercase,					initializer_range=self.initializer_range,					frequency_stride=self.frequency_stride,					time_stride=self.time_stride,					)




				def 							A__      (						self					:						Union[str, Any],					__lowercase					:						str,					__lowercase					:						Tuple,					__lowercase					:						int						):
							lowercase__					  =				ASTModel(config=__lowercase						)
							model.to(__lowercase						)
							model.eval()
							lowercase__					  =				model(__lowercase						)
							self.parent.assertEqual(result.last_hidden_state.shape,					(self.batch_size, self.seq_length, self.hidden_size)						)




				def 							A__      (						self					:						int						):
							lowercase__					  =				self.prepare_config_and_inputs()
							(
							    (
							    lowercase__
							)  ,       (
							    lowercase__
							)  ,       (
							    lowercase__
							)  ,       
							)					  =				config_and_inputs
							lowercase__					  =				{"input_values": input_values}
							return config, inputs_dict
@require_torch
class 				_snake_case			(					lowercase__    ,	lowercase__    ,	unittest.TestCase):
				UpperCamelCase__				:					List[Any]     		=(
				    (
				        ASTModel,
				        ASTForAudioClassification,
				    )
				    if is_torch_available()
				    else ()
				)
				UpperCamelCase__				:					Dict     		=(
				    {"""audio-classification""": ASTForAudioClassification, """feature-extraction""": ASTModel}
				    if is_torch_available()
				    else {}
				)
				UpperCamelCase__				:					Optional[Any]     		=False
				UpperCamelCase__				:					Union[str, Any]     		=False
				UpperCamelCase__				:					int     		=False
				UpperCamelCase__				:					List[str]     		=False




				def 							A__      (						self					:						List[Any],					__lowercase					:						str,					__lowercase					:						List[str],					__lowercase					:						List[Any],					__lowercase					:						Optional[Any],					__lowercase					:						str						):
							if pipeline_test_casse_name == "AudioClassificationPipelineTests":
										return True

							return False




				def 							A__      (						self					:						str						):
							lowercase__					  =				ASTModelTester(self						)
							lowercase__					  =				ConfigTester(self,					config_class=__lowercase,					has_text_modality=__lowercase,					hidden_size=37						)




				def 							A__      (						self					:						List[Any]						):
							self.config_tester.run_common_tests()




				@unittest.skip(reason="AST does not use inputs_embeds"						)
				def 							A__      (						self					:						Dict						):
							pass




				def 							A__      (						self					:						Any						):
							lowercase__  ,       lowercase__					  =				self.model_tester.prepare_config_and_inputs_for_common()

							for model_class in self.all_model_classes:
										lowercase__					  =				model_class(__lowercase						)
										self.assertIsInstance(model.get_input_embeddings(),					(nn.Module)						)
										lowercase__					  =				model.get_output_embeddings()
										self.assertTrue(x is None or isinstance(__lowercase,					nn.Linear						)						)




				def 							A__      (						self					:						Optional[int]						):
							lowercase__  ,       lowercase__					  =				self.model_tester.prepare_config_and_inputs_for_common()

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

										lowercase__					  =				["input_values"]
										self.assertListEqual(arg_names[:1],					__lowercase						)




				def 							A__      (						self					:						int						):
							lowercase__					  =				self.model_tester.prepare_config_and_inputs()
							self.model_tester.create_and_check_model(*__lowercase						)




				@slow
				def 							A__      (						self					:						Any						):
							for model_name in AUDIO_SPECTROGRAM_TRANSFORMER_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowercase__					  =				ASTModel.from_pretrained(__lowercase						)
										self.assertIsNotNone(__lowercase						)



def __lowerCAmelCase (     ):
			lowercase__					  =				hf_hub_download(
			    repo_id="nielsr/audio-spectogram-transformer-checkpoint"						,  filename="sample_audio.flac"						,  repo_type="dataset"  )

			lowercase__  ,       lowercase__					  =				torchaudio.load(SCREAMING_SNAKE_CASE_  )

			return audio, sampling_rate




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




				@cached_property
				def 							A__      (						self					:						List[str]						):
							return (
							    ASTFeatureExtractor.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593"						)
							    if is_torchaudio_available()
							    else None
							)




				@slow
				def 							A__      (						self					:						Tuple						):
							lowercase__					  =				self.default_feature_extractor
							lowercase__					  =				ASTForAudioClassification.from_pretrained("MIT/ast-finetuned-audioset-10-10-0.4593"						).to(__lowercase						)

							lowercase__					  =				self.default_feature_extractor
							lowercase__  ,       lowercase__					  =				prepare_audio()
							lowercase__					  =				audio.squeeze().numpy()
							lowercase__					  =				feature_extractor(__lowercase,					sampling_rate=__lowercase,					return_tensors="pt"						).to(__lowercase						)

							# forward pass
							with torch.no_grad():
										lowercase__					  =				model(**__lowercase						)

							# verify the logits
							lowercase__					  =				torch.Size((1, 527)						)
							self.assertEqual(outputs.logits.shape,					__lowercase						)

							lowercase__					  =				torch.tensor([-0.8760, -7.0042, -8.6602]						).to(__lowercase						)

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









def __lowerCAmelCase (     SCREAMING_SNAKE_CASE_  ):
			lowercase__					  =				len(SCREAMING_SNAKE_CASE_  )
			for i in range(SCREAMING_SNAKE_CASE_  ):
						for j in range(i + 1						,  SCREAMING_SNAKE_CASE_  ):
									if numbers[j] < numbers[i]:
												lowercase__  ,       lowercase__					  =				numbers[j], numbers[i]
			return numbers


if __name__ == "__main__":
							lowercase_								=     input("""Enter numbers separated by a comma:\n""").strip()
							lowercase_								=     [int(item) for item in user_input.split(""",""")]
							print(exchange_sort(unsorted))




