
import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


__lowerCAmelCase					:			int			      =		argparse.ArgumentParser("Stable Diffusion script with intel optimization", add_help=False)
parser.add_argument("--dpm", action="store_true", help="Enable DPMSolver or not")
parser.add_argument("--steps", default=None, type=int, help="Num inference steps")
__lowerCAmelCase					:			int			      =		parser.parse_args()


__lowerCAmelCase					:			Dict			      =		"cpu"
__lowerCAmelCase					:			Any			      =		"a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings"

__lowerCAmelCase					:			List[str]			      =		"path-to-your-trained-model"
__lowerCAmelCase					:			Optional[Any]			      =		StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
 __lowerCAmelCase					:			List[str]			      =		DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
__lowerCAmelCase					:			Optional[Any]			      =		pipe.to(device)

# to channels last
__lowerCAmelCase					:			Union[str, Any]			      =		pipe.unet.to(memory_format=torch.channels_last)
__lowerCAmelCase					:			List[str]			      =		pipe.vae.to(memory_format=torch.channels_last)
__lowerCAmelCase					:			str			      =		pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
 __lowerCAmelCase					:			List[str]			      =		pipe.safety_checker.to(memory_format=torch.channels_last)

# optimize with ipex
__lowerCAmelCase					:			List[Any]			      =		torch.randn(2, 4, 64, 64)
__lowerCAmelCase					:			Any			      =		torch.rand(1) * 999
__lowerCAmelCase					:			int			      =		torch.randn(2, 77, 768)
__lowerCAmelCase					:			List[Any]			      =		(sample, timestep, encoder_hidden_status)
try:
 __lowerCAmelCase					:			List[str]			      =		ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True, sample_input=input_example)
except Exception:
 __lowerCAmelCase					:			int			      =		ipex.optimize(pipe.unet.eval(), dtype=torch.bfloataa, inplace=True)
__lowerCAmelCase					:			Optional[int]			      =		ipex.optimize(pipe.vae.eval(), dtype=torch.bfloataa, inplace=True)
__lowerCAmelCase					:			str			      =		ipex.optimize(pipe.text_encoder.eval(), dtype=torch.bfloataa, inplace=True)
if pipe.requires_safety_checker:
 __lowerCAmelCase					:			int			      =		ipex.optimize(pipe.safety_checker.eval(), dtype=torch.bfloataa, inplace=True)

# compute
__lowerCAmelCase					:			Optional[Any]			      =		666
__lowerCAmelCase					:			Optional[int]			      =		torch.Generator(device).manual_seed(seed)
__lowerCAmelCase					:			Optional[Any]			      =		{"generator": generator}
if args.steps is not None:
 __lowerCAmelCase					:			int			      =		args.steps

with torch.cpu.amp.autocast(enabled=True, dtype=torch.bfloataa):
 __lowerCAmelCase					:			Any			      =		pipe(prompt, **generate_kwargs).images[0]

# save image
image.save("generated.png")




import csv

import tweepy

# Twitter API credentials
__lowerCAmelCase					:			str			      =		""
__lowerCAmelCase					:			Any			      =		""
__lowerCAmelCase					:			Any			      =		""
__lowerCAmelCase					:			Optional[int]			      =		""


def     UpperCAmelCase_  (						__lowerCAmelCase	) ->						None:
    # authorize twitter, initialize tweepy
    __lowercase		:			List[Any]	    =       tweepy.OAuthHandler(__lowerCAmelCase	,					__lowerCAmelCase	)
    auth.set_access_token(__lowerCAmelCase	,					__lowerCAmelCase	)
    __lowercase		:			str	    =       tweepy.API(__lowerCAmelCase	)

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

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

    # save most recent tweets
    alltweets.extend(__lowerCAmelCase	)

    # save the id of the oldest tweet less one
    __lowercase		:			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
        __lowercase		:			Tuple	    =       api.user_timeline(
            screen_name=__lowerCAmelCase	,					count=200	,					max_id=__lowerCAmelCase	)

        # save most recent tweets
        alltweets.extend(__lowerCAmelCase	)

        # update the id of the oldest tweet less one
        __lowercase		:			Any	    =       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
    __lowercase		:			Optional[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:
        __lowercase		:			int	    =       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")


