

'''simple docstring'''







import argparse

import intel_extension_for_pytorch as ipex
import torch

from diffusers import DPMSolverMultistepScheduler, StableDiffusionPipeline


__lowerCamelCase						    =      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						    =      parser.parse_args()


__lowerCamelCase						    =      '''cpu'''
__lowerCamelCase						    =      '''a lovely <dicoo> in red dress and hat, in the snowly and brightly night, with many brighly buildings'''

__lowerCamelCase						    =      '''path-to-your-trained-model'''
__lowerCamelCase						    =      StableDiffusionPipeline.from_pretrained(model_id)
if args.dpm:
      __lowerCamelCase						    =      DPMSolverMultistepScheduler.from_config(pipe.scheduler.config)
__lowerCamelCase						    =      pipe.to(device)

# to channels last
__lowerCamelCase						    =      pipe.unet.to(memory_format=torch.channels_last)
__lowerCamelCase						    =      pipe.vae.to(memory_format=torch.channels_last)
__lowerCamelCase						    =      pipe.text_encoder.to(memory_format=torch.channels_last)
if pipe.requires_safety_checker:
      __lowerCamelCase						    =      pipe.safety_checker.to(memory_format=torch.channels_last)

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

# compute
__lowerCamelCase						    =      666
__lowerCamelCase						    =      torch.Generator(device).manual_seed(seed)
__lowerCamelCase						    =      {'''generator''': generator}
if args.steps is not None:
      __lowerCamelCase						    =      args.steps

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

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



'''simple docstring'''







import requests

__lowerCamelCase						    =      ''''''  # <-- Put your OpenWeatherMap appid here!
__lowerCamelCase						    =      '''https://api.openweathermap.org/data/2.5/'''
def  UpperCAmelCase__      ( UpperCAmelCase__ = "Chicago",    UpperCAmelCase__ = APPID			)     ->     dict:
       return requests.get(URL_BASE + """weather""",    params=locals()			).json()
def  UpperCAmelCase__      ( UpperCAmelCase__ = "Kolkata, India",    UpperCAmelCase__ = APPID			)     ->     dict:
       return requests.get(URL_BASE + """forecast""",    params=locals()			).json()
def  UpperCAmelCase__      ( UpperCAmelCase__ = 55.68,    UpperCAmelCase__ = 12.57,    UpperCAmelCase__ = APPID			)     ->     dict:
       return requests.get(URL_BASE + """onecall""",    params=locals()			).json()


if __name__ == "__main__":
      from pprint import pprint

      while True:
            __lowerCamelCase						    =      input('''Enter a location:''').strip()
            if location:
                  pprint(current_weather(location))
            else:
                  break
