




'''simple docstring'''






import argparse

import torch

from transformers import ChineseCLIPConfig, ChineseCLIPModel






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)						->      List[Any]:
      snake_case__			,       snake_case__			,       snake_case__					:      Optional[int]  			=						pt_weights[f"{prefix}.in_proj_weight"].chunk(3							,			dim=0		)
      snake_case__			,       snake_case__			,       snake_case__					:      Union[str, Any]  			=						pt_weights[f"{prefix}.in_proj_bias"].chunk(3							,			dim=0		)

      snake_case__					:      List[Any]  			=						pt_weights[f"{prefix}.out_proj.weight"]
      snake_case__					:      Union[str, Any]  			=						pt_weights[f"{prefix}.out_proj.bias"]

      snake_case__					:      Tuple  			=						q_proj
      snake_case__					:      Dict  			=						q_proj_bias

      snake_case__					:      Tuple  			=						k_proj
      snake_case__					:      List[Any]  			=						k_proj_bias

      snake_case__					:      Tuple  			=						v_proj
      snake_case__					:      Dict  			=						v_proj_bias

      snake_case__					:      Tuple  			=						out_proj_weights
      snake_case__					:      Dict  			=						out_proj_bias






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)						->      Optional[int]:
      copy_linear(hf_mlp.fca							,			__SCREAMING_SNAKE_CASE							,			f"{prefix}.c_fc"		)
      copy_linear(hf_mlp.fca							,			__SCREAMING_SNAKE_CASE							,			f"{prefix}.c_proj"		)






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)						->      Optional[Any]:
      snake_case__					:      Any  			=						pt_weights[f"{prefix}.weight"].data
      snake_case__					:      Tuple  			=						pt_weights[f"{prefix}.bias"].data






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)						->      Dict:
      # copy layer norms
      copy_linear(hf_layer.layer_norma							,			__SCREAMING_SNAKE_CASE							,			f"{prefix}.ln_1"		)
      copy_linear(hf_layer.layer_norma							,			__SCREAMING_SNAKE_CASE							,			f"{prefix}.ln_2"		)

      # copy MLP
      copy_mlp(hf_layer.mlp							,			__SCREAMING_SNAKE_CASE							,			f"{prefix}.mlp"		)

      # copy attn
      copy_attn_layer(hf_layer.self_attn							,			__SCREAMING_SNAKE_CASE							,			f"{prefix}.attn"		)






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)						->      Optional[Any]:
      for layer_id, hf_layer in enumerate(__SCREAMING_SNAKE_CASE		):
            copy_layer(__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE							,			f"{prefix}.{layer_id}"		)






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)						->      Tuple:
      # copy projection
      snake_case__					:      Optional[Any]  			=						pt_weights['text_projection'].data.T

      # copy text encoder
      for name, param in hf_model.text_model.named_parameters():
            snake_case__					:      Dict  			=						pt_weights[f"bert.{name}"].data






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)						->      List[Any]:
      # copy projection
      snake_case__					:      Tuple  			=						pt_weights['visual.proj'].data.T

      # copy layer norms
      copy_linear(hf_model.vision_model.pre_layrnorm							,			__SCREAMING_SNAKE_CASE							,			'visual.ln_pre'		)
      copy_linear(hf_model.vision_model.post_layernorm							,			__SCREAMING_SNAKE_CASE							,			'visual.ln_post'		)

      # copy embeddings
      snake_case__					:      int  			=						pt_weights['visual.conv1.weight'].data
      snake_case__					:      List[str]  			=						pt_weights['visual.class_embedding'].data
      snake_case__					:      str  			=						pt_weights['visual.positional_embedding'].data

      # copy encoder
      copy_layers(hf_model.vision_model.encoder.layers							,			__SCREAMING_SNAKE_CASE							,			'visual.transformer.resblocks'		)






@torch.no_grad()
def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE=None		)						->      List[Any]:
      assert config_path is not None, "Please specify the ChineseCLIP model config of the corresponding model size."
      snake_case__					:      Any  			=						ChineseCLIPConfig.from_pretrained(__SCREAMING_SNAKE_CASE		)

      snake_case__					:      Optional[Any]  			=						ChineseCLIPModel(__SCREAMING_SNAKE_CASE		).eval()

      snake_case__					:      List[Any]  			=						torch.load(__SCREAMING_SNAKE_CASE							,			map_location='cpu'		)['state_dict']
      snake_case__					:      List[Any]  			=						{(name[7:] if name.startswith('module.'		) else name): value for name, value in pt_weights.items()}

      copy_text_model_and_projection(__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)
      copy_vision_model_and_projection(__SCREAMING_SNAKE_CASE							,			__SCREAMING_SNAKE_CASE		)
      snake_case__					:      Optional[int]  			=						pt_weights['logit_scale'].data

      hf_model.save_pretrained(__SCREAMING_SNAKE_CASE		)


if __name__ == "__main__":
      A_ 			=		argparse.ArgumentParser()
      parser.add_argument(
          "--pytorch_dump_folder_path",
          default=None,
          type=str,
          help="Path to the output folder storing converted hf PyTorch model.",
      )
      parser.add_argument(
          "--checkpoint_path", default=None, type=str, help="Path to original github format ChineseCLIP checkpoint."
      )
      parser.add_argument(
          "--config_path", default=None, required=True, type=str, help="Path to hf config.json of model to convert."
      )
      A_ 			=		parser.parse_args()

      convert_chinese_clip_checkpoint(args.checkpoint_path, args.pytorch_dump_folder_path, args.config_path)
      print("The conversion is finished!")






'''simple docstring'''






import bsa
import requests






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE		)						->      dict[str, str]:
      return {
          "name": soup.ha.a.text,
          "genre": soup.find('span'							,			class_='genre'		).text.strip(),
          "rating": soup.strong.text,
          "page_link": f"https://www.imdb.com{soup.a.get('href'		)}",
      }






def 		UpperCamelCase__			(		__SCREAMING_SNAKE_CASE = 5		)						->      tuple:
      snake_case__					:      Tuple  			=						int(float(__SCREAMING_SNAKE_CASE		)		)
      if num_movies < 1:
            return ()
      snake_case__					:      Any  			=						(
          'https://www.imdb.com/search/title?title_type='
          f"feature&sort=num_votes,desc&count={num_movies}"
      )
      snake_case__					:      Union[str, Any]  			=						bsa.BeautifulSoup(requests.get(__SCREAMING_SNAKE_CASE		).content							,			'html.parser'		)
      return tuple(
          get_movie_data_from_soup(__SCREAMING_SNAKE_CASE		)
          for movie in source.find_all('div'							,			class_='lister-item mode-advanced'		)		)


if __name__ == "__main__":
      import json

      A_ 			=		int(input("How many movies would you like to see? "))
      print(
          ", ".join(
              json.dumps(movie, indent=4) for movie in get_imdb_top_movies(num_movies)
          )
      )
