



"""simple docstring"""






import gc
import unittest

import numpy as np
import torch
from transformers import CLIPTextConfig, CLIPTextModel, CLIPTokenizer

from diffusers import TransformeraDModel, VQDiffusionPipeline, VQDiffusionScheduler, VQModel
from diffusers.pipelines.vq_diffusion.pipeline_vq_diffusion import LearnedClassifierFreeSamplingEmbeddings
from diffusers.utils import load_numpy, slow, torch_device
from diffusers.utils.testing_utils import require_torch_gpu


__snake_case							:   int      =    False



class 			A__   (  unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any])				->       List[Any]:

				"""simple docstring"""

				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		List[str])				->       Tuple:

				"""simple docstring"""

				return 12

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any])				->       Optional[Any]:

				"""simple docstring"""

				return 12

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       Dict:

				"""simple docstring"""

				return 32

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		Any)				->       Dict:

				"""simple docstring"""

				torch.manual_seed(0)
				__lowerCAmelCase      :  Optional[int]												=       VQModel(
				    block_out_channels=[32, 64]       ,			in_channels=3       ,			out_channels=3       ,			down_block_types=["DownEncoderBlock2D", "DownEncoderBlock2D"]       ,			up_block_types=["UpDecoderBlock2D", "UpDecoderBlock2D"]       ,			latent_channels=3       ,			num_vq_embeddings=self.num_embed       ,			vq_embed_dim=3       ,			)
				return model

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		Tuple)				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  Union[str, Any]												=       CLIPTokenizer.from_pretrained("hf-internal-testing/tiny-random-clip")
				return tokenizer

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		int)				->       Optional[int]:

				"""simple docstring"""

				torch.manual_seed(0)
				__lowerCAmelCase      :  Tuple												=       CLIPTextConfig(
				    bos_token_id=0       ,			eos_token_id=2       ,			hidden_size=self.text_embedder_hidden_size       ,			intermediate_size=37       ,			layer_norm_eps=1e-05       ,			num_attention_heads=4       ,			num_hidden_layers=5       ,			pad_token_id=1       ,			vocab_size=1000       ,			)
				return CLIPTextModel(_SCREAMING_SNAKE_CASE)

	@property
	def 							_SCREAMING_SNAKE_CASE   (     self:		List[Any])				->       Optional[int]:

				"""simple docstring"""

				torch.manual_seed(0)

				__lowerCAmelCase      :  Optional[Any]												=       12
				__lowerCAmelCase      :  Dict												=       12

				__lowerCAmelCase      :  Any												=       {
				    "attention_bias": True,
				    "cross_attention_dim": 32,
				    "attention_head_dim": height * width,
				    "num_attention_heads": 1,
				    "num_vector_embeds": self.num_embed,
				    "num_embeds_ada_norm": self.num_embeds_ada_norm,
				    "norm_num_groups": 32,
				    "sample_size": width,
				    "activation_fn": "geglu-approximate",
				}

				__lowerCAmelCase      :  str												=       TransformeraDModel(**_SCREAMING_SNAKE_CASE)
				return model

	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[int])				->       str:

				"""simple docstring"""

				__lowerCAmelCase      :  List[str]												=       "cpu"

				__lowerCAmelCase      :  Tuple												=       self.dummy_vqvae
				__lowerCAmelCase      :  List[Any]												=       self.dummy_text_encoder
				__lowerCAmelCase      :  Any												=       self.dummy_tokenizer
				__lowerCAmelCase      :  Optional[int]												=       self.dummy_transformer
				__lowerCAmelCase      :  List[str]												=       VQDiffusionScheduler(self.num_embed)
				__lowerCAmelCase      :  Tuple												=       LearnedClassifierFreeSamplingEmbeddings(learnable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Union[str, Any]												=       VQDiffusionPipeline(
				    vqvae=_SCREAMING_SNAKE_CASE       ,			text_encoder=_SCREAMING_SNAKE_CASE       ,			tokenizer=_SCREAMING_SNAKE_CASE       ,			transformer=_SCREAMING_SNAKE_CASE       ,			scheduler=_SCREAMING_SNAKE_CASE       ,			learned_classifier_free_sampling_embeddings=_SCREAMING_SNAKE_CASE       ,			)
				__lowerCAmelCase      :  Dict												=       pipe.to(_SCREAMING_SNAKE_CASE)
				pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  int												=       "teddy bear playing in the pool"

				__lowerCAmelCase      :  Optional[Any]												=       torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(0)
				__lowerCAmelCase      :  Dict												=       pipe([prompt]       ,			generator=_SCREAMING_SNAKE_CASE       ,			num_inference_steps=2       ,			output_type="np")
				__lowerCAmelCase      :  List[str]												=       output.images

				__lowerCAmelCase      :  Union[str, Any]												=       torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(0)
				__lowerCAmelCase      :  Tuple												=       pipe(
				    [prompt]       ,			generator=_SCREAMING_SNAKE_CASE       ,			output_type="np"       ,			return_dict=_SCREAMING_SNAKE_CASE       ,			num_inference_steps=2)[0]

				__lowerCAmelCase      :  Union[str, Any]												=       image[0, -3:, -3:, -1]
				__lowerCAmelCase      :  Union[str, Any]												=       image_from_tuple[0, -3:, -3:, -1]

				assert image.shape == (1, 24, 24, 3)

				__lowerCAmelCase      :  Dict												=       np.array([0.6551, 0.6168, 0.5008, 0.5676, 0.5659, 0.4295, 0.6073, 0.5599, 0.4992])

				assert np.abs(image_slice.flatten() - expected_slice).max() < 1e-2
				assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2







	def 							_SCREAMING_SNAKE_CASE   (     self:		Dict)				->       Dict:

				"""simple docstring"""

				__lowerCAmelCase      :  Tuple												=       "cpu"

				__lowerCAmelCase      :  List[Any]												=       self.dummy_vqvae
				__lowerCAmelCase      :  List[Any]												=       self.dummy_text_encoder
				__lowerCAmelCase      :  Any												=       self.dummy_tokenizer
				__lowerCAmelCase      :  Optional[int]												=       self.dummy_transformer
				__lowerCAmelCase      :  Union[str, Any]												=       VQDiffusionScheduler(self.num_embed)
				__lowerCAmelCase      :  List[Any]												=       LearnedClassifierFreeSamplingEmbeddings(
				    learnable=_SCREAMING_SNAKE_CASE       ,			hidden_size=self.text_embedder_hidden_size       ,			length=tokenizer.model_max_length)

				__lowerCAmelCase      :  Optional[int]												=       VQDiffusionPipeline(
				    vqvae=_SCREAMING_SNAKE_CASE       ,			text_encoder=_SCREAMING_SNAKE_CASE       ,			tokenizer=_SCREAMING_SNAKE_CASE       ,			transformer=_SCREAMING_SNAKE_CASE       ,			scheduler=_SCREAMING_SNAKE_CASE       ,			learned_classifier_free_sampling_embeddings=_SCREAMING_SNAKE_CASE       ,			)
				__lowerCAmelCase      :  int												=       pipe.to(_SCREAMING_SNAKE_CASE)
				pipe.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				__lowerCAmelCase      :  Tuple												=       "teddy bear playing in the pool"

				__lowerCAmelCase      :  List[Any]												=       torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(0)
				__lowerCAmelCase      :  Any												=       pipe([prompt]       ,			generator=_SCREAMING_SNAKE_CASE       ,			num_inference_steps=2       ,			output_type="np")
				__lowerCAmelCase      :  Union[str, Any]												=       output.images

				__lowerCAmelCase      :  Dict												=       torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(0)
				__lowerCAmelCase      :  Optional[Any]												=       pipe(
				    [prompt]       ,			generator=_SCREAMING_SNAKE_CASE       ,			output_type="np"       ,			return_dict=_SCREAMING_SNAKE_CASE       ,			num_inference_steps=2)[0]

				__lowerCAmelCase      :  Optional[Any]												=       image[0, -3:, -3:, -1]
				__lowerCAmelCase      :  Optional[int]												=       image_from_tuple[0, -3:, -3:, -1]

				assert image.shape == (1, 24, 24, 3)

				__lowerCAmelCase      :  str												=       np.array([0.6693, 0.6075, 0.4959, 0.5701, 0.5583, 0.4333, 0.6171, 0.5684, 0.4988])

				assert np.abs(image_slice.flatten() - expected_slice).max() < 2.0
				assert np.abs(image_from_tuple_slice.flatten() - expected_slice).max() < 1e-2






@slow
@require_torch_gpu
class 			A__   (  unittest.TestCase							):




	'''simple docstring'''





	def 							_SCREAMING_SNAKE_CASE   (     self:		str)				->       str:

				"""simple docstring"""

				super().tearDown()
				gc.collect()
				torch.cuda.empty_cache()







	def 							_SCREAMING_SNAKE_CASE   (     self:		Optional[Any])				->       int:

				"""simple docstring"""

				__lowerCAmelCase      :  Tuple												=       load_numpy(
				    "https://huggingface.co/datasets/hf-internal-testing/diffusers-images/resolve/main"
				    "/vq_diffusion/teddy_bear_pool_classifier_free_sampling.npy")

				__lowerCAmelCase      :  Union[str, Any]												=       VQDiffusionPipeline.from_pretrained("microsoft/vq-diffusion-ithq")
				__lowerCAmelCase      :  Optional[int]												=       pipeline.to(_SCREAMING_SNAKE_CASE)
				pipeline.set_progress_bar_config(disable=_SCREAMING_SNAKE_CASE)

				# requires GPU generator for gumbel softmax
				# don't use GPU generator in tests though
				__lowerCAmelCase      :  Tuple												=       torch.Generator(device=_SCREAMING_SNAKE_CASE).manual_seed(0)
				__lowerCAmelCase      :  Any												=       pipeline(
				    "teddy bear playing in the pool"       ,			num_images_per_prompt=1       ,			generator=_SCREAMING_SNAKE_CASE       ,			output_type="np"       ,			)

				__lowerCAmelCase      :  Tuple												=       output.images[0]

				assert image.shape == (256, 256, 3)
				assert np.abs(expected_image - image).max() < 2.0




"""simple docstring"""






from itertools import zip_longest

import requests
from bsa import BeautifulSoup
from pandas import DataFrame


def 			_lowercase				(  __snake_case = "laptop"	)						->   DataFrame:
			__lowerCAmelCase      :  str												=       F"""https://www.amazon.in/laptop/s?k={product}"""
			__lowerCAmelCase      :  Union[str, Any]												=       {
			    "User-Agent": "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36\n        (KHTML, like Gecko)Chrome/44.0.2403.157 Safari/537.36",
			    "Accept-Language": "en-US, en;q=0.5",
			}
			__lowerCAmelCase      :  List[str]												=       BeautifulSoup(requests.get(__snake_case					,headers=__snake_case	).text	)
			# Initialize a Pandas dataframe with the column titles
			__lowerCAmelCase      :  Dict												=       DataFrame(
			    columns=[
			        "Product Title",
			        "Product Link",
			        "Current Price of the product",
			        "Product Rating",
			        "MRP of the product",
			        "Discount",
			    ]	)
			# Loop through each entry and store them in the dataframe
			for item, _ in zip_longest(
			    soup.find_all(
			        "div"					,attrs={"class": "s-result-item", "data-component-type": "s-search-result"}					,)					,soup.find_all("div"					,attrs={"class": "a-row a-size-base a-color-base"}	)					,):
						try:
									__lowerCAmelCase      :  Any												=       item.ha.text
									__lowerCAmelCase      :  Union[str, Any]												=       "https://www.amazon.in/" + item.ha.a["href"]
									__lowerCAmelCase      :  Any												=       item.find("span"					,attrs={"class": "a-offscreen"}	).text
									try:
												__lowerCAmelCase      :  Union[str, Any]												=       item.find("span"					,attrs={"class": "a-icon-alt"}	).text
									except AttributeError:
												__lowerCAmelCase      :  Optional[Any]												=       "Not available"
									try:
												__lowerCAmelCase      :  Union[str, Any]												=       (
												    "₹"
												    + item.find(
												        "span"					,attrs={"class": "a-price a-text-price"}	).text.split("₹"	)[1]
												)
									except AttributeError:
												__lowerCAmelCase      :  Dict												=       ""
									try:
												__lowerCAmelCase      :  str												=       float(
												    (
												        (
												            float(product_mrp.strip("₹"	).replace(","					,""	)	)
												            - float(product_price.strip("₹"	).replace(","					,""	)	)
												        )
												        / float(product_mrp.strip("₹"	).replace(","					,""	)	)
												    )
												    * 100	)
									except ValueError:
												__lowerCAmelCase      :  List[str]												=       float("nan"	)
						except AttributeError:
									pass
						__lowerCAmelCase      :  int												=       [
						    product_title,
						    product_link,
						    product_price,
						    product_rating,
						    product_mrp,
						    discount,
						]
			__lowerCAmelCase      :  Union[str, Any]												=       " "
			__lowerCAmelCase      :  Union[str, Any]												=       " "
			data_frame.index += 1
			return data_frame


if __name__ == "__main__":
	__snake_case							:   Any      =    'headphones'
	get_amazon_product_data(product).to_csv(F"""Amazon Product Data for {product}.csv""")