






'''simple docstring'''
import gc
import unittest

from diffusers import FlaxDPMSolverMultistepScheduler, FlaxStableDiffusionPipeline
from diffusers.utils import is_flax_available, slow
from diffusers.utils.testing_utils import require_flax


if is_flax_available():
  import jax
  import jax.numpy as jnp
  from flax.jax_utils import replicate
  from flax.training.common_utils import shard






@slow
@require_flax
class    __SCREAMING_SNAKE_CASE					(	unittest.TestCase ):




 def    __magic_name__		(					self		:							List[str]					)		->  Union[str, Any]:
       super().tearDown()
       gc.collect()




 def    __magic_name__		(					self		:							List[Any]					)		->  Optional[Any]:
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=FlaxStableDiffusionPipeline.from_pretrained(
           '''stabilityai/stable-diffusion-2'''    ,					revision='''bf16'''    ,					dtype=jnp.bfloataa    ,					)

       SCREAMING_SNAKE_CASE__   : List[Any]													="A painting of a squirrel eating a burger"
       SCREAMING_SNAKE_CASE__   : List[str]													=jax.device_count()
       SCREAMING_SNAKE_CASE__   : str													=num_samples * [prompt]
       SCREAMING_SNAKE_CASE__   : str													=sd_pipe.prepare_inputs(__lowercase					)

       SCREAMING_SNAKE_CASE__   : Optional[int]													=replicate(__lowercase					)
       SCREAMING_SNAKE_CASE__   : List[str]													=shard(__lowercase					)

       SCREAMING_SNAKE_CASE__   : int													=jax.random.PRNGKey(0					)
       SCREAMING_SNAKE_CASE__   : Any													=jax.random.split(__lowercase    ,					jax.device_count()					)

       SCREAMING_SNAKE_CASE__   : Dict													=sd_pipe(__lowercase    ,					__lowercase    ,					__lowercase    ,					num_inference_steps=25    ,					jit=__lowercase					)[0]
       assert images.shape == (jax.device_count(), 1, 7_68, 7_68, 3)

       SCREAMING_SNAKE_CASE__   : Optional[int]													=images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]					)
       SCREAMING_SNAKE_CASE__   : str													=images[0, 2_53:2_56, 2_53:2_56, -1]

       SCREAMING_SNAKE_CASE__   : Optional[int]													=jnp.asarray(jax.device_get(image_slice.flatten()					)					)
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=jnp.array([0.4238, 0.4414, 0.4395, 0.4453, 0.4629, 0.4590, 0.4531, 0.45508, 0.4512]					)
       print(F"output_slice: {output_slice}"					)
       assert jnp.abs(output_slice - expected_slice					).max() < 1e-2




 def    __magic_name__		(					self		:							int					)		->  List[Any]:
       SCREAMING_SNAKE_CASE__   : Dict													="stabilityai/stable-diffusion-2"
       SCREAMING_SNAKE_CASE__   : int													=FlaxDPMSolverMultistepScheduler.from_pretrained(__lowercase    ,					subfolder='''scheduler'''					)
       SCREAMING_SNAKE_CASE__   : List[str]													=FlaxStableDiffusionPipeline.from_pretrained(
           __lowercase    ,					scheduler=__lowercase    ,					revision='''bf16'''    ,					dtype=jnp.bfloataa    ,					)
       SCREAMING_SNAKE_CASE__   : str													=scheduler_params

       SCREAMING_SNAKE_CASE__   : List[str]													="A painting of a squirrel eating a burger"
       SCREAMING_SNAKE_CASE__   : Union[str, Any]													=jax.device_count()
       SCREAMING_SNAKE_CASE__   : str													=num_samples * [prompt]
       SCREAMING_SNAKE_CASE__   : List[Any]													=sd_pipe.prepare_inputs(__lowercase					)

       SCREAMING_SNAKE_CASE__   : Tuple													=replicate(__lowercase					)
       SCREAMING_SNAKE_CASE__   : List[str]													=shard(__lowercase					)

       SCREAMING_SNAKE_CASE__   : Optional[Any]													=jax.random.PRNGKey(0					)
       SCREAMING_SNAKE_CASE__   : Tuple													=jax.random.split(__lowercase    ,					jax.device_count()					)

       SCREAMING_SNAKE_CASE__   : Optional[Any]													=sd_pipe(__lowercase    ,					__lowercase    ,					__lowercase    ,					num_inference_steps=25    ,					jit=__lowercase					)[0]
       assert images.shape == (jax.device_count(), 1, 7_68, 7_68, 3)

       SCREAMING_SNAKE_CASE__   : List[str]													=images.reshape((images.shape[0] * images.shape[1],) + images.shape[-3:]					)
       SCREAMING_SNAKE_CASE__   : Optional[Any]													=images[0, 2_53:2_56, 2_53:2_56, -1]

       SCREAMING_SNAKE_CASE__   : int													=jnp.asarray(jax.device_get(image_slice.flatten()					)					)
       SCREAMING_SNAKE_CASE__   : List[str]													=jnp.array([0.4336, 0.42969, 0.4453, 0.4199, 0.4297, 0.4531, 0.4434, 0.4434, 0.4297]					)
       print(F"output_slice: {output_slice}"					)
       assert jnp.abs(output_slice - expected_slice					).max() < 1e-2






'''simple docstring'''


import sys
import webbrowser

import requests
from bsa import BeautifulSoup
from fake_useragent import UserAgent

if __name__ == "__main__":
 print('''Googling.....''')
 lowerCAmelCase					:     str												='''https://www.google.com/search?q=''' + ''' '''.join(sys.argv[1:])
 lowerCAmelCase					:     List[str]												=requests.get(url, headers={'''UserAgent''': UserAgent().random})
 # res.raise_for_status()
 with open('''project1a.html''', '''wb''') as out_file:  # only for knowing the class
  for data in res.iter_content(10_000):
   out_file.write(data)
 lowerCAmelCase					:     List[Any]												=BeautifulSoup(res.text, '''html.parser''')
 lowerCAmelCase					:     List[Any]												=list(soup.select('''.eZt8xd'''))[:5]

 print(len(links))
 for link in links:
  if link.text == "Maps":
   webbrowser.open(link.get('''href'''))
  else:
   webbrowser.open(F'''https://google.com{link.get('href')}''')


