



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




		'''simple docstring'''



		def __init__(self						,__lowerCamelCase						,__lowerCamelCase=3						,__lowerCamelCase=32						,__lowerCamelCase=3						,__lowerCamelCase=10						,__lowerCamelCase=[10, 20, 30, 40]						,__lowerCamelCase=[1, 1, 2, 1]						,__lowerCamelCase=True						,__lowerCamelCase=True						,__lowerCamelCase="relu"						,__lowerCamelCase=3						,__lowerCamelCase=None						,)	->     List[Any]:

						"""simple docstring"""






						lowerCAmelCase__	:							str				=	parent
						lowerCAmelCase__	:							int				=	batch_size
						lowerCAmelCase__	:							int				=	image_size
						lowerCAmelCase__	:							Any				=	num_channels
						lowerCAmelCase__	:							List[Any]				=	embeddings_size
						lowerCAmelCase__	:							str				=	hidden_sizes
						lowerCAmelCase__	:							Dict				=	depths
						lowerCAmelCase__	:							str				=	is_training
						lowerCAmelCase__	:							Any				=	use_labels
						lowerCAmelCase__	:							str				=	hidden_act
						lowerCAmelCase__	:							Optional[Any]				=	num_labels
						lowerCAmelCase__	:							List[Any]				=	scope
						lowerCAmelCase__	:							Tuple				=	len(UpperCamelCase__					)



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

						"""simple docstring"""






						lowerCAmelCase__	:							str				=	floats_tensor([self.batch_size, self.num_channels, self.image_size, self.image_size]					)

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

						lowerCAmelCase__	:							Tuple				=	self.get_config()
						return config, pixel_values, labels



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

						"""simple docstring"""






						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 						lowerCAmelCase__ (self						,__lowerCamelCase						,__lowerCamelCase						,__lowerCamelCase					)	->     Union[str, Any]:

						"""simple docstring"""






						lowerCAmelCase__	:							Any				=	TFRegNetModel(config=UpperCamelCase__					)
						lowerCAmelCase__	:							Tuple				=	model(UpperCamelCase__						,training=UpperCamelCase__					)
						# 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 // 32, self.image_size // 32)						,)



		def 						lowerCAmelCase__ (self						,__lowerCamelCase						,__lowerCamelCase						,__lowerCamelCase					)	->     str:

						"""simple docstring"""






						lowerCAmelCase__	:							List[Any]				=	self.num_labels
						lowerCAmelCase__	:							Any				=	TFRegNetForImageClassification(UpperCamelCase__					)
						lowerCAmelCase__	:							List[Any]				=	model(UpperCamelCase__						,labels=UpperCamelCase__						,training=UpperCamelCase__					)
						self.parent.assertEqual(result.logits.shape						,(self.batch_size, self.num_labels)					)



		def 						lowerCAmelCase__ (self					)	->     Any:

						"""simple docstring"""






						lowerCAmelCase__	:							Dict				=	self.prepare_config_and_inputs()
						lowerCAmelCase__		,						lowerCAmelCase__		,						lowerCAmelCase__	:							str				=	config_and_inputs
						lowerCAmelCase__	:							Optional[int]				=	{'''pixel_values''': pixel_values}
						return config, inputs_dict



@require_tf
class 			lowerCamelCase__     (				_snake_case ,							_snake_case ,							unittest.TestCase):




		'''simple docstring'''



		snake_case_      =(TFRegNetModel, TFRegNetForImageClassification) if is_tf_available() else ()
		snake_case_      =(
		    {"""feature-extraction""": TFRegNetModel, """image-classification""": TFRegNetForImageClassification}
		    if is_tf_available()
		    else {}
		)

		snake_case_      =False
		snake_case_      =False
		snake_case_      =False
		snake_case_      =False
		snake_case_      =False



		def 						lowerCAmelCase__ (self					)	->     str:

						"""simple docstring"""






						lowerCAmelCase__	:							Any				=	TFRegNetModelTester(self					)
						lowerCAmelCase__	:							Any				=	ConfigTester(self						,config_class=UpperCamelCase__						,has_text_modality=UpperCamelCase__					)



		def 						lowerCAmelCase__ (self					)	->     str:

						"""simple docstring"""






						return



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

						"""simple docstring"""






						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 						lowerCAmelCase__ (self					)	->     Dict:

						"""simple docstring"""






						super().test_keras_fit()



		@unittest.skip(reason='''RegNet does not support input and output embeddings'''					)
		def 						lowerCAmelCase__ (self					)	->     Union[str, Any]:

						"""simple docstring"""






						pass



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

						"""simple docstring"""






						lowerCAmelCase__		,						lowerCAmelCase__	:							Tuple				=	self.model_tester.prepare_config_and_inputs_for_common()

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

										lowerCAmelCase__	:							Optional[Any]				=	['''pixel_values''']
										self.assertListEqual(arg_names[:1]						,UpperCamelCase__					)



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

						"""simple docstring"""






						lowerCAmelCase__	:							List[Any]				=	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_model(*UpperCamelCase__					)



		def 						lowerCAmelCase__ (self					)	->     int:

						"""simple docstring"""






						def check_hidden_states_output(__lowerCamelCase						,__lowerCamelCase						,__lowerCamelCase					):
										lowerCAmelCase__	:							List[str]				=	model_class(UpperCamelCase__					)
										lowerCAmelCase__	:							Optional[int]				=	model(**self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__					)						,training=UpperCamelCase__					)

										lowerCAmelCase__	:							Optional[int]				=	outputs.encoder_hidden_states if config.is_encoder_decoder else outputs.hidden_states

										lowerCAmelCase__	:							str				=	self.model_tester.num_stages
										self.assertEqual(len(UpperCamelCase__					)						,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]						,)

						lowerCAmelCase__		,						lowerCAmelCase__	:							Any				=	self.model_tester.prepare_config_and_inputs_for_common()
						lowerCAmelCase__	:							Dict				=	['''basic''', '''bottleneck''']
						for model_class in self.all_model_classes:
										for layer_type in layers_type:
														lowerCAmelCase__	:							Union[str, Any]				=	layer_type
														lowerCAmelCase__	:							List[Any]				=	True
														check_hidden_states_output(UpperCamelCase__						,UpperCamelCase__						,UpperCamelCase__					)

														# check that output_hidden_states also work using config
														del inputs_dict["output_hidden_states"]
														lowerCAmelCase__	:							Optional[int]				=	True

														check_hidden_states_output(UpperCamelCase__						,UpperCamelCase__						,UpperCamelCase__					)



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

						"""simple docstring"""






						lowerCAmelCase__		,						lowerCAmelCase__	:							Union[str, Any]				=	self.model_tester.prepare_config_and_inputs_for_common()

						def check_equivalence(__lowerCamelCase						,__lowerCamelCase						,__lowerCamelCase						,__lowerCamelCase={}					):
										lowerCAmelCase__	:							List[str]				=	model(UpperCamelCase__						,return_dict=UpperCamelCase__						,**UpperCamelCase__					)
										lowerCAmelCase__	:							Optional[int]				=	model(UpperCamelCase__						,return_dict=UpperCamelCase__						,**UpperCamelCase__					).to_tuple()

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

														recursive_check(UpperCamelCase__						,UpperCamelCase__					)

						for model_class in self.all_model_classes:
										lowerCAmelCase__	:							str				=	model_class(UpperCamelCase__					)

										lowerCAmelCase__	:							Dict				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__					)
										lowerCAmelCase__	:							Any				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__					)
										check_equivalence(UpperCamelCase__						,UpperCamelCase__						,UpperCamelCase__					)

										lowerCAmelCase__	:							Optional[Any]				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__						,return_labels=UpperCamelCase__					)
										lowerCAmelCase__	:							List[Any]				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__						,return_labels=UpperCamelCase__					)
										check_equivalence(UpperCamelCase__						,UpperCamelCase__						,UpperCamelCase__					)

										lowerCAmelCase__	:							Optional[Any]				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__					)
										lowerCAmelCase__	:							List[Any]				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__					)
										check_equivalence(UpperCamelCase__						,UpperCamelCase__						,UpperCamelCase__						,{'''output_hidden_states''': True}					)

										lowerCAmelCase__	:							List[Any]				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__						,return_labels=UpperCamelCase__					)
										lowerCAmelCase__	:							Tuple				=	self._prepare_for_class(UpperCamelCase__						,UpperCamelCase__						,return_labels=UpperCamelCase__					)
										check_equivalence(UpperCamelCase__						,UpperCamelCase__						,UpperCamelCase__						,{'''output_hidden_states''': True}					)



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

						"""simple docstring"""






						lowerCAmelCase__	:							Optional[Any]				=	self.model_tester.prepare_config_and_inputs()
						self.model_tester.create_and_check_for_image_classification(*UpperCamelCase__					)



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

						"""simple docstring"""






						for model_name in TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[:1]:
										lowerCAmelCase__	:							Dict				=	TFRegNetModel.from_pretrained(UpperCamelCase__					)
										self.assertIsNotNone(UpperCamelCase__					)






def       lowerCAmelCase__						(       ):





				'''simple docstring'''

				lowerCAmelCase__	:							Union[str, Any]				=	Image.open('''./tests/fixtures/tests_samples/COCO/000000039769.png''')
				return image



@require_tf
@require_vision
class 			lowerCamelCase__     (				unittest.TestCase):




		'''simple docstring'''



		@cached_property
		def 						lowerCAmelCase__ (self					)	->     Tuple:

						"""simple docstring"""






						return (
						    AutoImageProcessor.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]					)
						    if is_vision_available()
						    else None
						)



		@slow
		def 						lowerCAmelCase__ (self					)	->     List[Any]:

						"""simple docstring"""






						lowerCAmelCase__	:							str				=	TFRegNetForImageClassification.from_pretrained(TF_REGNET_PRETRAINED_MODEL_ARCHIVE_LIST[0]					)

						lowerCAmelCase__	:							Optional[Any]				=	self.default_image_processor
						lowerCAmelCase__	:							List[Any]				=	prepare_img()
						lowerCAmelCase__	:							List[str]				=	image_processor(images=UpperCamelCase__						,return_tensors='''tf'''					)

						# forward pass
						lowerCAmelCase__	:							Optional[Any]				=	model(**UpperCamelCase__						,training=UpperCamelCase__					)

						# verify the logits
						lowerCAmelCase__	:							Dict				=	tf.TensorShape((1, 10_00)					)
						self.assertEqual(outputs.logits.shape						,UpperCamelCase__					)

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

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




'''simple docstring'''







import csv

import tweepy

# Twitter API credentials
__lowerCamelCase									=     ''''''
__lowerCamelCase									=     ''''''
__lowerCamelCase									=     ''''''
__lowerCamelCase									=     ''''''
def    UpperCAmelCase__     (   UpperCAmelCase__					)      ->      None:
       # authorize twitter, initialize tweepy
       A_						       =   tweepy.OAuthHandler(UpperCAmelCase__,							UpperCAmelCase__					)
       auth.set_access_token(UpperCAmelCase__,							UpperCAmelCase__					)
       A_						       =   tweepy.API(UpperCAmelCase__					)

       # initialize a list to hold all the tweepy Tweets
       A_						       =   []

       # make initial request for most recent tweets (200 is the maximum allowed count)
       A_						       =   api.user_timeline(screen_name=UpperCAmelCase__,							count=2_00					)

       # save most recent tweets
       alltweets.extend(UpperCAmelCase__					)

       # save the id of the oldest tweet less one
       A_						       =   alltweets[-1].id - 1

       # keep grabbing tweets until there are no tweets left to grab
       while len(UpperCAmelCase__					) > 0:
              print(F'''getting tweets before {oldest}'''					)

              # all subsequent requests use the max_id param to prevent duplicates
              A_						       =   api.user_timeline(
                  screen_name=UpperCAmelCase__,							count=2_00,							max_id=UpperCAmelCase__					)

              # save most recent tweets
              alltweets.extend(UpperCAmelCase__					)

              # update the id of the oldest tweet less one
              A_						       =   alltweets[-1].id - 1

              print(F'''...{len(UpperCAmelCase__					)} tweets downloaded so far'''					)

       # transform the tweepy tweets into a 2D array that will populate the csv
       A_						       =   [[tweet.id_str, tweet.created_at, tweet.text] for tweet in alltweets]

       # write the csv
       with open(F'''new_{screen_name}_tweets.csv''',							"""w"""					) as f:
              A_						       =   csv.writer(UpperCAmelCase__					)
              writer.writerow(["""id""", """created_at""", """text"""]					)
              writer.writerows(UpperCAmelCase__					)


if __name__ == "__main__":
      # pass in the username of the account you want to download
      get_all_tweets('''FirePing32''')
