





from typing import Any, Callable, Dict, List, Optional, Union

import torch
from transformers import CLIPImageProcessor, CLIPTextModel, CLIPTokenizer

from diffusers import (
    AutoencoderKL,
    DDIMScheduler,
    DiffusionPipeline,
    LMSDiscreteScheduler,
    PNDMScheduler,
    StableDiffusionPipeline,
    UNetaDConditionModel,
)
from diffusers.pipelines.stable_diffusion import StableDiffusionPipelineOutput
from diffusers.pipelines.stable_diffusion.safety_checker import StableDiffusionSafetyChecker


lowerCAmelCase_						   =    """CompVis/stable-diffusion-v1-1"""
lowerCAmelCase_						   =    """CompVis/stable-diffusion-v1-2"""
lowerCAmelCase_						   =    """CompVis/stable-diffusion-v1-3"""
lowerCAmelCase_						   =    """CompVis/stable-diffusion-v1-4"""



class        _lowerCAmelCase    (			UpperCAmelCase_							):


  '''simple docstring'''







  def __init__(      self      :					List[str]      ,				UpperCamelCase      :					AutoencoderKL      ,				UpperCamelCase      :					CLIPTextModel      ,				UpperCamelCase      :					CLIPTokenizer      ,				UpperCamelCase      :					UNetaDConditionModel      ,				UpperCamelCase      :					Union[DDIMScheduler, PNDMScheduler, LMSDiscreteScheduler]      ,				UpperCamelCase      :					StableDiffusionSafetyChecker      ,				UpperCamelCase      :					CLIPImageProcessor      ,				UpperCamelCase      :					bool = True      ,				):


    '''simple docstring'''





    super()._init_()

    _snake_case   :				List[str]														=	StableDiffusionPipeline.from_pretrained(UpperCamelCase							)
    _snake_case   :				Tuple														=	StableDiffusionPipeline.from_pretrained(UpperCamelCase							)
    _snake_case   :				Tuple														=	StableDiffusionPipeline.from_pretrained(UpperCamelCase							)
    _snake_case   :				List[str]														=	StableDiffusionPipeline(
        vae=UpperCamelCase      ,				text_encoder=UpperCamelCase      ,				tokenizer=UpperCamelCase      ,				unet=UpperCamelCase      ,				scheduler=UpperCamelCase      ,				safety_checker=UpperCamelCase      ,				feature_extractor=UpperCamelCase      ,				requires_safety_checker=UpperCamelCase      ,				)

    self.register_modules(pipelinea=self.pipea      ,				pipelinea=self.pipea      ,				pipelinea=self.pipea      ,				pipelinea=self.pipea							)







  @property
  def UpperCamelCase_ (      self      :					int							):


    '''simple docstring'''





    return {k: getattr(self      ,				UpperCamelCase							) for k in self.config.keys() if not k.startswith('_'							)}







  def UpperCamelCase_ (      self      :					Dict      ,				UpperCamelCase      :					Optional[Union[str, int]] = "auto"							):


    '''simple docstring'''





    if slice_size == "auto":
      # half the attention head size is usually a good trade-off between
      # speed and memory
      _snake_case   :				int														=	self.unet.config.attention_head_dim // 2
    self.unet.set_attention_slice(UpperCamelCase							)







  def UpperCamelCase_ (      self      :					List[str]							):


    '''simple docstring'''





    self.enable_attention_slicing(UpperCamelCase							)







  @torch.no_grad()
  def UpperCamelCase_ (      self      :					Dict      ,				UpperCamelCase      :					Union[str, List[str]]      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 50      ,				UpperCamelCase      :					float = 7.5      ,				UpperCamelCase      :					Optional[Union[str, List[str]]] = None      ,				UpperCamelCase      :					Optional[int] = 1      ,				UpperCamelCase      :					float = 0.0      ,				UpperCamelCase      :					Optional[torch.Generator] = None      ,				UpperCamelCase      :					Optional[torch.FloatTensor] = None      ,				UpperCamelCase      :					Optional[str] = "pil"      ,				UpperCamelCase      :					bool = True      ,				UpperCamelCase      :					Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,				UpperCamelCase      :					int = 1      ,				**UpperCamelCase      :					List[str]      ,				):


    '''simple docstring'''





    return self.pipea(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)







  @torch.no_grad()
  def UpperCamelCase_ (      self      :					Optional[int]      ,				UpperCamelCase      :					Union[str, List[str]]      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 50      ,				UpperCamelCase      :					float = 7.5      ,				UpperCamelCase      :					Optional[Union[str, List[str]]] = None      ,				UpperCamelCase      :					Optional[int] = 1      ,				UpperCamelCase      :					float = 0.0      ,				UpperCamelCase      :					Optional[torch.Generator] = None      ,				UpperCamelCase      :					Optional[torch.FloatTensor] = None      ,				UpperCamelCase      :					Optional[str] = "pil"      ,				UpperCamelCase      :					bool = True      ,				UpperCamelCase      :					Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,				UpperCamelCase      :					int = 1      ,				**UpperCamelCase      :					Tuple      ,				):


    '''simple docstring'''





    return self.pipea(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)







  @torch.no_grad()
  def UpperCamelCase_ (      self      :					Tuple      ,				UpperCamelCase      :					Union[str, List[str]]      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 50      ,				UpperCamelCase      :					float = 7.5      ,				UpperCamelCase      :					Optional[Union[str, List[str]]] = None      ,				UpperCamelCase      :					Optional[int] = 1      ,				UpperCamelCase      :					float = 0.0      ,				UpperCamelCase      :					Optional[torch.Generator] = None      ,				UpperCamelCase      :					Optional[torch.FloatTensor] = None      ,				UpperCamelCase      :					Optional[str] = "pil"      ,				UpperCamelCase      :					bool = True      ,				UpperCamelCase      :					Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,				UpperCamelCase      :					int = 1      ,				**UpperCamelCase      :					Any      ,				):


    '''simple docstring'''





    return self.pipea(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)







  @torch.no_grad()
  def UpperCamelCase_ (      self      :					List[str]      ,				UpperCamelCase      :					Union[str, List[str]]      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 50      ,				UpperCamelCase      :					float = 7.5      ,				UpperCamelCase      :					Optional[Union[str, List[str]]] = None      ,				UpperCamelCase      :					Optional[int] = 1      ,				UpperCamelCase      :					float = 0.0      ,				UpperCamelCase      :					Optional[torch.Generator] = None      ,				UpperCamelCase      :					Optional[torch.FloatTensor] = None      ,				UpperCamelCase      :					Optional[str] = "pil"      ,				UpperCamelCase      :					bool = True      ,				UpperCamelCase      :					Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,				UpperCamelCase      :					int = 1      ,				**UpperCamelCase      :					List[str]      ,				):


    '''simple docstring'''





    return self.pipea(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)







  @torch.no_grad()
  def UpperCamelCase_ (      self      :					Optional[Any]      ,				UpperCamelCase      :					Union[str, List[str]]      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 5_12      ,				UpperCamelCase      :					int = 50      ,				UpperCamelCase      :					float = 7.5      ,				UpperCamelCase      :					Optional[Union[str, List[str]]] = None      ,				UpperCamelCase      :					Optional[int] = 1      ,				UpperCamelCase      :					float = 0.0      ,				UpperCamelCase      :					Optional[torch.Generator] = None      ,				UpperCamelCase      :					Optional[torch.FloatTensor] = None      ,				UpperCamelCase      :					Optional[str] = "pil"      ,				UpperCamelCase      :					bool = True      ,				UpperCamelCase      :					Optional[Callable[[int, int, torch.FloatTensor], None]] = None      ,				UpperCamelCase      :					int = 1      ,				**UpperCamelCase      :					List[Any]      ,				):


    '''simple docstring'''





    _snake_case   :				Union[str, Any]														=	'cuda' if torch.cuda.is_available() else 'cpu'
    self.to(UpperCamelCase							)

    # Checks if the height and width are divisible by 8 or not
    if height % 8 != 0 or width % 8 != 0:
      raise ValueError(f"""`height` and `width` must be divisible by 8 but are {height} and {width}."""							)

    # Get first result from Stable Diffusion Checkpoint v1.1
    _snake_case   :				Union[str, Any]														=	self.textaimg_sda_a(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)

    # Get first result from Stable Diffusion Checkpoint v1.2
    _snake_case   :				Union[str, Any]														=	self.textaimg_sda_a(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)

    # Get first result from Stable Diffusion Checkpoint v1.3
    _snake_case   :				Dict														=	self.textaimg_sda_a(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)

    # Get first result from Stable Diffusion Checkpoint v1.4
    _snake_case   :				List[str]														=	self.textaimg_sda_a(
        prompt=UpperCamelCase      ,				height=UpperCamelCase      ,				width=UpperCamelCase      ,				num_inference_steps=UpperCamelCase      ,				guidance_scale=UpperCamelCase      ,				negative_prompt=UpperCamelCase      ,				num_images_per_prompt=UpperCamelCase      ,				eta=UpperCamelCase      ,				generator=UpperCamelCase      ,				latents=UpperCamelCase      ,				output_type=UpperCamelCase      ,				return_dict=UpperCamelCase      ,				callback=UpperCamelCase      ,				callback_steps=UpperCamelCase      ,				**UpperCamelCase      ,				)

    # Get all result images into a single list and pass it via StableDiffusionPipelineOutput for final result
    return StableDiffusionPipelineOutput([resa[0], resa[0], resa[0], resa[0]]							)











import csv

import tweepy

# Twitter API credentials
lowerCAmelCase_						   =    """"""
lowerCAmelCase_						   =    """"""
lowerCAmelCase_						   =    """"""
lowerCAmelCase_						   =    """"""


def     lowerCamelCase_	(      lowerCAmelCase:	str				)->		None:
  # authorize twitter, initialize tweepy
  _snake_case   :				Optional[Any]														=	tweepy.OAuthHandler(lowerCAmelCase    ,							lowerCAmelCase				)
  auth.set_access_token(lowerCAmelCase    ,							lowerCAmelCase				)
  _snake_case   :				List[Any]														=	tweepy.API(lowerCAmelCase				)

  # initialize a list to hold all the tweepy Tweets
  _snake_case   :				Any														=	[]

  # make initial request for most recent tweets (200 is the maximum allowed count)
  _snake_case   :				List[str]														=	api.user_timeline(screen_name=lowerCAmelCase    ,							count=2_00				)

  # save most recent tweets
  alltweets.extend(lowerCAmelCase				)

  # save the id of the oldest tweet less one
  _snake_case   :				List[Any]														=	alltweets[-1].id - 1

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

    # all subsequent requests use the max_id param to prevent duplicates
    _snake_case   :				Tuple														=	api.user_timeline(
        screen_name=lowerCAmelCase    ,							count=2_00    ,							max_id=lowerCAmelCase				)

    # save most recent tweets
    alltweets.extend(lowerCAmelCase				)

    # update the id of the oldest tweet less one
    _snake_case   :				List[str]														=	alltweets[-1].id - 1

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

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


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




