


import os
from glob import glob

import imageio
import torch
import torchvision
import wandb
from img_processing import custom_to_pil, loop_post_process, preprocess, preprocess_vqgan
from loaders import load_vqgan
from PIL import Image
from torch import nn

from transformers import CLIPModel, CLIPTokenizerFast
from utils import get_device, get_timestamp, show_pil







class 			_lowercase :


       """simple docstring"""




       def __init__(   self							:			Union[str, Any]					,      __lowerCamelCase							:			str = "cpu"					,      __lowerCamelCase							:			str = "openai/clip-vit-large-patch14"       ):


             '''simple docstring'''



             lowerCamelCase__		:				str    =  device
             lowerCamelCase__		:				Union[str, Any]    =  CLIPTokenizerFast.from_pretrained(__lowerCamelCase       )
             lowerCamelCase__		:				Optional[Any]    =  [0.4_8_1_4_5_4_6_6, 0.4_5_7_8_2_7_5, 0.4_0_8_2_1_0_7_3]
             lowerCamelCase__		:				List[Any]    =  [0.2_6_8_6_2_9_5_4, 0.2_6_1_3_0_2_5_8, 0.2_7_5_7_7_7_1_1]
             lowerCamelCase__		:				List[Any]    =  torchvision.transforms.Normalize(self.image_mean					,      self.image_std       )
             lowerCamelCase__		:				Tuple    =  torchvision.transforms.Resize(224       )
             lowerCamelCase__		:				int    =  torchvision.transforms.CenterCrop(224       )





       def 						lowerCAmelCase     (   self							:			Optional[int]					,      __lowerCamelCase							:			int       ):


             '''simple docstring'''



             lowerCamelCase__		:				Union[str, Any]    =  self.resize(__lowerCamelCase       )
             lowerCamelCase__		:				List[Any]    =  self.center_crop(__lowerCamelCase       )
             lowerCamelCase__		:				List[Any]    =  self.normalize(__lowerCamelCase       )
             return images





       def __call__(   self							:			int					,      __lowerCamelCase							:			Any=None					,      __lowerCamelCase							:			Any=None					,      **__lowerCamelCase							:			Union[str, Any]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Optional[Any]    =  self.tokenizer(text=__lowerCamelCase					,      **__lowerCamelCase       )
             lowerCamelCase__		:				List[str]    =  self.preprocess_img(__lowerCamelCase       )
             lowerCamelCase__		:				Any    =  {key: value.to(self.device       ) for (key, value) in encoding.items()}
             return encoding







class 			_lowercase (							nn.Module):


       """simple docstring"""




       def __init__(   self							:			Optional[Any]					,      __lowerCamelCase							:			List[Any]=10					,      __lowerCamelCase							:			Tuple=0.0_1					,      __lowerCamelCase							:			Optional[int]=None					,      __lowerCamelCase							:			List[Any]=None					,      __lowerCamelCase							:			Optional[Any]=None					,      __lowerCamelCase							:			Optional[int]=None					,      __lowerCamelCase							:			int=None					,      __lowerCamelCase							:			List[str]=None					,      __lowerCamelCase							:			str=False					,      __lowerCamelCase							:			int=True					,      __lowerCamelCase							:			Dict="image"					,      __lowerCamelCase							:			Optional[int]=True					,      __lowerCamelCase							:			Optional[Any]=False					,      __lowerCamelCase							:			Union[str, Any]=False					,      __lowerCamelCase							:			List[str]=False					,      ):


             '''simple docstring'''



             super().__init__()
             lowerCamelCase__		:				Dict    =  None
             lowerCamelCase__		:				Any    =  device if device else get_device()
             if vqgan:
                   lowerCamelCase__		:				Union[str, Any]    =  vqgan
             else:
                   lowerCamelCase__		:				Dict    =  load_vqgan(self.device					,      conf_path=__lowerCamelCase					,      ckpt_path=__lowerCamelCase       )
             self.vqgan.eval()
             if clip:
                   lowerCamelCase__		:				Tuple    =  clip
             else:
                   lowerCamelCase__		:				List[str]    =  CLIPModel.from_pretrained("openai/clip-vit-base-patch32"       )
             self.clip.to(self.device       )
             lowerCamelCase__		:				List[str]    =  ProcessorGradientFlow(device=self.device       )

             lowerCamelCase__		:				Tuple    =  iterations
             lowerCamelCase__		:				Optional[Any]    =  lr
             lowerCamelCase__		:				int    =  log
             lowerCamelCase__		:				Dict    =  make_grid
             lowerCamelCase__		:				List[str]    =  return_val
             lowerCamelCase__		:				str    =  quantize
             lowerCamelCase__		:				Dict    =  self.vqgan.decoder.z_shape





       def 						lowerCAmelCase     (   self							:			Optional[int]					,      __lowerCamelCase							:			Tuple=None					,      __lowerCamelCase							:			Optional[Any]=None					,      __lowerCamelCase							:			List[Any]=5					,      __lowerCamelCase							:			int=True       ):


             '''simple docstring'''



             lowerCamelCase__		:				int    =  []
             if output_path is None:
                   lowerCamelCase__		:				Any    =  "./animation.gif"
             if input_path is None:
                   lowerCamelCase__		:				int    =  self.save_path
             lowerCamelCase__		:				Tuple    =  sorted(glob(input_path + "/*"       )       )
             if not len(__lowerCamelCase       ):
                   raise ValueError(
                       "No images found in save path, aborting (did you pass save_intermediate=True to the generate"
                       " function?)"       )
             if len(__lowerCamelCase       ) == 1:
                   print("Only one image found in save path, (did you pass save_intermediate=True to the generate function?)"       )
             lowerCamelCase__		:				int    =  total_duration / len(__lowerCamelCase       )
             lowerCamelCase__		:				int    =  [frame_duration] * len(__lowerCamelCase       )
             if extend_frames:
                   lowerCamelCase__		:				Dict    =  1.5
                   lowerCamelCase__		:				Tuple    =  3
             for file_name in paths:
                   if file_name.endswith(".png"       ):
                         images.append(imageio.imread(__lowerCamelCase       )       )
             imageio.mimsave(__lowerCamelCase					,      __lowerCamelCase					,      duration=__lowerCamelCase       )
             print(f"gif saved to {output_path}"       )





       def 						lowerCAmelCase     (   self							:			int					,      __lowerCamelCase							:			Dict=None					,      __lowerCamelCase							:			Dict=None       ):


             '''simple docstring'''



             if not (path or img):
                   raise ValueError("Input either path or tensor"       )
             if img is not None:
                   raise NotImplementedError
             lowerCamelCase__		:				Any    =  preprocess(Image.open(__lowerCamelCase       )					,      target_image_size=256       ).to(self.device       )
             lowerCamelCase__		:				Optional[int]    =  preprocess_vqgan(__lowerCamelCase       )
             lowerCamelCase__    ,   *lowerCamelCase__		:				List[Any]    =  self.vqgan.encode(__lowerCamelCase       )
             return z





       def 						lowerCAmelCase     (   self							:			Optional[int]					,      __lowerCamelCase							:			Optional[Any]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Dict    =  self.latent.detach().requires_grad_()
             lowerCamelCase__		:				Tuple    =  base_latent + transform_vector
             if self.quantize:
                   lowerCamelCase__    ,   *lowerCamelCase__		:				str    =  self.vqgan.quantize(__lowerCamelCase       )
             else:
                   lowerCamelCase__		:				Union[str, Any]    =  trans_latent
             return self.vqgan.decode(__lowerCamelCase       )





       def 						lowerCAmelCase     (   self							:			int					,      __lowerCamelCase							:			List[str]					,      __lowerCamelCase							:			List[Any]					,      __lowerCamelCase							:			Tuple=None       ):


             '''simple docstring'''



             lowerCamelCase__		:				Optional[int]    =  self.clip_preprocessor(text=__lowerCamelCase					,      images=__lowerCamelCase					,      return_tensors="pt"					,      padding=__lowerCamelCase       )
             lowerCamelCase__		:				Union[str, Any]    =  self.clip(**__lowerCamelCase       )
             lowerCamelCase__		:				Tuple    =  clip_outputs.logits_per_image
             if weights is not None:
                   lowerCamelCase__		:				Union[str, Any]    =  similarity_logits * weights
             return similarity_logits.sum()





       def 						lowerCAmelCase     (   self							:			Tuple					,      __lowerCamelCase							:			Union[str, Any]					,      __lowerCamelCase							:			Optional[int]					,      __lowerCamelCase							:			Any       ):


             '''simple docstring'''



             lowerCamelCase__		:				str    =  self._get_clip_similarity(pos_prompts["prompts"]					,      __lowerCamelCase					,      weights=(1 / pos_prompts["weights"])       )
             if neg_prompts:
                   lowerCamelCase__		:				Tuple    =  self._get_clip_similarity(neg_prompts["prompts"]					,      __lowerCamelCase					,      weights=neg_prompts["weights"]       )
             else:
                   lowerCamelCase__		:				Any    =  torch.tensor([1]					,      device=self.device       )
             lowerCamelCase__		:				Any    =  -torch.log(__lowerCamelCase       ) + torch.log(__lowerCamelCase       )
             return loss





       def 						lowerCAmelCase     (   self							:			Optional[int]					,      __lowerCamelCase							:			List[Any]					,      __lowerCamelCase							:			List[str]					,      __lowerCamelCase							:			Union[str, Any]       ):


             '''simple docstring'''



             lowerCamelCase__		:				List[str]    =  torch.randn_like(self.latent					,      requires_grad=__lowerCamelCase					,      device=self.device       )
             lowerCamelCase__		:				str    =  torch.optim.Adam([vector]					,      lr=self.lr       )

             for i in range(self.iterations       ):
                   optim.zero_grad()
                   lowerCamelCase__		:				List[str]    =  self._add_vector(__lowerCamelCase       )
                   lowerCamelCase__		:				List[Any]    =  loop_post_process(__lowerCamelCase       )
                   lowerCamelCase__		:				Optional[Any]    =  self._get_CLIP_loss(__lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase       )
                   print("CLIP loss"					,      __lowerCamelCase       )
                   if self.log:
                         wandb.log({"CLIP Loss": clip_loss}       )
                   clip_loss.backward(retain_graph=__lowerCamelCase       )
                   optim.step()
                   if self.return_val == "image":
                         yield custom_to_pil(transformed_img[0]       )
                   else:
                         yield vector





       def 						lowerCAmelCase     (   self							:			Any					,      __lowerCamelCase							:			List[str]					,      __lowerCamelCase							:			int					,      __lowerCamelCase							:			List[Any]       ):


             '''simple docstring'''



             wandb.init(reinit=__lowerCamelCase					,      project="face-editor"       )
             wandb.config.update({"Positive Prompts": positive_prompts}       )
             wandb.config.update({"Negative Prompts": negative_prompts}       )
             wandb.config.update({"lr": self.lr, "iterations": self.iterations}       )
             if image_path:
                   lowerCamelCase__		:				int    =  Image.open(__lowerCamelCase       )
                   lowerCamelCase__		:				Optional[Any]    =  image.resize((256, 256)       )
                   wandb.log("Original Image"					,      wandb.Image(__lowerCamelCase       )       )





       def 						lowerCAmelCase     (   self							:			Dict					,      __lowerCamelCase							:			List[Any]       ):


             '''simple docstring'''



             if not prompts:
                   return []
             lowerCamelCase__		:				Any    =  []
             lowerCamelCase__		:				Tuple    =  []
             if isinstance(__lowerCamelCase					,      __lowerCamelCase       ):
                   lowerCamelCase__		:				Optional[int]    =  [prompt.strip() for prompt in prompts.split("|"       )]
             for prompt in prompts:
                   if isinstance(__lowerCamelCase					,      (tuple, list)       ):
                         lowerCamelCase__		:				Optional[Any]    =  prompt[0]
                         lowerCamelCase__		:				Any    =  float(prompt[1]       )
                   elif ":" in prompt:
                         lowerCamelCase__    ,   lowerCamelCase__		:				List[str]    =  prompt.split(":"       )
                         lowerCamelCase__		:				int    =  float(__lowerCamelCase       )
                   else:
                         lowerCamelCase__		:				List[str]    =  prompt
                         lowerCamelCase__		:				Tuple    =  1.0
                   processed_prompts.append(__lowerCamelCase       )
                   weights.append(__lowerCamelCase       )
             return {
                 "prompts": processed_prompts,
                 "weights": torch.tensor(__lowerCamelCase					,      device=self.device       ),
             }





       def 						lowerCAmelCase     (   self							:			List[str]					,      __lowerCamelCase							:			List[str]					,      __lowerCamelCase							:			Dict=None					,      __lowerCamelCase							:			str=None					,      __lowerCamelCase							:			Dict=True					,      __lowerCamelCase							:			str=False					,      __lowerCamelCase							:			str=True					,      __lowerCamelCase							:			Dict=True					,      __lowerCamelCase							:			Optional[Any]=None					,      ):


             '''simple docstring'''



             if image_path:
                   lowerCamelCase__		:				str    =  self._get_latent(__lowerCamelCase       )
             else:
                   lowerCamelCase__		:				str    =  torch.randn(self.latent_dim					,      device=self.device       )
             if self.log:
                   self._init_logging(__lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase       )

             assert pos_prompts, "You must provide at least one positive prompt."
             lowerCamelCase__		:				Optional[Any]    =  self.process_prompts(__lowerCamelCase       )
             lowerCamelCase__		:				str    =  self.process_prompts(__lowerCamelCase       )
             if save_final and save_path is None:
                   lowerCamelCase__		:				Optional[int]    =  os.path.join("./outputs/"					,      "_".join(pos_prompts["prompts"]       )       )
             if not os.path.exists(__lowerCamelCase       ):
                   os.makedirs(__lowerCamelCase       )
             else:
                   lowerCamelCase__		:				Optional[int]    =  save_path + "_" + get_timestamp()
                   os.makedirs(__lowerCamelCase       )
             lowerCamelCase__		:				List[Any]    =  save_path

             lowerCamelCase__		:				List[str]    =  self.vqgan.decode(self.latent       )[0]
             if show_intermediate:
                   print("Original Image"       )
                   show_pil(custom_to_pil(__lowerCamelCase       )       )

             lowerCamelCase__		:				Optional[Any]    =  loop_post_process(__lowerCamelCase       )
             for iter, transformed_img in enumerate(self._optimize_CLIP(__lowerCamelCase					,      __lowerCamelCase					,      __lowerCamelCase       )       ):
                   if show_intermediate:
                         show_pil(__lowerCamelCase       )
                   if save_intermediate:
                         transformed_img.save(os.path.join(self.save_path					,      f"iter_{iter:03d}.png"       )       )
                   if self.log:
                         wandb.log({"Image": wandb.Image(__lowerCamelCase       )}       )
             if show_final:
                   show_pil(__lowerCamelCase       )
             if save_final:
                   transformed_img.save(os.path.join(self.save_path					,      f"iter_{iter:03d}_final.png"       )       )






import unittest

from transformers import (
    MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING,
    TextClassificationPipeline,
    pipeline,
)
from transformers.testing_utils import is_pipeline_test, nested_simplify, require_tf, require_torch, slow

from .test_pipelines_common import ANY


# These 2 model types require different inputs than those of the usual text models.
A      :    Union[str, Any]		=					{"LayoutLMv2Config", "LayoutLMv3Config"}







@is_pipeline_test
class 			_lowercase (							unittest.TestCase):


       """simple docstring"""




       A__											=			MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING
       A__											=			TF_MODEL_FOR_SEQUENCE_CLASSIFICATION_MAPPING

       if model_mapping is not None:
              A__											=			{config: model for config, model in model_mapping.items() if config.__name__ not in _TO_SKIP}
       if tf_model_mapping is not None:
              A__											=			{
                  config: model for config, model in tf_model_mapping.items() if config.__name__ not in _TO_SKIP
              }





       @require_torch
       def 						lowerCAmelCase     (   self							:			List[str]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Tuple    =  pipeline(
                 task="text-classification"					,      model="hf-internal-testing/tiny-random-distilbert"					,      framework="pt"       )

             lowerCamelCase__		:				Dict    =  text_classifier("This is great !"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "LABEL_0", "score": 0.5_0_4}]       )

             lowerCamelCase__		:				List[str]    =  text_classifier("This is great !"					,      top_k=2       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [{"label": "LABEL_0", "score": 0.5_0_4}, {"label": "LABEL_1", "score": 0.4_9_6}]       )

             lowerCamelCase__		:				Optional[int]    =  text_classifier(["This is great !", "This is bad"]					,      top_k=2       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [
                     [{"label": "LABEL_0", "score": 0.5_0_4}, {"label": "LABEL_1", "score": 0.4_9_6}],
                     [{"label": "LABEL_0", "score": 0.5_0_4}, {"label": "LABEL_1", "score": 0.4_9_6}],
                 ]					,      )

             lowerCamelCase__		:				Any    =  text_classifier("This is great !"					,      top_k=1       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "LABEL_0", "score": 0.5_0_4}]       )

             # Legacy behavior
             lowerCamelCase__		:				Dict    =  text_classifier("This is great !"					,      return_all_scores=__lowerCamelCase       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "LABEL_0", "score": 0.5_0_4}]       )

             lowerCamelCase__		:				str    =  text_classifier("This is great !"					,      return_all_scores=__lowerCamelCase       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [[{"label": "LABEL_0", "score": 0.5_0_4}, {"label": "LABEL_1", "score": 0.4_9_6}]]       )

             lowerCamelCase__		:				Optional[Any]    =  text_classifier(["This is great !", "Something else"]					,      return_all_scores=__lowerCamelCase       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [
                     [{"label": "LABEL_0", "score": 0.5_0_4}, {"label": "LABEL_1", "score": 0.4_9_6}],
                     [{"label": "LABEL_0", "score": 0.5_0_4}, {"label": "LABEL_1", "score": 0.4_9_6}],
                 ]					,      )

             lowerCamelCase__		:				Any    =  text_classifier(["This is great !", "Something else"]					,      return_all_scores=__lowerCamelCase       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [
                     {"label": "LABEL_0", "score": 0.5_0_4},
                     {"label": "LABEL_0", "score": 0.5_0_4},
                 ]					,      )





       @require_torch
       def 						lowerCAmelCase     (   self							:			str       ):


             '''simple docstring'''



             import torch

             lowerCamelCase__		:				int    =  pipeline(
                 task="text-classification"					,      model="hf-internal-testing/tiny-random-distilbert"					,      framework="pt"					,      device=torch.device("cpu"       )					,      )

             lowerCamelCase__		:				Any    =  text_classifier("This is great !"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "LABEL_0", "score": 0.5_0_4}]       )





       @require_tf
       def 						lowerCAmelCase     (   self							:			int       ):


             '''simple docstring'''



             lowerCamelCase__		:				List[str]    =  pipeline(
                 task="text-classification"					,      model="hf-internal-testing/tiny-random-distilbert"					,      framework="tf"       )

             lowerCamelCase__		:				List[str]    =  text_classifier("This is great !"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "LABEL_0", "score": 0.5_0_4}]       )





       @slow
       @require_torch
       def 						lowerCAmelCase     (   self							:			List[Any]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Optional[Any]    =  pipeline("text-classification"       )

             lowerCamelCase__		:				List[str]    =  text_classifier("This is great !"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "POSITIVE", "score": 1.0}]       )
             lowerCamelCase__		:				Optional[int]    =  text_classifier("This is bad !"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "NEGATIVE", "score": 1.0}]       )
             lowerCamelCase__		:				Tuple    =  text_classifier("Birds are a type of animal"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "POSITIVE", "score": 0.9_8_8}]       )





       @slow
       @require_tf
       def 						lowerCAmelCase     (   self							:			List[Any]       ):


             '''simple docstring'''



             lowerCamelCase__		:				str    =  pipeline("text-classification"					,      framework="tf"       )

             lowerCamelCase__		:				Optional[int]    =  text_classifier("This is great !"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "POSITIVE", "score": 1.0}]       )
             lowerCamelCase__		:				Optional[Any]    =  text_classifier("This is bad !"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "NEGATIVE", "score": 1.0}]       )
             lowerCamelCase__		:				Dict    =  text_classifier("Birds are a type of animal"       )
             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": "POSITIVE", "score": 0.9_8_8}]       )





       def 						lowerCAmelCase     (   self							:			Tuple					,      __lowerCamelCase							:			Any					,      __lowerCamelCase							:			str					,      __lowerCamelCase							:			Optional[Any]       ):


             '''simple docstring'''



             lowerCamelCase__		:				Tuple    =  TextClassificationPipeline(model=__lowerCamelCase					,      tokenizer=__lowerCamelCase       )
             return text_classifier, ["HuggingFace is in", "This is another test"]





       def 						lowerCAmelCase     (   self							:			Optional[Any]					,      __lowerCamelCase							:			Tuple					,      __lowerCamelCase							:			Any       ):


             '''simple docstring'''



             lowerCamelCase__		:				int    =  text_classifier.model
             # Small inputs because BartTokenizer tiny has maximum position embeddings = 22
             lowerCamelCase__		:				List[Any]    =  "HuggingFace is in"
             lowerCamelCase__		:				Tuple    =  text_classifier(__lowerCamelCase       )

             self.assertEqual(nested_simplify(__lowerCamelCase       )					,      [{"label": ANY(__lowerCamelCase       ), "score": ANY(__lowerCamelCase       )}]       )
             self.assertTrue(outputs[0]["label"] in model.config.idalabel.values()       )

             lowerCamelCase__		:				Optional[int]    =  ["HuggingFace is in ", "Paris is in France"]
             lowerCamelCase__		:				Dict    =  text_classifier(__lowerCamelCase       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [{"label": ANY(__lowerCamelCase       ), "score": ANY(__lowerCamelCase       )}, {"label": ANY(__lowerCamelCase       ), "score": ANY(__lowerCamelCase       )}]					,      )
             self.assertTrue(outputs[0]["label"] in model.config.idalabel.values()       )
             self.assertTrue(outputs[1]["label"] in model.config.idalabel.values()       )

             # Forcing to get all results with `top_k=None`
             # This is NOT the legacy format
             lowerCamelCase__		:				List[Any]    =  text_classifier(__lowerCamelCase					,      top_k=__lowerCamelCase       )
             lowerCamelCase__		:				Union[str, Any]    =  len(model.config.idalabel.values()       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [[{"label": ANY(__lowerCamelCase       ), "score": ANY(__lowerCamelCase       )}] * N, [{"label": ANY(__lowerCamelCase       ), "score": ANY(__lowerCamelCase       )}] * N]					,      )

             lowerCamelCase__		:				Optional[int]    =  {"text": "HuggingFace is in ", "text_pair": "Paris is in France"}
             lowerCamelCase__		:				List[Any]    =  text_classifier(__lowerCamelCase       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      {"label": ANY(__lowerCamelCase       ), "score": ANY(__lowerCamelCase       )}					,      )
             self.assertTrue(outputs["label"] in model.config.idalabel.values()       )

             # This might be used a text pair, but tokenizer + pipe interaction
             # makes it hard to understand that it's not using the pair properly
             # https://github.com/huggingface/transformers/issues/17305
             # We disabled this usage instead as it was outputting wrong outputs.
             lowerCamelCase__		:				Any    =  [["HuggingFace is in ", "Paris is in France"]]
             with self.assertRaises(__lowerCamelCase       ):
                   text_classifier(__lowerCamelCase       )

             # This used to be valid for doing text pairs
             # We're keeping it working because of backward compatibility
             lowerCamelCase__		:				int    =  text_classifier([[["HuggingFace is in ", "Paris is in France"]]]       )
             self.assertEqual(
                 nested_simplify(__lowerCamelCase       )					,      [{"label": ANY(__lowerCamelCase       ), "score": ANY(__lowerCamelCase       )}]					,      )
             self.assertTrue(outputs[0]["label"] in model.config.idalabel.values()       )


