code: 
  
  
  
  import argparse
  
  import torch
  
  from diffusers import UNetaDConditionModel
  
  
  
  def  __a  (					lowerCAmelCase_     :      Dict    ,lowerCAmelCase_     :      Optional[int]    ,lowerCAmelCase_     :      Optional[int]    ,lowerCAmelCase_     :      Optional[int]=None    ,lowerCAmelCase_     :      Tuple=None    ,lowerCAmelCase_     :      Optional[Any]=None       )   ->				Optional[Any]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						assert isinstance(lowercase_    ,lowercase_       ), "Paths should be a list of dicts containing 'old' and 'new' keys."
  
  						# Splits the attention layers into three variables.
  						if attention_paths_to_split is not None:
  												for path, path_map in attention_paths_to_split.items():
  																		UpperCAmelCase_=     old_checkpoint[path]
  																		UpperCAmelCase_=     old_tensor.shape[0] // 3
  
  																		UpperCAmelCase_=     (-1, channels) if len(old_tensor.shape       ) == 3 else (-1)
  
  																		UpperCAmelCase_=     old_tensor.shape[0] // config['''num_head_channels'''] // 3
  
  																		UpperCAmelCase_=     old_tensor.reshape((num_heads, 3 * channels // num_heads) + old_tensor.shape[1:]       )
  																		UpperCAmelCase_=     old_tensor.split(channels // num_heads    ,dim=1       )
  
  																		UpperCAmelCase_=     query.reshape(lowercase_       )
  																		UpperCAmelCase_=     key.reshape(lowercase_       )
  																		UpperCAmelCase_=     value.reshape(lowercase_       )
  
  						for path in paths:
  												UpperCAmelCase_=     path['''new''']
  
  												# These have already been assigned
  												if attention_paths_to_split is not None and new_path in attention_paths_to_split:
  																		continue
  
  												if additional_replacements is not None:
  																		for replacement in additional_replacements:
  																								UpperCAmelCase_=     new_path.replace(replacement["""old"""]    ,replacement["""new"""]       )
  
          # proj_attn.weight has to be converted from conv 1D to linear
  												UpperCAmelCase_=     old_checkpoint[path['''old''']]
  												UpperCAmelCase_=     ['''proj_attn.weight''']
  												UpperCAmelCase_=     ['''proj_out.weight''', '''proj_in.weight''']
  												if any(k in new_path for k in names       ):
  																		UpperCAmelCase_=     weight[:, :, 0]
  												elif any(k in new_path for k in names_a       ) and len(weight.shape       ) > 2 and ".attentions." not in new_path:
  																		UpperCAmelCase_=     weight[:, :, 0]
  												else:
  																		UpperCAmelCase_=     weight
  
  
  
  def  __a  (					lowerCAmelCase_     :      str    ,lowerCAmelCase_     :      List[Any]=0       )   ->				Optional[int]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     []
  						for old_item in old_list:
  												UpperCAmelCase_=     old_item
  
  												#         new_item = new_item.replace('norm.weight', 'group_norm.weight')
  												#         new_item = new_item.replace('norm.bias', 'group_norm.bias')
  
  												#         new_item = new_item.replace('proj_out.weight', 'proj_attn.weight')
  												#         new_item = new_item.replace('proj_out.bias', 'proj_attn.bias')
  
  												#         new_item = shave_segments(new_item, n_shave_prefix_segments=n_shave_prefix_segments)
  
  												mapping.append({"""old""": old_item, """new""": new_item}       )
  
  						return mapping
  
  
  
  def  __a  (					lowerCAmelCase_     :      Union[str, Any]    ,lowerCAmelCase_     :      str=1       )   ->				int:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						if n_shave_prefix_segments >= 0:
  												return ".".join(path.split("""."""       )[n_shave_prefix_segments:]       )
  						else:
  												return ".".join(path.split("""."""       )[:n_shave_prefix_segments]       )
  
  
  
  def  __a  (					lowerCAmelCase_     :      Dict    ,lowerCAmelCase_     :      List[str]=0       )   ->				List[Any]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     []
  						for old_item in old_list:
  												mapping.append({"""old""": old_item, """new""": old_item}       )
  
  						return mapping
  
  
  
  def  __a  (					lowerCAmelCase_     :      List[str]    ,lowerCAmelCase_     :      Union[str, Any]=0       )   ->				str:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     []
  						for old_item in old_list:
  												UpperCAmelCase_=     old_item.replace("""in_layers.0"""    ,"""norm1"""       )
  												UpperCAmelCase_=     new_item.replace("""in_layers.2"""    ,"""conv1"""       )
  
  												UpperCAmelCase_=     new_item.replace("""out_layers.0"""    ,"""norm2"""       )
  												UpperCAmelCase_=     new_item.replace("""out_layers.3"""    ,"""conv2"""       )
  
  												UpperCAmelCase_=     new_item.replace("""emb_layers.1"""    ,"""time_emb_proj"""       )
  												UpperCAmelCase_=     new_item.replace("""skip_connection"""    ,"""conv_shortcut"""       )
  
  												UpperCAmelCase_=     shave_segments(lowercase_    ,n_shave_prefix_segments=lowercase_       )
  
  												if "temopral_conv" not in old_item:
  																		mapping.append({"""old""": old_item, """new""": new_item}       )
  
  						return mapping
  
  
  
  def  __a  (					lowerCAmelCase_     :      Optional[Any]    ,lowerCAmelCase_     :      Optional[int]    ,lowerCAmelCase_     :      int=None    ,lowerCAmelCase_     :      Optional[Any]=False       )   ->				Optional[int]:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     {}
  						UpperCAmelCase_=     list(checkpoint.keys()       )
  
  						UpperCAmelCase_=     '''model.diffusion_model.'''
  
  						# at least a 100 parameters have to start with `model_ema` in order for the checkpoint to be EMA
  						if sum(k.startswith("""model_ema"""       ) for k in keys       ) > 1_00 and extract_ema:
  												print(F"""Checkpoint {path} has both EMA and non-EMA weights."""       )
  												print(
  												    """In this conversion only the EMA weights are extracted. If you want to instead extract the non-EMA"""
  												    """ weights (useful to continue fine-tuning), please make sure to remove the `--extract_ema` flag."""       )
  												for key in keys:
  																		if key.startswith("""model.diffusion_model"""       ):
  																								UpperCAmelCase_=     '''model_ema.''' + ''''''.join(key.split("""."""       )[1:]       )
  																								UpperCAmelCase_=     checkpoint.pop(lowercase_       )
  						else:
  												if sum(k.startswith("""model_ema"""       ) for k in keys       ) > 1_00:
  																		print(
  																		    """In this conversion only the non-EMA weights are extracted. If you want to instead extract the EMA"""
  																		    """ weights (usually better for inference), please make sure to add the `--extract_ema` flag."""       )
  
  												for key in keys:
  																		UpperCAmelCase_=     checkpoint.pop(lowercase_       )
  
  						UpperCAmelCase_=     {}
  
  						UpperCAmelCase_=     unet_state_dict['''time_embed.0.weight''']
  						UpperCAmelCase_=     unet_state_dict['''time_embed.0.bias''']
  						UpperCAmelCase_=     unet_state_dict['''time_embed.2.weight''']
  						UpperCAmelCase_=     unet_state_dict['''time_embed.2.bias''']
  
  						if config["class_embed_type"] is None:
  												# No parameters to port
  												...
  						elif config["class_embed_type"] == "timestep" or config["class_embed_type"] == "projection":
  												UpperCAmelCase_=     unet_state_dict['''label_emb.0.0.weight''']
  												UpperCAmelCase_=     unet_state_dict['''label_emb.0.0.bias''']
  												UpperCAmelCase_=     unet_state_dict['''label_emb.0.2.weight''']
  												UpperCAmelCase_=     unet_state_dict['''label_emb.0.2.bias''']
  						else:
  												raise NotImplementedError(F"""Not implemented `class_embed_type`: {config["class_embed_type"]}"""       )
  
  						UpperCAmelCase_=     unet_state_dict['''input_blocks.0.0.weight''']
  						UpperCAmelCase_=     unet_state_dict['''input_blocks.0.0.bias''']
  
  						UpperCAmelCase_=     [v for v in unet_state_dict if v.startswith("""input_blocks.0.1"""       )]
  						UpperCAmelCase_=     renew_attention_paths(lowercase_       )
  						UpperCAmelCase_=     {'''old''': '''input_blocks.0.1''', '''new''': '''transformer_in'''}
  						assign_to_checkpoint(lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  						UpperCAmelCase_=     unet_state_dict['''out.0.weight''']
  						UpperCAmelCase_=     unet_state_dict['''out.0.bias''']
  						UpperCAmelCase_=     unet_state_dict['''out.2.weight''']
  						UpperCAmelCase_=     unet_state_dict['''out.2.bias''']
  
  						# Retrieves the keys for the input blocks only
  						UpperCAmelCase_=     len({""".""".join(layer.split("""."""       )[:2]       ) for layer in unet_state_dict if """input_blocks""" in layer}       )
  						UpperCAmelCase_=     {
  						    layer_id: [key for key in unet_state_dict if F"""input_blocks.{layer_id}""" in key]
  						    for layer_id in range(lowercase_       )
  						}
  
  						# Retrieves the keys for the middle blocks only
  						UpperCAmelCase_=     len({""".""".join(layer.split("""."""       )[:2]       ) for layer in unet_state_dict if """middle_block""" in layer}       )
  						UpperCAmelCase_=     {
  						    layer_id: [key for key in unet_state_dict if F"""middle_block.{layer_id}""" in key]
  						    for layer_id in range(lowercase_       )
  						}
  
  						# Retrieves the keys for the output blocks only
  						UpperCAmelCase_=     len({""".""".join(layer.split("""."""       )[:2]       ) for layer in unet_state_dict if """output_blocks""" in layer}       )
  						UpperCAmelCase_=     {
  						    layer_id: [key for key in unet_state_dict if F"""output_blocks.{layer_id}""" in key]
  						    for layer_id in range(lowercase_       )
  						}
  
  						for i in range(1    ,lowercase_       ):
  												UpperCAmelCase_=     (i - 1) // (config['''layers_per_block'''] + 1)
  												UpperCAmelCase_=     (i - 1) % (config['''layers_per_block'''] + 1)
  
  												UpperCAmelCase_=     [
  												    key for key in input_blocks[i] if F"""input_blocks.{i}.0""" in key and F"""input_blocks.{i}.0.op""" not in key
  												]
  												UpperCAmelCase_=     [key for key in input_blocks[i] if F"""input_blocks.{i}.1""" in key]
  												UpperCAmelCase_=     [key for key in input_blocks[i] if F"""input_blocks.{i}.2""" in key]
  
  												if F"""input_blocks.{i}.op.weight""" in unet_state_dict:
  																		UpperCAmelCase_=     unet_state_dict.pop(
  																		    F"""input_blocks.{i}.op.weight"""       )
  																		UpperCAmelCase_=     unet_state_dict.pop(
  																		    F"""input_blocks.{i}.op.bias"""       )
  
  												UpperCAmelCase_=     renew_resnet_paths(lowercase_       )
  												UpperCAmelCase_=     {'''old''': F"""input_blocks.{i}.0""", '''new''': F"""down_blocks.{block_id}.resnets.{layer_in_block_id}"""}
  												assign_to_checkpoint(
  												    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  												UpperCAmelCase_=     [key for key in resnets if '''temopral_conv''' in key]
  												UpperCAmelCase_=     renew_temp_conv_paths(lowercase_       )
  												UpperCAmelCase_=     {
  												    '''old''': F"""input_blocks.{i}.0.temopral_conv""",
  												    '''new''': F"""down_blocks.{block_id}.temp_convs.{layer_in_block_id}""",
  												}
  												assign_to_checkpoint(
  												    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  												if len(lowercase_       ):
  																		UpperCAmelCase_=     renew_attention_paths(lowercase_       )
  																		UpperCAmelCase_=     {'''old''': F"""input_blocks.{i}.1""", '''new''': F"""down_blocks.{block_id}.attentions.{layer_in_block_id}"""}
  																		assign_to_checkpoint(
  																		    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  												if len(lowercase_       ):
  																		UpperCAmelCase_=     renew_attention_paths(lowercase_       )
  																		UpperCAmelCase_=     {
  																		    '''old''': F"""input_blocks.{i}.2""",
  																		    '''new''': F"""down_blocks.{block_id}.temp_attentions.{layer_in_block_id}""",
  																		}
  																		assign_to_checkpoint(
  																		    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  						UpperCAmelCase_=     middle_blocks[0]
  						UpperCAmelCase_=     [key for key in resnet_a if '''temopral_conv''' in key]
  						UpperCAmelCase_=     middle_blocks[1]
  						UpperCAmelCase_=     middle_blocks[2]
  						UpperCAmelCase_=     middle_blocks[3]
  						UpperCAmelCase_=     [key for key in resnet_a if '''temopral_conv''' in key]
  
  						UpperCAmelCase_=     renew_resnet_paths(lowercase_       )
  						UpperCAmelCase_=     {'''old''': '''middle_block.0''', '''new''': '''mid_block.resnets.0'''}
  						assign_to_checkpoint(
  						    lowercase_    ,lowercase_    ,lowercase_    ,config=lowercase_    ,additional_replacements=[meta_path]       )
  
  						UpperCAmelCase_=     renew_temp_conv_paths(lowercase_       )
  						UpperCAmelCase_=     {'''old''': '''middle_block.0.temopral_conv''', '''new''': '''mid_block.temp_convs.0'''}
  						assign_to_checkpoint(
  						    lowercase_    ,lowercase_    ,lowercase_    ,config=lowercase_    ,additional_replacements=[meta_path]       )
  
  						UpperCAmelCase_=     renew_resnet_paths(lowercase_       )
  						UpperCAmelCase_=     {'''old''': '''middle_block.3''', '''new''': '''mid_block.resnets.1'''}
  						assign_to_checkpoint(
  						    lowercase_    ,lowercase_    ,lowercase_    ,config=lowercase_    ,additional_replacements=[meta_path]       )
  
  						UpperCAmelCase_=     renew_temp_conv_paths(lowercase_       )
  						UpperCAmelCase_=     {'''old''': '''middle_block.3.temopral_conv''', '''new''': '''mid_block.temp_convs.1'''}
  						assign_to_checkpoint(
  						    lowercase_    ,lowercase_    ,lowercase_    ,config=lowercase_    ,additional_replacements=[meta_path]       )
  
  						UpperCAmelCase_=     renew_attention_paths(lowercase_       )
  						UpperCAmelCase_=     {'''old''': '''middle_block.1''', '''new''': '''mid_block.attentions.0'''}
  						assign_to_checkpoint(
  						    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  						UpperCAmelCase_=     renew_attention_paths(lowercase_       )
  						UpperCAmelCase_=     {'''old''': '''middle_block.2''', '''new''': '''mid_block.temp_attentions.0'''}
  						assign_to_checkpoint(
  						    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  						for i in range(lowercase_       ):
  												UpperCAmelCase_=     i // (config['''layers_per_block'''] + 1)
  												UpperCAmelCase_=     i % (config['''layers_per_block'''] + 1)
  												UpperCAmelCase_=     [shave_segments(lowercase_    ,2       ) for name in output_blocks[i]]
  												UpperCAmelCase_=     {}
  
  												for layer in output_block_layers:
  																		UpperCAmelCase_=     layer.split("""."""       )[0], shave_segments(lowercase_    ,1       )
  																		if layer_id in output_block_list:
  																								output_block_list[layer_id].append(lowercase_       )
  																		else:
  																								UpperCAmelCase_=     [layer_name]
  
  												if len(lowercase_       ) > 1:
  																		UpperCAmelCase_=     [key for key in output_blocks[i] if F"""output_blocks.{i}.0""" in key]
  																		UpperCAmelCase_=     [key for key in output_blocks[i] if F"""output_blocks.{i}.1""" in key]
  																		UpperCAmelCase_=     [key for key in output_blocks[i] if F"""output_blocks.{i}.2""" in key]
  
  																		UpperCAmelCase_=     renew_resnet_paths(lowercase_       )
  																		UpperCAmelCase_=     renew_resnet_paths(lowercase_       )
  
  																		UpperCAmelCase_=     {'''old''': F"""output_blocks.{i}.0""", '''new''': F"""up_blocks.{block_id}.resnets.{layer_in_block_id}"""}
  																		assign_to_checkpoint(
  																		    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  																		UpperCAmelCase_=     [key for key in resnets if '''temopral_conv''' in key]
  																		UpperCAmelCase_=     renew_temp_conv_paths(lowercase_       )
  																		UpperCAmelCase_=     {
  																		    '''old''': F"""output_blocks.{i}.0.temopral_conv""",
  																		    '''new''': F"""up_blocks.{block_id}.temp_convs.{layer_in_block_id}""",
  																		}
  																		assign_to_checkpoint(
  																		    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  																		UpperCAmelCase_=     {k: sorted(lowercase_       ) for k, v in output_block_list.items()}
  																		if ["conv.bias", "conv.weight"] in output_block_list.values():
  																								UpperCAmelCase_=     list(output_block_list.values()       ).index(["""conv.bias""", """conv.weight"""]       )
  																								UpperCAmelCase_=     unet_state_dict[
  																								    F"""output_blocks.{i}.{index}.conv.weight"""
  																								]
  																								UpperCAmelCase_=     unet_state_dict[
  																								    F"""output_blocks.{i}.{index}.conv.bias"""
  																								]
  
  																								# Clear attentions as they have been attributed above.
  																								if len(lowercase_       ) == 2:
  																														UpperCAmelCase_=     []
  
  																		if len(lowercase_       ):
  																								UpperCAmelCase_=     renew_attention_paths(lowercase_       )
  																								UpperCAmelCase_=     {
  																								    '''old''': F"""output_blocks.{i}.1""",
  																								    '''new''': F"""up_blocks.{block_id}.attentions.{layer_in_block_id}""",
  																								}
  																								assign_to_checkpoint(
  																								    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  
  																		if len(lowercase_       ):
  																								UpperCAmelCase_=     renew_attention_paths(lowercase_       )
  																								UpperCAmelCase_=     {
  																								    '''old''': F"""output_blocks.{i}.2""",
  																								    '''new''': F"""up_blocks.{block_id}.temp_attentions.{layer_in_block_id}""",
  																								}
  																								assign_to_checkpoint(
  																								    lowercase_    ,lowercase_    ,lowercase_    ,additional_replacements=[meta_path]    ,config=lowercase_       )
  												else:
  																		UpperCAmelCase_=     renew_resnet_paths(lowercase_    ,n_shave_prefix_segments=1       )
  																		for path in resnet_0_paths:
  																								UpperCAmelCase_=     '''.'''.join(["""output_blocks""", str(lowercase_       ), path["""old"""]]       )
  																								UpperCAmelCase_=     '''.'''.join(["""up_blocks""", str(lowercase_       ), """resnets""", str(lowercase_       ), path["""new"""]]       )
  																								UpperCAmelCase_=     unet_state_dict[old_path]
  
  																		UpperCAmelCase_=     [l for l in output_block_layers if '''temopral_conv''' in l]
  																		for path in temopral_conv_paths:
  																								UpperCAmelCase_=     path.split("""temopral_conv."""       )[-1]
  																								UpperCAmelCase_=     '''.'''.join(["""output_blocks""", str(lowercase_       ), str(lowercase_       ), """temopral_conv""", pruned_path]       )
  																								UpperCAmelCase_=     '''.'''.join(["""up_blocks""", str(lowercase_       ), """temp_convs""", str(lowercase_       ), pruned_path]       )
  																								UpperCAmelCase_=     unet_state_dict[old_path]
  
  						return new_checkpoint
  
  
  if __name__ == "__main__":
  	__A       					=		argparse.ArgumentParser()
  
  	parser.add_argument(
  	    '''--checkpoint_path''', default=None, type=str, required=True, help='''Path to the checkpoint to convert.'''
  	)
  	parser.add_argument('''--dump_path''', default=None, type=str, required=True, help='''Path to the output model.''')
  	__A       					=		parser.parse_args()
  
  	__A       					=		torch.load(args.checkpoint_path, map_location='''cpu''')
  	__A       					=		UNetaDConditionModel()
  
  	__A       					=		convert_ldm_unet_checkpoint(unet_checkpoint, unet.config)
  
  	__A       					=		set(unet.state_dict().keys()) - set(converted_ckpt.keys())
  	__A       					=		set(converted_ckpt.keys()) - set(unet.state_dict().keys())
  
  	assert len(diff_a) == len(diff_a) == 0, "Converted weights don't match"
  
  	# load state_dict
  	unet.load_state_dict(converted_ckpt)
  
  	unet.save_pretrained(args.dump_path)
  
  	# -- finish converting the unet --
  
  
  
  
style_context: 
  
  
  
  from __future__ import annotations
  
  import os
  
  
  
  
  
  
  class 	lowercase		:
  
  
  
  
  
  
  	"""simple docstring"""
  
  
  	a__   :      List[str]	     =							(
  	    "High card",
  	    "One pair",
  	    "Two pairs",
  	    "Three of a kind",
  	    "Straight",
  	    "Flush",
  	    "Full house",
  	    "Four of a kind",
  	    "Straight flush",
  	    "Royal flush",
  	)
  
  	a__   :      Optional[Any]	     =							(
  	    "",  # placeholder as tuples are zero-indexed
  	    "One",
  	    "Two",
  	    "Three",
  	    "Four",
  	    "Five",
  	    "Six",
  	    "Seven",
  	    "Eight",
  	    "Nine",
  	    "Ten",
  	    "Jack",
  	    "Queen",
  	    "King",
  	    "Ace",
  	)
  
  
  
  
  	def __init__(			self			:		Tuple		,						__UpperCAmelCase			:		str  )    ->				None:
  							if not isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  													UpperCAmelCase_=     F"""Hand should be of type 'str': {hand!r}"""
  													raise TypeError(__UpperCAmelCase  )
  							# split removes duplicate whitespaces so no need of strip
  							if len(hand.split(""" """  )  ) != 5:
  													UpperCAmelCase_=     F"""Hand should contain only 5 cards: {hand!r}"""
  													raise ValueError(__UpperCAmelCase  )
  							UpperCAmelCase_=     hand
  							UpperCAmelCase_=     0
  							UpperCAmelCase_=     0
  							UpperCAmelCase_,     UpperCAmelCase_=     self._internal_state()
  							UpperCAmelCase_=     self._get_hand_type()
  							UpperCAmelCase_=     self._card_values[0]
  
  
  
  
  	@property
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		int  )    ->				Union[str, Any]:
  							return self._hand
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		List[Any]		,						__UpperCAmelCase			:		PokerHand  )    ->				str:
  							# Breaking the tie works on the following order of precedence:
  							# 1. First pair (default 0)
  							# 2. Second pair (default 0)
  							# 3. Compare all cards in reverse order because they are sorted.
  
  							# First pair and second pair will only be a non-zero value if the card
  							# type is either from the following:
  							# 21: Four of a kind
  							# 20: Full house
  							# 17: Three of a kind
  							# 16: Two pairs
  							# 15: One pair
  							if self._hand_type > other._hand_type:
  													return "Win"
  							elif self._hand_type < other._hand_type:
  													return "Loss"
  							elif self._first_pair == other._first_pair:
  													if self._second_pair == other._second_pair:
  																			return self._compare_cards(__UpperCAmelCase  )
  													else:
  																			return "Win" if self._second_pair > other._second_pair else "Loss"
  							return "Win" if self._first_pair > other._first_pair else "Loss"
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Optional[int]  )    ->				str:
  							UpperCAmelCase_=     PokerHand._HAND_NAME[self._hand_type - 14]
  							UpperCAmelCase_=     PokerHand._CARD_NAME[self._high_card]
  							UpperCAmelCase_=     PokerHand._CARD_NAME[self._first_pair]
  							UpperCAmelCase_=     PokerHand._CARD_NAME[self._second_pair]
  							if self._hand_type in [22, 19, 18]:
  													return name + F""", {high}-high"""
  							elif self._hand_type in [21, 17, 15]:
  													return name + F""", {paira}s"""
  							elif self._hand_type in [20, 16]:
  													UpperCAmelCase_=     """over""" if self._hand_type == 20 else """and"""
  													return name + F""", {paira}s {join} {paira}s"""
  							elif self._hand_type == 23:
  													return name
  							else:
  													return name + F""", {high}"""
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Optional[int]		,						__UpperCAmelCase			:		PokerHand  )    ->				str:
  							# Enumerate gives us the index as well as the element of a list
  							for index, card_value in enumerate(self._card_values  ):
  													if card_value != other._card_values[index]:
  																			return "Win" if card_value > other._card_values[index] else "Loss"
  							return "Tie"
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		List[Any]  )    ->				int:
  							# Number representing the type of hand internally:
  							# 23: Royal flush
  							# 22: Straight flush
  							# 21: Four of a kind
  							# 20: Full house
  							# 19: Flush
  							# 18: Straight
  							# 17: Three of a kind
  							# 16: Two pairs
  							# 15: One pair
  							# 14: High card
  							if self._is_flush():
  													if self._is_five_high_straight() or self._is_straight():
  																			return 23 if sum(self._card_values  ) == 60 else 22
  													return 19
  							elif self._is_five_high_straight() or self._is_straight():
  													return 18
  							return 14 + self._is_same_kind()
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Dict  )    ->				bool:
  							return len(self._card_suit  ) == 1
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Optional[Any]  )    ->				bool:
  							# If a card is a five high straight (low ace) change the location of
  							# ace from the start of the list to the end. Check whether the first
  							# element is ace or not. (Don't want to change again)
  							# Five high straight (low ace): AH 2H 3S 4C 5D
  							# Why use sorted here? One call to this function will mutate the list to
  							# [5, 4, 3, 2, 14] and so for subsequent calls (which will be rare) we
  							# need to compare the sorted version.
  							# Refer test_multiple_calls_five_high_straight in test_poker_hand.py
  							if sorted(self._card_values  ) == [2, 3, 4, 5, 14]:
  													if self._card_values[0] == 14:
  																			# Remember, our list is sorted in reverse order
  																			UpperCAmelCase_=     self._card_values.pop(0  )
  																			self._card_values.append(__UpperCAmelCase  )
  													return True
  							return False
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Tuple  )    ->				bool:
  							for i in range(4  ):
  													if self._card_values[i] - self._card_values[i + 1] != 1:
  																			return False
  							return True
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		Any  )    ->				int:
  							# Kind Values for internal use:
  							# 7: Four of a kind
  							# 6: Full house
  							# 3: Three of a kind
  							# 2: Two pairs
  							# 1: One pair
  							# 0: False
  							UpperCAmelCase_=     UpperCAmelCase_=     UpperCAmelCase_=     0
  							for i in range(4  ):
  													# Compare two cards at a time, if they are same increase 'kind',
  													# add the value of the card to val1, if it is repeating again we
  													# will add 2 to 'kind' as there are now 3 cards with same value.
  													# If we get card of different value than val1, we will do the same
  													# thing with val2
  													if self._card_values[i] == self._card_values[i + 1]:
  																			if not vala:
  																									UpperCAmelCase_=     self._card_values[i]
  																									kind += 1
  																			elif vala == self._card_values[i]:
  																									kind += 2
  																			elif not vala:
  																									UpperCAmelCase_=     self._card_values[i]
  																									kind += 1
  																			elif vala == self._card_values[i]:
  																									kind += 2
          # For consistency in hand type (look at note in _get_hand_type function)
  							UpperCAmelCase_=     kind + 2 if kind in [4, 5] else kind
  							# first meaning first pair to compare in 'compare_with'
  							UpperCAmelCase_=     max(__UpperCAmelCase		,						__UpperCAmelCase  )
  							UpperCAmelCase_=     min(__UpperCAmelCase		,						__UpperCAmelCase  )
  							# If it's full house (three count pair + two count pair), make sure
  							# first pair is three count and if not then switch them both.
  							if kind == 6 and self._card_values.count(__UpperCAmelCase  ) != 3:
  													UpperCAmelCase_,     UpperCAmelCase_=     second, first
  							UpperCAmelCase_=     first
  							UpperCAmelCase_=     second
  							return kind
  
  
  
  
  	def 						_SCREAMING_SNAKE_CASE	(			self			:		int  )    ->				tuple[list[int], set[str]]:
  							# Internal representation of hand as a list of card values and
  							# a set of card suit
  							UpperCAmelCase_=     {"T": "10", "J": "11", "Q": "12", "K": "13", "A": "14"}
  							UpperCAmelCase_=     self._hand.translate(str.maketrans(__UpperCAmelCase  )  ).split()
  							UpperCAmelCase_=     [int(card[:-1]  ) for card in new_hand]
  							UpperCAmelCase_=     {card[-1] for card in new_hand}
  							return sorted(__UpperCAmelCase		,						reverse=__UpperCAmelCase  ), card_suit
  
  
  
  
  	def __repr__(			self			:		Dict  )    ->				Dict:
  							return F"""{self.__class__}(\"{self._hand}\")"""
  
  
  
  
  	def __str__(			self			:		Tuple  )    ->				List[Any]:
  							return self._hand
  
  
  
  
  	def __eq__(			self			:		List[Any]		,						__UpperCAmelCase			:		Optional[Any]  )    ->				int:
  							if isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  													return self.compare_with(__UpperCAmelCase  ) == "Tie"
  							return NotImplemented
  
  
  
  
  	def __lt__(			self			:		Union[str, Any]		,						__UpperCAmelCase			:		Optional[int]  )    ->				Union[str, Any]:
  							if isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  													return self.compare_with(__UpperCAmelCase  ) == "Loss"
  							return NotImplemented
  
  
  
  
  	def __le__(			self			:		List[str]		,						__UpperCAmelCase			:		Optional[int]  )    ->				Optional[Any]:
  							if isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  													return self < other or self == other
  							return NotImplemented
  
  
  
  
  	def __gt__(			self			:		List[str]		,						__UpperCAmelCase			:		List[str]  )    ->				int:
  							if isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  													return not self < other and self != other
  							return NotImplemented
  
  
  
  
  	def __ge__(			self			:		Union[str, Any]		,						__UpperCAmelCase			:		Tuple  )    ->				Any:
  							if isinstance(__UpperCAmelCase		,						__UpperCAmelCase  ):
  													return not self < other
  							return NotImplemented
  
  
  
  
  	def __hash__(			self			:		Any  )    ->				int:
  							return object.__hash__(self  )
  
  
  
  def  __a  (					)   ->				int:
  
  
  
  
  
  
  						'''simple docstring'''
  
  
  
  						UpperCAmelCase_=     0
  						UpperCAmelCase_=     os.path.abspath(os.path.dirname(lowerCAmelCase_       )       )
  						UpperCAmelCase_=     os.path.join(lowerCAmelCase_    ,"""poker_hands.txt"""       )
  						with open(lowerCAmelCase_       ) as file_hand:
  												for line in file_hand:
  																		UpperCAmelCase_=     line[:14].strip()
  																		UpperCAmelCase_=     line[15:].strip()
  																		UpperCAmelCase_,     UpperCAmelCase_=     PokerHand(lowerCAmelCase_       ), PokerHand(lowerCAmelCase_       )
  																		UpperCAmelCase_=     player.compare_with(lowerCAmelCase_       )
  																		if output == "Win":
  																								answer += 1
  						return answer
  
  
  if __name__ == "__main__":
  	solution()
  
  
  
  
  