





"""simple docstring"""





from typing import Optional, Tuple

import jax
import jax.numpy as jnp
from flax import linen as nn
from flax.core.frozen_dict import FrozenDict
from transformers import CLIPConfig, FlaxPreTrainedModel
from transformers.models.clip.modeling_flax_clip import FlaxCLIPVisionModule
def 					__A  (_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE=1e-12     )   ->Tuple:





  """simple docstring"""


  lowerCAmelCase__     :List[Any]											=				jnp.divide(emb_a.T	,  jnp.clip(jnp.linalg.norm(_SCREAMING_SNAKE_CASE	,  axis=1     )	,  a_min=_SCREAMING_SNAKE_CASE     )     ).T
  lowerCAmelCase__     :Any											=				jnp.divide(emb_a.T	,  jnp.clip(jnp.linalg.norm(_SCREAMING_SNAKE_CASE	,  axis=1     )	,  a_min=_SCREAMING_SNAKE_CASE     )     ).T
  return jnp.matmul(_SCREAMING_SNAKE_CASE	,  norm_emb_a.T     )






class    _lowerCAmelCase  (	nn.Module			):
       """simple docstring"""




       __magic_name__	:CLIPConfig
       __magic_name__	:jnp.dtype						    =   jnp.floataa






       def 	snake_case		(       self ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				FlaxCLIPVisionModule(self.config.vision_config )
         lowerCAmelCase__     :str											=				nn.Dense(self.config.projection_dim       ,					use_bias=__UpperCAmelCase       ,					dtype=self.dtype )

         lowerCAmelCase__     :Tuple											=				self.param('concept_embeds'       ,					jax.nn.initializers.ones       ,					(1_7, self.config.projection_dim) )
         lowerCAmelCase__     :int											=				self.param(
             'special_care_embeds'       ,					jax.nn.initializers.ones       ,					(3, self.config.projection_dim) )

         lowerCAmelCase__     :Any											=				self.param('concept_embeds_weights'       ,					jax.nn.initializers.ones       ,					(1_7,) )
         lowerCAmelCase__     :str											=				self.param('special_care_embeds_weights'       ,					jax.nn.initializers.ones       ,					(3,) )






       def __call__(       self       ,					__UpperCAmelCase ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				self.vision_model(__UpperCAmelCase )[1]
         lowerCAmelCase__     :int											=				self.visual_projection(__UpperCAmelCase )

         lowerCAmelCase__     :Any											=				jax_cosine_distance(__UpperCAmelCase       ,					self.special_care_embeds )
         lowerCAmelCase__     :Dict											=				jax_cosine_distance(__UpperCAmelCase       ,					self.concept_embeds )

         # increase this value to create a stronger `nfsw` filter
         # at the cost of increasing the possibility of filtering benign image inputs
         lowerCAmelCase__     :str											=				0.0

         lowerCAmelCase__     :Dict											=				special_cos_dist - self.special_care_embeds_weights[None, :] + adjustment
         lowerCAmelCase__     :Optional[int]											=				jnp.round(__UpperCAmelCase       ,					3 )
         lowerCAmelCase__     :List[str]											=				jnp.any(special_scores > 0       ,					axis=1       ,					keepdims=__UpperCAmelCase )
         # Use a lower threshold if an image has any special care concept
         lowerCAmelCase__     :Tuple											=				is_special_care * 0.01

         lowerCAmelCase__     :Tuple											=				cos_dist - self.concept_embeds_weights[None, :] + special_adjustment
         lowerCAmelCase__     :Tuple											=				jnp.round(__UpperCAmelCase       ,					3 )
         lowerCAmelCase__     :Tuple											=				jnp.any(concept_scores > 0       ,					axis=1 )

         return has_nsfw_concepts






class    _lowerCAmelCase  (	a			):
       """simple docstring"""




       __magic_name__	:Optional[int]						    =   CLIPConfig
       __magic_name__	:Any						    =   """clip_input"""
       __magic_name__	:Tuple						    =   FlaxStableDiffusionSafetyCheckerModule






       def __init__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					__UpperCAmelCase = 0       ,					__UpperCAmelCase = jnp.floataa       ,					__UpperCAmelCase = True       ,					**__UpperCAmelCase       ,					):



         '''simple docstring'''

         if input_shape is None:
           lowerCAmelCase__     :Dict											=				(1, 2_2_4, 2_2_4, 3)
         lowerCAmelCase__     :Optional[int]											=				self.module_class(config=__UpperCAmelCase       ,					dtype=__UpperCAmelCase       ,					**__UpperCAmelCase )
         super().__init__(__UpperCAmelCase       ,					__UpperCAmelCase       ,					input_shape=__UpperCAmelCase       ,					seed=__UpperCAmelCase       ,					dtype=__UpperCAmelCase       ,					_do_init=_do_init )






       def 	snake_case		(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None ):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[Any]											=				jax.random.normal(__UpperCAmelCase       ,					__UpperCAmelCase )

         lowerCAmelCase__				,							lowerCAmelCase__     :Optional[Any]											=				jax.random.split(__UpperCAmelCase )
         lowerCAmelCase__     :Union[str, Any]											=				{'params': params_rng, 'dropout': dropout_rng}

         lowerCAmelCase__     :Optional[int]											=				self.module.init(__UpperCAmelCase       ,					__UpperCAmelCase )['params']

         return random_params






       def __call__(       self       ,					__UpperCAmelCase       ,					__UpperCAmelCase = None       ,					):



         '''simple docstring'''

         lowerCAmelCase__     :Optional[int]											=				jnp.transpose(__UpperCAmelCase       ,					(0, 2, 3, 1) )

         return self.module.apply(
             {'params': params or self.params}       ,					jnp.array(__UpperCAmelCase       ,					dtype=jnp.floataa )       ,					rngs={}       ,					)







"""simple docstring"""





import csv

import tweepy

# Twitter API credentials
__A											=						""""""
__A											=						""""""
__A											=						""""""
__A											=						""""""
def 					__A  (_SCREAMING_SNAKE_CASE     )   ->None:





  """simple docstring"""


  lowerCAmelCase__     :Any											=				tweepy.OAuthHandler(_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )
  auth.set_access_token(_SCREAMING_SNAKE_CASE	,  _SCREAMING_SNAKE_CASE     )
  lowerCAmelCase__     :List[Any]											=				tweepy.API(_SCREAMING_SNAKE_CASE     )

  # initialize a list to hold all the tweepy Tweets
  lowerCAmelCase__     :Union[str, Any]											=				[]

  # make initial request for most recent tweets (200 is the maximum allowed count)
  lowerCAmelCase__     :Optional[Any]											=				api.user_timeline(screen_name=_SCREAMING_SNAKE_CASE	,  count=200     )

  # save most recent tweets
  alltweets.extend(_SCREAMING_SNAKE_CASE     )

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

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

    # all subsequent requests use the max_id param to prevent duplicates
    lowerCAmelCase__     :Union[str, Any]											=				api.user_timeline(
        screen_name=_SCREAMING_SNAKE_CASE	,  count=200	,  max_id=_SCREAMING_SNAKE_CASE     )

    # save most recent tweets
    alltweets.extend(_SCREAMING_SNAKE_CASE     )

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

    print(F"...{len(_SCREAMING_SNAKE_CASE     )} tweets downloaded so far"     )

  # transform the tweepy tweets into a 2D array that will populate the csv
  lowerCAmelCase__     :Optional[Any]											=				[[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:
    lowerCAmelCase__     :List[str]											=				csv.writer(_SCREAMING_SNAKE_CASE     )
    writer.writerow(['id', 'created_at', 'text']     )
    writer.writerows(_SCREAMING_SNAKE_CASE     )


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