





from collections import OrderedDict
from typing import TYPE_CHECKING, Any, Mapping, Optional, Union

from ...configuration_utils import PretrainedConfig
from ...onnx import OnnxConfig, OnnxSeqaSeqConfigWithPast
from ...utils import logging


if TYPE_CHECKING:
							from ...feature_extraction_utils import FeatureExtractionMixin
							from ...tokenization_utils_base import PreTrainedTokenizerBase
							from ...utils import TensorType

__lowerCAmelCase :int     =    logging.get_logger(__name__)

__lowerCAmelCase :Tuple     =    {
    'openai/whisper-base': 'https://huggingface.co/openai/whisper-base/resolve/main/config.json',
}

# fmt: off
__lowerCAmelCase :Optional[Any]     =    [
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 3_57, 3_66, 4_38, 5_32, 6_85,
    7_05, 7_96, 9_30, 10_58, 12_20, 12_67, 12_79, 13_03, 13_43, 13_77,
    13_91, 16_35, 17_82, 18_75, 21_62, 23_61, 24_88, 34_67, 40_08, 42_11,
    46_00, 48_08, 52_99, 58_55, 63_29, 72_03, 96_09, 99_59, 1_05_63, 1_07_86,
    1_14_20, 1_17_09, 1_19_07, 1_31_63, 1_36_97, 1_37_00, 1_48_08, 1_53_06, 1_64_10, 1_67_91,
    1_79_92, 1_92_03, 1_95_10, 2_07_24, 2_23_05, 2_29_35, 2_70_07, 3_01_09, 3_04_20, 3_34_09,
    3_49_49, 4_02_83, 4_04_93, 4_05_49, 4_72_82, 4_91_46, 5_02_57, 5_03_59, 5_03_60, 5_03_61
]
__lowerCAmelCase :List[Any]     =    [
    1, 2, 7, 8, 9, 10, 14, 25,
    26, 27, 28, 29, 31, 58, 59, 60, 61, 62,
    63, 90, 91, 92, 93, 3_59, 5_03, 5_22, 5_42, 8_73,
    8_93, 9_02, 9_18, 9_22, 9_31, 13_50, 18_53, 19_82, 24_60, 26_27,
    32_46, 32_53, 32_68, 35_36, 38_46, 39_61, 41_83, 46_67, 65_85, 66_47,
    72_73, 90_61, 93_83, 1_04_28, 1_09_29, 1_19_38, 1_20_33, 1_23_31, 1_25_62, 1_37_93,
    1_41_57, 1_46_35, 1_52_65, 1_56_18, 1_65_53, 1_66_04, 1_83_62, 1_89_56, 2_00_75, 2_16_75,
    2_25_20, 2_61_30, 2_61_61, 2_64_35, 2_82_79, 2_94_64, 3_16_50, 3_23_02, 3_24_70, 3_68_65,
    4_28_63, 4_74_25, 4_98_70, 5_02_54, 5_02_58, 5_03_60, 5_03_61, 5_03_62
]






class        _a(    __A    ):
		lowerCamelCase__     :List[str]   				=		'whisper'
		lowerCamelCase__     :int   				=		['past_key_values']
		lowerCamelCase__     :List[str]   				=		{'num_attention_heads': 'encoder_attention_heads', 'hidden_size': 'd_model'}







		def __init__(    self ,						__snake_case=5_1_8_6_5 ,						__snake_case=8_0 ,						__snake_case=6 ,						__snake_case=4 ,						__snake_case=6 ,						__snake_case=4 ,						__snake_case=1_5_3_6 ,						__snake_case=1_5_3_6 ,						__snake_case=0.0 ,						__snake_case=0.0 ,						__snake_case=5_0_2_5_7 ,						__snake_case=True ,						__snake_case=True ,						__snake_case="gelu" ,						__snake_case=2_5_6 ,						__snake_case=0.0 ,						__snake_case=0.0 ,						__snake_case=0.0 ,						__snake_case=0.02 ,						__snake_case=False ,						__snake_case=1_5_0_0 ,						__snake_case=4_4_8 ,						__snake_case=5_0_2_5_6 ,						__snake_case=5_0_2_5_6 ,						__snake_case=5_0_2_5_6 ,						__snake_case=None ,						__snake_case=[2_2_0, 5_0_2_5_6] ,						__snake_case=False ,						__snake_case=2_5_6 ,						__snake_case=False ,						__snake_case=0.05 ,						__snake_case=1_0 ,						__snake_case=2 ,						__snake_case=0.0 ,						__snake_case=1_0 ,						__snake_case=0 ,						__snake_case=7 ,						**__snake_case ,						)      ->      Optional[int]:


							'''simple docstring'''

							_snake_case       :					Union[str, Any]				       =   vocab_size
							_snake_case       :					Optional[int]				       =   num_mel_bins
							_snake_case       :					str				       =   d_model
							_snake_case       :					int				       =   encoder_layers
							_snake_case       :					Any				       =   encoder_attention_heads
							_snake_case       :					Optional[Any]				       =   decoder_layers
							_snake_case       :					Optional[int]				       =   decoder_attention_heads
							_snake_case       :					Tuple				       =   decoder_ffn_dim
							_snake_case       :					List[Any]				       =   encoder_ffn_dim
							_snake_case       :					Any				       =   dropout
							_snake_case       :					Optional[int]				       =   attention_dropout
							_snake_case       :					Dict				       =   activation_dropout
							_snake_case       :					int				       =   activation_function
							_snake_case       :					Tuple				       =   init_std
							_snake_case       :					Dict				       =   encoder_layerdrop
							_snake_case       :					int				       =   decoder_layerdrop
							_snake_case       :					Union[str, Any]				       =   use_cache
							_snake_case       :					List[Any]				       =   encoder_layers
							_snake_case       :					List[Any]				       =   scale_embedding  # scale factor will be sqrt(d_model) if True
							_snake_case       :					Tuple				       =   max_source_positions
							_snake_case       :					Tuple				       =   max_target_positions

							# Audio Classification-specific parameters. Feel free to ignore for other classes.
							_snake_case       :					Optional[int]				       =   classifier_proj_size
							_snake_case       :					List[Any]				       =   use_weighted_layer_sum

							# fine-tuning config parameters for SpecAugment: https://arxiv.org/abs/1904.08779
							_snake_case       :					Tuple				       =   apply_spec_augment
							_snake_case       :					Dict				       =   mask_time_prob
							_snake_case       :					Union[str, Any]				       =   mask_time_length
							_snake_case       :					List[Any]				       =   mask_time_min_masks
							_snake_case       :					Optional[int]				       =   mask_feature_prob
							_snake_case       :					str				       =   mask_feature_length
							_snake_case       :					int				       =   mask_feature_min_masks

							_snake_case       :					Optional[int]				       =   median_filter_width

							super().__init__(
							    pad_token_id=__snake_case ,						bos_token_id=__snake_case ,						eos_token_id=__snake_case ,						is_encoder_decoder=__snake_case ,						decoder_start_token_id=__snake_case ,						suppress_tokens=__snake_case ,						begin_suppress_tokens=__snake_case ,						**__snake_case ,						)






class        _a(    __A    ):







		@property
		def        lowercase       (    self				)      ->      Mapping[str, Mapping[int, str]]:


							'''simple docstring'''

							_snake_case       :					Optional[int]				       =   OrderedDict(
							    [
							        ("input_features", {0: "batch", 1: "feature_size", 2: "encoder_sequence"}),
							    ]				)
							if self.use_past:
												_snake_case       :					Any				       =   {0: "batch"}
							else:
												_snake_case       :					Tuple				       =   {0: "batch", 1: "decoder_sequence"}

							if self.use_past:
												self.fill_with_past_key_values_(__snake_case ,						direction="inputs"				)

							return common_inputs







		def        lowercase       (    self ,						__snake_case ,						__snake_case = -1 ,						__snake_case = -1 ,						__snake_case = False ,						__snake_case = None ,						__snake_case = 2_2_0_5_0 ,						__snake_case = 5.0 ,						__snake_case = 2_2_0 ,						)      ->      Mapping[str, Any]:


							'''simple docstring'''

							_snake_case       :					int				       =   OrderedDict()
							_snake_case       :					Union[str, Any]				       =   OnnxConfig.generate_dummy_inputs(
							    self ,						preprocessor=preprocessor.feature_extractor ,						batch_size=__snake_case ,						framework=__snake_case ,						sampling_rate=__snake_case ,						time_duration=__snake_case ,						frequency=__snake_case ,						)
							_snake_case       :					Dict				       =   encoder_inputs["input_features"].shape[2]
							_snake_case       :					Any				       =   encoder_sequence_length // 2 if self.use_past else seq_length

							_snake_case       :					str				       =   super().generate_dummy_inputs(
							    preprocessor.tokenizer ,						__snake_case ,						__snake_case ,						__snake_case ,						__snake_case				)

							_snake_case       :					List[Any]				       =   encoder_inputs.pop("input_features"				)
							_snake_case       :					Union[str, Any]				       =   decoder_inputs.pop("decoder_input_ids"				)

							if "past_key_values" in decoder_inputs:
												_snake_case       :					str				       =   decoder_inputs.pop("past_key_values"				)

							return dummy_inputs







		@property
		def        lowercase       (    self				)      ->      float:


							'''simple docstring'''

							return 1E-3






import argparse
import os
from io import BytesIO
from pathlib import Path

import requests
from clip_retrieval.clip_client import ClipClient
from PIL import Image
from tqdm import tqdm







def    A				(							UpperCAmelCase  ,  UpperCAmelCase  ,  UpperCAmelCase				):
					_snake_case       :					List[str]				       =   1.5
					_snake_case       :					Union[str, Any]				       =   int(factor * num_class_images				)
					_snake_case       :					Dict				       =   ClipClient(
					    url="https://knn.laion.ai/knn-service"  ,  indice_name="laion_400m"  ,  num_images=UpperCAmelCase  ,  aesthetic_weight=0.1				)

					os.makedirs(F"""{class_data_dir}/images"""  ,  exist_ok=UpperCAmelCase				)
					if len(list(Path(F"""{class_data_dir}/images"""				).iterdir()				)				) >= num_class_images:
										return

					while True:
										_snake_case       :					Optional[int]				       =   client.query(text=UpperCAmelCase				)
										if len(UpperCAmelCase				) >= factor * num_class_images or num_images > 1e4:
															break
										else:
															_snake_case       :					str				       =   int(factor * num_images				)
															_snake_case       :					Union[str, Any]				       =   ClipClient(
															    url="https://knn.laion.ai/knn-service"  ,  indice_name="laion_400m"  ,  num_images=UpperCAmelCase  ,  aesthetic_weight=0.1  ,  )

					_snake_case       :					List[Any]				       =   0
					_snake_case       :					Any				       =   0
					_snake_case       :					List[Any]				       =   tqdm(desc="downloading real regularization images"  ,  total=UpperCAmelCase				)

					with open(F"""{class_data_dir}/caption.txt"""  ,  "w"				) as fa, open(F"""{class_data_dir}/urls.txt"""  ,  "w"				) as fa, open(
					    F"""{class_data_dir}/images.txt"""  ,  "w"				) as fa:
										while total < num_class_images:
															_snake_case       :					Optional[Any]				       =   class_images[count]
															count += 1
															try:
																				_snake_case       :					Tuple				       =   requests.get(images["url"]				)
																				if img.status_code == 200:
																									_snake_case       :					int				       =   Image.open(BytesIO(img.content				)				)
																									with open(F"""{class_data_dir}/images/{total}.jpg"""  ,  "wb"				) as f:
																														f.write(img.content				)
																									fa.write(images["caption"] + "\n"				)
																									fa.write(images["url"] + "\n"				)
																									fa.write(F"""{class_data_dir}/images/{total}.jpg""" + "\n"				)
																									total += 1
																									pbar.update(1				)
																				else:
																									continue
															except Exception:
																				continue
					return







def    A				(							):
					_snake_case       :					Any				       =   argparse.ArgumentParser(""  ,  add_help=UpperCAmelCase				)
					parser.add_argument("--class_prompt"  ,  help="text prompt to retrieve images"  ,  required=UpperCAmelCase  ,  type=UpperCAmelCase				)
					parser.add_argument("--class_data_dir"  ,  help="path to save images"  ,  required=UpperCAmelCase  ,  type=UpperCAmelCase				)
					parser.add_argument("--num_class_images"  ,  help="number of images to download"  ,  default=200  ,  type=UpperCAmelCase				)
					return parser.parse_args()


if __name__ == "__main__":
							__lowerCAmelCase :List[Any]     =    parse_args()
							retrieve(args.class_prompt, args.class_data_dir, args.num_class_images)