



import json
import os
from typing import TYPE_CHECKING, List, Optional, Tuple

import regex as re

from ...tokenization_utils import AddedToken, PreTrainedTokenizer
from ...utils import logging


if TYPE_CHECKING:
    from transformers.pipelines.conversational import Conversation

UpperCamelCase__		   =    logging.get_logger(__name__)

UpperCamelCase__		   =    {"""vocab_file""": """vocab.json""", """merges_file""": """merges.txt"""}

UpperCamelCase__		   =    {
    """vocab_file""": {
        """microsoft/deberta-base""": """https://huggingface.co/microsoft/deberta-base/resolve/main/vocab.json""",
        """microsoft/deberta-large""": """https://huggingface.co/microsoft/deberta-large/resolve/main/vocab.json""",
        """microsoft/deberta-xlarge""": """https://huggingface.co/microsoft/deberta-xlarge/resolve/main/vocab.json""",
        """microsoft/deberta-base-mnli""": """https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/vocab.json""",
        """microsoft/deberta-large-mnli""": """https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/vocab.json""",
        """microsoft/deberta-xlarge-mnli""": (
            """https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/vocab.json"""
        ),
    },
    """merges_file""": {
        """microsoft/deberta-base""": """https://huggingface.co/microsoft/deberta-base/resolve/main/merges.txt""",
        """microsoft/deberta-large""": """https://huggingface.co/microsoft/deberta-large/resolve/main/merges.txt""",
        """microsoft/deberta-xlarge""": """https://huggingface.co/microsoft/deberta-xlarge/resolve/main/merges.txt""",
        """microsoft/deberta-base-mnli""": """https://huggingface.co/microsoft/deberta-base-mnli/resolve/main/merges.txt""",
        """microsoft/deberta-large-mnli""": """https://huggingface.co/microsoft/deberta-large-mnli/resolve/main/merges.txt""",
        """microsoft/deberta-xlarge-mnli""": (
            """https://huggingface.co/microsoft/deberta-xlarge-mnli/resolve/main/merges.txt"""
        ),
    },
}

UpperCamelCase__		   =    {
    """microsoft/deberta-base""": 512,
    """microsoft/deberta-large""": 512,
    """microsoft/deberta-xlarge""": 512,
    """microsoft/deberta-base-mnli""": 512,
    """microsoft/deberta-large-mnli""": 512,
    """microsoft/deberta-xlarge-mnli""": 512,
}

UpperCamelCase__		   =    {
    """microsoft/deberta-base""": {"""do_lower_case""": False},
    """microsoft/deberta-large""": {"""do_lower_case""": False},
}







def 	lowerCamelCase__			(   ):


       """simple docstring"""




       __snake_case					  =       (
           list(range(ord("""!"""		)  ,ord("""~"""		) + 1		)		) + list(range(ord("""¡"""		)  ,ord("""¬"""		) + 1		)		) + list(range(ord("""®"""		)  ,ord("""ÿ"""		) + 1		)		)
       )
       __snake_case					  =       bs[:]
       __snake_case					  =       0
       for b in range(2**8		):
              if b not in bs:
                     bs.append(__A		)
                     cs.append(2**8 + n		)
                     n += 1
       __snake_case					  =       [chr(__A		) for n in cs]
       return dict(zip(__A  ,__A		)		)







def 	lowerCamelCase__			(   __A						:Union[str, Any]		):


       """simple docstring"""




       __snake_case					  =       set()
       __snake_case					  =       word[0]
       for char in word[1:]:
              pairs.add((prev_char, char)		)
              __snake_case					  =       char
       return pairs




class 						__snake_case						(							UpperCamelCase__     ):
       """simple docstring"""







       __SCREAMING_SNAKE_CASE													=       VOCAB_FILES_NAMES
       __SCREAMING_SNAKE_CASE													=       PRETRAINED_VOCAB_FILES_MAP
       __SCREAMING_SNAKE_CASE													=       PRETRAINED_POSITIONAL_EMBEDDINGS_SIZES
       __SCREAMING_SNAKE_CASE													=       ["""input_ids""", """attention_mask""", """token_type_ids"""]


       def __init__(		self			,   _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase="replace"			,   _UpperCamelCase="[CLS]"			,   _UpperCamelCase="[SEP]"			,   _UpperCamelCase="[SEP]"			,   _UpperCamelCase="[CLS]"			,   _UpperCamelCase="[UNK]"			,   _UpperCamelCase="[PAD]"			,   _UpperCamelCase="[MASK]"			,   _UpperCamelCase=False			,   _UpperCamelCase=False			,   **_UpperCamelCase			,   )			->       Any:






              """simple docstring"""


              __snake_case					  =       AddedToken(lowerCAmelCase__			,   lstrip=lowerCAmelCase__			,   rstrip=lowerCAmelCase__      ) if isinstance(lowerCAmelCase__			,   lowerCAmelCase__      ) else bos_token
              __snake_case					  =       AddedToken(lowerCAmelCase__			,   lstrip=lowerCAmelCase__			,   rstrip=lowerCAmelCase__      ) if isinstance(lowerCAmelCase__			,   lowerCAmelCase__      ) else eos_token
              __snake_case					  =       AddedToken(lowerCAmelCase__			,   lstrip=lowerCAmelCase__			,   rstrip=lowerCAmelCase__      ) if isinstance(lowerCAmelCase__			,   lowerCAmelCase__      ) else sep_token
              __snake_case					  =       AddedToken(lowerCAmelCase__			,   lstrip=lowerCAmelCase__			,   rstrip=lowerCAmelCase__      ) if isinstance(lowerCAmelCase__			,   lowerCAmelCase__      ) else cls_token
              __snake_case					  =       AddedToken(lowerCAmelCase__			,   lstrip=lowerCAmelCase__			,   rstrip=lowerCAmelCase__      ) if isinstance(lowerCAmelCase__			,   lowerCAmelCase__      ) else unk_token
              __snake_case					  =       AddedToken(lowerCAmelCase__			,   lstrip=lowerCAmelCase__			,   rstrip=lowerCAmelCase__      ) if isinstance(lowerCAmelCase__			,   lowerCAmelCase__      ) else pad_token

              # Mask token behave like a normal word, i.e. include the space before it
              __snake_case					  =       AddedToken(lowerCAmelCase__			,   lstrip=lowerCAmelCase__			,   rstrip=lowerCAmelCase__      ) if isinstance(lowerCAmelCase__			,   lowerCAmelCase__      ) else mask_token

              super().__init__(
                  errors=lowerCAmelCase__			,   bos_token=lowerCAmelCase__			,   eos_token=lowerCAmelCase__			,   unk_token=lowerCAmelCase__			,   sep_token=lowerCAmelCase__			,   cls_token=lowerCAmelCase__			,   pad_token=lowerCAmelCase__			,   mask_token=lowerCAmelCase__			,   add_prefix_space=lowerCAmelCase__			,   add_bos_token=lowerCAmelCase__			,   **lowerCAmelCase__			,   )
              __snake_case					  =       add_bos_token

              with open(lowerCAmelCase__			,   encoding="""utf-8"""      ) as vocab_handle:
                     __snake_case					  =       json.load(lowerCAmelCase__      )
              __snake_case					  =       {v: k for k, v in self.encoder.items()}
              __snake_case					  =       errors  # how to handle errors in decoding
              __snake_case					  =       bytes_to_unicode()
              __snake_case					  =       {v: k for k, v in self.byte_encoder.items()}
              with open(lowerCAmelCase__			,   encoding="""utf-8"""      ) as merges_handle:
                     __snake_case					  =       merges_handle.read().split("""\n"""      )[1:-1]
              __snake_case					  =       [tuple(merge.split()      ) for merge in bpe_merges]
              __snake_case					  =       dict(zip(lowerCAmelCase__			,   range(len(lowerCAmelCase__      )      )      )      )
              __snake_case					  =       {}
              __snake_case					  =       add_prefix_space

              # Should have added re.IGNORECASE so BPE merges can happen for capitalized versions of contractions
              __snake_case					  =       re.compile(r"""'s|'t|'re|'ve|'m|'ll|'d| ?\p{L}+| ?\p{N}+| ?[^\s\p{L}\p{N}]+|\s+(?!\S)|\s+"""      )


       @property
       # Copied from transformers.models.gpt2.tokenization_gpt2.GPT2Tokenizer.vocab_size
       def  a		(		self      )			->       Any:






              """simple docstring"""


              return len(self.encoder      )


       def  a		(		self      )			->       Optional[int]:






              """simple docstring"""


              return dict(self.encoder			,   **self.added_tokens_encoder      )


       def  a		(		self			,   _UpperCamelCase      )			->       List[str]:






              """simple docstring"""


              if token in self.cache:
                     return self.cache[token]
              __snake_case					  =       tuple(lowerCAmelCase__      )
              __snake_case					  =       get_pairs(lowerCAmelCase__      )

              if not pairs:
                     return token

              while True:
                     __snake_case					  =       min(lowerCAmelCase__			,   key=lambda _UpperCamelCase      : self.bpe_ranks.get(lowerCAmelCase__			,   float("""inf"""      )      )      )
                     if bigram not in self.bpe_ranks:
                            break
                     __snake_case					  =       bigram
                     __snake_case					  =       []
                     __snake_case					  =       0
                     while i < len(lowerCAmelCase__      ):
                            try:
                                   __snake_case					  =       word.index(lowerCAmelCase__			,   lowerCAmelCase__      )
                            except ValueError:
                                   new_word.extend(word[i:]      )
                                   break
                            else:
                                   new_word.extend(word[i:j]      )
                                   __snake_case					  =       j

                            if word[i] == first and i < len(lowerCAmelCase__      ) - 1 and word[i + 1] == second:
                                   new_word.append(first + second      )
                                   i += 2
                            else:
                                   new_word.append(word[i]      )
                                   i += 1
                     __snake_case					  =       tuple(lowerCAmelCase__      )
                     __snake_case					  =       new_word
                     if len(lowerCAmelCase__      ) == 1:
                            break
                     else:
                            __snake_case					  =       get_pairs(lowerCAmelCase__      )
              __snake_case					  =       " ".join(lowerCAmelCase__      )
              __snake_case					  =       word
              return word


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase = None      )			->       List[int]:






              """simple docstring"""


              if token_ids_a is None:
                     return [self.cls_token_id] + token_ids_a + [self.sep_token_id]
              __snake_case					  =       [self.cls_token_id]
              __snake_case					  =       [self.sep_token_id]
              return cls + token_ids_a + sep + token_ids_a + sep


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase = None			,   _UpperCamelCase = False      )			->       List[int]:






              """simple docstring"""


              if already_has_special_tokens:
                     return super().get_special_tokens_mask(
                         token_ids_a=lowerCAmelCase__			,   token_ids_a=lowerCAmelCase__			,   already_has_special_tokens=lowerCAmelCase__      )

              if token_ids_a is None:
                     return [1] + ([0] * len(lowerCAmelCase__      )) + [1]
              return [1] + ([0] * len(lowerCAmelCase__      )) + [1] + ([0] * len(lowerCAmelCase__      )) + [1]


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase = None      )			->       List[int]:






              """simple docstring"""


              __snake_case					  =       [self.sep_token_id]
              __snake_case					  =       [self.cls_token_id]

              if token_ids_a is None:
                     return len(cls + token_ids_a + sep      ) * [0]
              return len(cls + token_ids_a + sep      ) * [0] + len(token_ids_a + sep      ) * [1]


       def  a		(		self			,   _UpperCamelCase      )			->       Optional[int]:






              """simple docstring"""


              __snake_case					  =       []
              for token in re.findall(self.pat			,   lowerCAmelCase__      ):
                     __snake_case					  =       "".join(
                         self.byte_encoder[b] for b in token.encode("""utf-8"""      )      )  # Maps all our bytes to unicode strings, avoiding control tokens of the BPE (spaces in our case)
                     bpe_tokens.extend(bpe_token for bpe_token in self.bpe(lowerCAmelCase__      ).split(""" """      )      )
              return bpe_tokens


       def  a		(		self			,   _UpperCamelCase      )			->       int:






              """simple docstring"""


              return self.encoder.get(lowerCAmelCase__			,   self.encoder.get(self.unk_token      )      )


       def  a		(		self			,   _UpperCamelCase      )			->       int:






              """simple docstring"""


              return self.decoder.get(lowerCAmelCase__      )


       def  a		(		self			,   _UpperCamelCase      )			->       str:






              """simple docstring"""


              __snake_case					  =       "".join(lowerCAmelCase__      )
              __snake_case					  =       bytearray([self.byte_decoder[c] for c in text]      ).decode("""utf-8"""			,   errors=self.errors      )
              return text


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase = None      )			->       Tuple[str]:






              """simple docstring"""


              if not os.path.isdir(lowerCAmelCase__      ):
                     logger.error(F'Vocabulary path ({save_directory}) should be a directory'      )
                     return
              __snake_case					  =       os.path.join(
                  lowerCAmelCase__			,   (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""vocab_file"""]      )
              __snake_case					  =       os.path.join(
                  lowerCAmelCase__			,   (filename_prefix + """-""" if filename_prefix else """""") + VOCAB_FILES_NAMES["""merges_file"""]      )

              with open(lowerCAmelCase__			,   """w"""			,   encoding="""utf-8"""      ) as f:
                     f.write(json.dumps(self.encoder			,   indent=2			,   sort_keys=lowerCAmelCase__			,   ensure_ascii=lowerCAmelCase__      ) + """\n"""      )

              __snake_case					  =       0
              with open(lowerCAmelCase__			,   """w"""			,   encoding="""utf-8"""      ) as writer:
                     writer.write("""#version: 0.2\n"""      )
                     for bpe_tokens, token_index in sorted(self.bpe_ranks.items()			,   key=lambda _UpperCamelCase      : kv[1]      ):
                            if index != token_index:
                                   logger.warning(
                                       F'Saving vocabulary to {merge_file}: BPE merge indices are not consecutive.'
                                       """ Please check that the tokenizer is not corrupted!"""      )
                                   __snake_case					  =       token_index
                            writer.write(""" """.join(lowerCAmelCase__      ) + """\n"""      )
                            index += 1

              return vocab_file, merge_file


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase=False			,   **_UpperCamelCase      )			->       Dict:






              """simple docstring"""


              __snake_case					  =       kwargs.pop("""add_prefix_space"""			,   self.add_prefix_space      )
              if (is_split_into_words or add_prefix_space) and (len(lowerCAmelCase__      ) > 0 and not text[0].isspace()):
                     __snake_case					  =       " " + text
              return (text, kwargs)






       def  a		(		self			,   _UpperCamelCase      )			->       List[int]:






              """simple docstring"""


              __snake_case					  =       []
              for is_user, text in conversation.iter_texts():
                     input_ids.extend(self.encode(lowerCAmelCase__			,   add_special_tokens=lowerCAmelCase__      ) + [self.eos_token_id]      )
              if len(lowerCAmelCase__      ) > self.model_max_length:
                     __snake_case					  =       input_ids[-self.model_max_length :]
              return input_ids




import colorsys
import io

import cva
import matplotlib as mpl
import matplotlib.colors as mplc
import matplotlib.figure as mplfigure
import numpy as np
import torch
from matplotlib.backends.backend_agg import FigureCanvasAgg

from utils import img_tensorize


UpperCamelCase__		   =    1000

class 						__snake_case						:
       """simple docstring"""







       def __init__(		self			,   _UpperCamelCase			,   _UpperCamelCase=1.2			,   _UpperCamelCase="g"			,   _UpperCamelCase=0.5			,   _UpperCamelCase="-"			,   _UpperCamelCase="test_out.jpg"			,   _UpperCamelCase=True			,   _UpperCamelCase=False			,   _UpperCamelCase=None			,   _UpperCamelCase=None			,   _UpperCamelCase=0.7			,   )			->       Union[str, Any]:






              """simple docstring"""


              if isinstance(_UpperCamelCase			,   torch.Tensor      ):
                     __snake_case					  =       img.numpy().astype("""np.uint8"""      )
              if isinstance(_UpperCamelCase			,   _UpperCamelCase      ):
                     __snake_case					  =       img_tensorize(_UpperCamelCase      )
              assert isinstance(_UpperCamelCase			,   np.ndarray      )

              __snake_case  ,						__snake_case					  =       img.shape[1], img.shape[0]
              __snake_case					  =       mplfigure.Figure(frameon=_UpperCamelCase      )
              __snake_case					  =       fig.get_dpi()
              __snake_case					  =       (width * scale + 1E-2) / dpi
              __snake_case					  =       (height * scale + 1E-2) / dpi
              fig.set_size_inches(_UpperCamelCase			,   _UpperCamelCase      )
              __snake_case					  =       fig.add_axes([0.0, 0.0, 1.0, 1.0]      )
              ax.axis("""off"""      )
              ax.set_xlim(0.0			,   _UpperCamelCase      )
              ax.set_ylim(_UpperCamelCase      )

              __snake_case					  =       saveas
              __snake_case					  =       rgb
              __snake_case					  =       pynb
              __snake_case					  =       img
              __snake_case					  =       edgecolor
              __snake_case					  =       0.5
              __snake_case					  =       linestyle
              __snake_case					  =       int(np.sqrt(min(_UpperCamelCase			,   _UpperCamelCase      )      ) * scale // 3      )
              __snake_case					  =       width
              __snake_case					  =       height
              __snake_case					  =       scale
              __snake_case					  =       fig
              __snake_case					  =       ax
              __snake_case					  =       pad
              __snake_case					  =       idaobj
              __snake_case					  =       idaattr
              __snake_case					  =       FigureCanvasAgg(_UpperCamelCase      )


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase=None      )			->       int:






              """simple docstring"""


              if color is None:
                     __snake_case					  =       self.edgecolor
              ((__snake_case)  ,						(__snake_case)  ,						(__snake_case)  ,						(__snake_case))					  =       box
              __snake_case					  =       xa - xa
              __snake_case					  =       ya - ya
              self.ax.add_patch(
                  mpl.patches.Rectangle(
                      (xa, ya)			,   _UpperCamelCase			,   _UpperCamelCase			,   fill=_UpperCamelCase			,   edgecolor=_UpperCamelCase			,   linewidth=self.font_size // 3			,   alpha=self.alpha			,   linestyle=self.linestyle			,   )      )


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase=None			,   _UpperCamelCase=None			,   _UpperCamelCase=None			,   _UpperCamelCase=None      )			->       List[str]:






              """simple docstring"""


              if len(boxes.shape      ) > 2:
                     __snake_case					  =       boxes[0]
              if len(obj_ids.shape      ) > 1:
                     __snake_case					  =       obj_ids[0]
              if len(obj_scores.shape      ) > 1:
                     __snake_case					  =       obj_scores[0]
              if len(attr_ids.shape      ) > 1:
                     __snake_case					  =       attr_ids[0]
              if len(attr_scores.shape      ) > 1:
                     __snake_case					  =       attr_scores[0]
              if isinstance(_UpperCamelCase			,   torch.Tensor      ):
                     __snake_case					  =       boxes.numpy()
              if isinstance(_UpperCamelCase			,   _UpperCamelCase      ):
                     __snake_case					  =       np.array(_UpperCamelCase      )
              assert isinstance(_UpperCamelCase			,   np.ndarray      )
              __snake_case					  =       np.prod(boxes[:, 2:] - boxes[:, :2]			,   axis=1      )
              __snake_case					  =       np.argsort(-areas      ).tolist()
              __snake_case					  =       boxes[sorted_idxs] if boxes is not None else None
              __snake_case					  =       obj_ids[sorted_idxs] if obj_ids is not None else None
              __snake_case					  =       obj_scores[sorted_idxs] if obj_scores is not None else None
              __snake_case					  =       attr_ids[sorted_idxs] if attr_ids is not None else None
              __snake_case					  =       attr_scores[sorted_idxs] if attr_scores is not None else None

              __snake_case					  =       [self._random_color(maximum=1      ) for _ in range(len(_UpperCamelCase      )      )]
              __snake_case					  =       [assigned_colors[idx] for idx in sorted_idxs]
              if obj_ids is not None:
                     __snake_case					  =       self._create_text_labels_attr(_UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase      )
                     for i in range(len(_UpperCamelCase      )      ):
                            __snake_case					  =       assigned_colors[i]
                            self.add_box(boxes[i]			,   _UpperCamelCase      )
                            self.draw_labels(labels[i]			,   boxes[i]			,   _UpperCamelCase      )


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase      )			->       Optional[Any]:






              """simple docstring"""


              __snake_case  ,						__snake_case  ,						__snake_case  ,						__snake_case					  =       box
              __snake_case					  =       (xa, ya)
              __snake_case					  =       (ya - ya) * (xa - xa)
              __snake_case					  =       _SMALL_OBJ * self.scale
              if instance_area < small or ya - ya < 40 * self.scale:
                     if ya >= self.height - 5:
                            __snake_case					  =       (xa, ya)
                     else:
                            __snake_case					  =       (xa, ya)

              __snake_case					  =       (ya - ya) / np.sqrt(self.height * self.width      )
              __snake_case					  =       self._change_color_brightness(_UpperCamelCase			,   brightness_factor=0.7      )
              __snake_case					  =       np.clip((height_ratio - 0.02) / 0.08 + 1			,   1.2			,   2      )
              font_size *= 0.75 * self.font_size

              self.draw_text(
                  text=_UpperCamelCase			,   position=_UpperCamelCase			,   color=_UpperCamelCase			,   )


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase="g"			,   _UpperCamelCase="left"			,   )			->       List[Any]:






              """simple docstring"""


              __snake_case					  =       0
              __snake_case					  =       self.font_size
              __snake_case					  =       np.maximum(list(mplc.to_rgb(_UpperCamelCase      )      )			,   0.2      )
              __snake_case					  =       max(0.8			,   np.max(_UpperCamelCase      )      )
              __snake_case					  =       {
                  """facecolor""": """black""",
                  """alpha""": self.alpha,
                  """pad""": self.pad,
                  """edgecolor""": """none""",
              }
              __snake_case  ,						__snake_case					  =       position
              self.ax.text(
                  _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase			,   size=font_size * self.scale			,   family="""sans-serif"""			,   bbox=_UpperCamelCase			,   verticalalignment="""top"""			,   horizontalalignment=_UpperCamelCase			,   color=_UpperCamelCase			,   zorder=10			,   rotation=_UpperCamelCase			,   )


       def  a		(		self			,   _UpperCamelCase=None      )			->       str:






              """simple docstring"""


              if saveas is None:
                     __snake_case					  =       self.saveas
              if saveas.lower().endswith(""".jpg"""      ) or saveas.lower().endswith(""".png"""      ):
                     cva.imwrite(
                         _UpperCamelCase			,   self._get_buffer()[:, :, ::-1]			,   )
              else:
                     self.fig.savefig(_UpperCamelCase      )


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase      )			->       List[Any]:






              """simple docstring"""


              __snake_case					  =       [self.idaobj[i] for i in classes]
              __snake_case					  =       [self.idaattr[i] for i in attr_classes]
              __snake_case					  =       [
                  F'{label} {score:.2f} {attr} {attr_score:.2f}'
                  for label, score, attr, attr_score in zip(_UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase			,   _UpperCamelCase      )
              ]
              return labels


       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase      )			->       Union[str, Any]:






              """simple docstring"""


              __snake_case					  =       [self.idaobj[i] for i in classes]
              if scores is not None:
                     if labels is None:
                            __snake_case					  =       ["""{:.0f}%""".format(s * 1_00      ) for s in scores]
                     else:
                            __snake_case					  =       ["""{} {:.0f}%""".format(_UpperCamelCase			,   s * 1_00      ) for li, s in zip(_UpperCamelCase			,   _UpperCamelCase      )]
              return labels


       def  a		(		self			,   _UpperCamelCase=2_55      )			->       List[Any]:






              """simple docstring"""


              __snake_case					  =       np.random.randint(0			,   len(_COLORS      )      )
              __snake_case					  =       _COLORS[idx] * maximum
              if not self.rgb:
                     __snake_case					  =       ret[::-1]
              return ret


       def  a		(		self      )			->       Optional[Any]:






              """simple docstring"""


              if not self.pynb:
                     __snake_case  ,						__snake_case					  =       self.canvas.print_to_buffer()
                     if (width, height) != (self.width, self.height):
                            __snake_case					  =       cva.resize(self.img			,   (width, height)      )
                     else:
                            __snake_case					  =       self.img
              else:
                     __snake_case					  =       io.BytesIO()  # works for cairo backend
                     self.canvas.print_rgba(_UpperCamelCase      )
                     __snake_case  ,						__snake_case					  =       self.width, self.height
                     __snake_case					  =       buf.getvalue()
                     __snake_case					  =       self.img

              __snake_case					  =       np.frombuffer(_UpperCamelCase			,   dtype="""uint8"""      )
              __snake_case					  =       buffer.reshape(_UpperCamelCase			,   _UpperCamelCase			,   4      )
              __snake_case  ,						__snake_case					  =       np.split(_UpperCamelCase			,   [3]			,   axis=2      )

              try:
                     import numexpr as ne  # fuse them with numexpr

                     __snake_case					  =       ne.evaluate("""img * (1 - alpha / 255.0) + rgb * (alpha / 255.0)"""      )
              except ImportError:
                     __snake_case					  =       alpha.astype("""float32"""      ) / 255.0
                     __snake_case					  =       img * (1 - alpha) + rgb * alpha

              return visualized_image.astype("""uint8"""      )






       def  a		(		self			,   _UpperCamelCase			,   _UpperCamelCase      )			->       Dict:






              """simple docstring"""


              assert brightness_factor >= -1.0 and brightness_factor <= 1.0
              __snake_case					  =       mplc.to_rgb(_UpperCamelCase      )
              __snake_case					  =       colorsys.rgb_to_hls(*mplc.to_rgb(_UpperCamelCase      )      )
              __snake_case					  =       polygon_color[1] + (brightness_factor * polygon_color[1])
              __snake_case					  =       0.0 if modified_lightness < 0.0 else modified_lightness
              __snake_case					  =       1.0 if modified_lightness > 1.0 else modified_lightness
              __snake_case					  =       colorsys.hls_to_rgb(polygon_color[0]			,   _UpperCamelCase			,   polygon_color[2]      )
              return modified_color






UpperCamelCase__		   =    (
    np.array(
        [
            0.000,
            0.447,
            0.741,
            0.850,
            0.325,
            0.098,
            0.929,
            0.694,
            0.125,
            0.494,
            0.184,
            0.556,
            0.466,
            0.674,
            0.188,
            0.301,
            0.745,
            0.933,
            0.635,
            0.078,
            0.184,
            0.300,
            0.300,
            0.300,
            0.600,
            0.600,
            0.600,
            1.000,
            0.000,
            0.000,
            1.000,
            0.500,
            0.000,
            0.749,
            0.749,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.333,
            0.333,
            0.000,
            0.333,
            0.667,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            0.333,
            0.000,
            0.667,
            0.667,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.667,
            0.000,
            1.000,
            1.000,
            0.000,
            0.000,
            0.333,
            0.500,
            0.000,
            0.667,
            0.500,
            0.000,
            1.000,
            0.500,
            0.333,
            0.000,
            0.500,
            0.333,
            0.333,
            0.500,
            0.333,
            0.667,
            0.500,
            0.333,
            1.000,
            0.500,
            0.667,
            0.000,
            0.500,
            0.667,
            0.333,
            0.500,
            0.667,
            0.667,
            0.500,
            0.667,
            1.000,
            0.500,
            1.000,
            0.000,
            0.500,
            1.000,
            0.333,
            0.500,
            1.000,
            0.667,
            0.500,
            1.000,
            1.000,
            0.500,
            0.000,
            0.333,
            1.000,
            0.000,
            0.667,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            0.000,
            1.000,
            0.333,
            0.333,
            1.000,
            0.333,
            0.667,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            0.000,
            1.000,
            0.667,
            0.333,
            1.000,
            0.667,
            0.667,
            1.000,
            0.667,
            1.000,
            1.000,
            1.000,
            0.000,
            1.000,
            1.000,
            0.333,
            1.000,
            1.000,
            0.667,
            1.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.167,
            0.000,
            0.000,
            0.333,
            0.000,
            0.000,
            0.500,
            0.000,
            0.000,
            0.667,
            0.000,
            0.000,
            0.833,
            0.000,
            0.000,
            1.000,
            0.000,
            0.000,
            0.000,
            0.143,
            0.143,
            0.143,
            0.857,
            0.857,
            0.857,
            1.000,
            1.000,
            1.000,
        ]
    )
    .astype(np.floataa)
    .reshape(-1, 3)
)

