import torch
from torch import nn
from transformers import CLIPPreTrainedModel, CLIPVisionModel

from ...models.attention import BasicTransformerBlock
from ...utils import logging


__a  :     Optional[Any]       =  logging.get_logger(__name__)  # pylint: disable=invalid-name




class    _UpperCamelCase      (						_UpperCAmelCase ):


			"""simple docstring"""






			def __init__(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__=7_68						)     ->					Any:

							'''simple docstring'''


							super().__init__(lowerCAmelCase__						)
							__lowercase 			=							proj_size

							__lowercase 			=							CLIPVisionModel(lowerCAmelCase__						)
							__lowercase 			=							PaintByExampleMapper(lowerCAmelCase__						)
							__lowercase 			=							nn.LayerNorm(config.hidden_size						)
							__lowercase 			=							nn.Linear(config.hidden_size      ,   self.proj_size						)

							# uncondition for scaling
							__lowercase 			=							nn.Parameter(torch.randn((1, 1, self.proj_size)						)						)





			def        _SCREAMING_SNAKE_CASE			(   self      ,   lowerCAmelCase__      ,   lowerCAmelCase__=False						)     ->					Dict:

							'''simple docstring'''


							__lowercase 			=							self.model(pixel_values=lowerCAmelCase__						)
							__lowercase 			=							clip_output.pooler_output
							__lowercase 			=							self.mapper(latent_states[:, None]						)
							__lowercase 			=							self.final_layer_norm(lowerCAmelCase__						)
							__lowercase 			=							self.proj_out(lowerCAmelCase__						)
							if return_uncond_vector:
											return latent_states, self.uncond_vector

							return latent_states




class    _UpperCamelCase      (						nn.Module ):


			"""simple docstring"""






			def __init__(   self      ,   lowerCAmelCase__						)     ->					Dict:

							'''simple docstring'''


							super().__init__()
							__lowercase 			=							(config.num_hidden_layers + 1) // 5
							__lowercase 			=							config.hidden_size
							__lowercase 			=							1
							__lowercase 			=							nn.ModuleList(
							    [
							        BasicTransformerBlock(lowerCAmelCase__      ,   lowerCAmelCase__      ,   lowerCAmelCase__      ,   activation_fn='''gelu'''      ,   attention_bias=lowerCAmelCase__						)
							        for _ in range(lowerCAmelCase__						)
							    ]						)





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

							'''simple docstring'''


							for block in self.blocks:
											__lowercase 			=							block(lowerCAmelCase__						)

							return hidden_states
import requests





def 				UpperCAmelCase						(    lowercase							,			lowercase							):







				"""simple docstring"""



				__lowercase 			=							{'''Content-Type''': '''application/json'''}
				__lowercase 			=							requests.post(lowercase							,			json={'''text''': message_body}							,			headers=lowercase							)
				if response.status_code != 200:
								__lowercase 			=							(
								    '''Request to slack returned an error '''
								    F"{response.status_code}, the response is:\n{response.text}"
								)
								raise ValueError(lowercase							)


if __name__ == "__main__":
		# Set the slack url to the one provided by Slack when you create the webhook at
		# https://my.slack.com/services/new/incoming-webhook/
		send_slack_message("""<YOUR MESSAGE BODY>""", """<SLACK CHANNEL URL>""")