




import os

from ...utils import logging
from .utils import DataProcessor, InputExample


UpperCamelCase								=     logging.get_logger(__name__)





class  __lowerCamelCase       (    UpperCamelCase__    ):




    """simple docstring"""

    def __init__(       self     :     str   ,	SCREAMING_SNAKE_CASE__     :     str   ,	SCREAMING_SNAKE_CASE__     :     Union[str, Any]=None   )      ->       List[str]:
         lowerCAmelCase__		= language
         lowerCAmelCase__		= train_language


    def    a      (       self     :     Tuple   ,	SCREAMING_SNAKE_CASE__     :     Optional[Any]   )      ->       int:
         lowerCAmelCase__		= self.language if self.train_language is None else self.train_language
         lowerCAmelCase__		= self._read_tsv(os.path.join(SCREAMING_SNAKE_CASE__   ,	f'XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv'   )   )
         lowerCAmelCase__		= []
         for i, line in enumerate(SCREAMING_SNAKE_CASE__   ):
              if i == 0:
                   continue
              lowerCAmelCase__		= f'train-{i}'
              lowerCAmelCase__		= line[0]
              lowerCAmelCase__		= line[1]
              lowerCAmelCase__		= "contradiction" if line[2] == "contradictory" else line[2]
              if not isinstance(SCREAMING_SNAKE_CASE__   ,	SCREAMING_SNAKE_CASE__   ):
                   raise ValueError(f'Training input {text_a} is not a string'   )
              if not isinstance(SCREAMING_SNAKE_CASE__   ,	SCREAMING_SNAKE_CASE__   ):
                   raise ValueError(f'Training input {text_b} is not a string'   )
              if not isinstance(SCREAMING_SNAKE_CASE__   ,	SCREAMING_SNAKE_CASE__   ):
                   raise ValueError(f'Training label {label} is not a string'   )
              examples.append(InputExample(guid=SCREAMING_SNAKE_CASE__   ,	text_a=SCREAMING_SNAKE_CASE__   ,	text_b=SCREAMING_SNAKE_CASE__   ,	label=SCREAMING_SNAKE_CASE__   )   )
         return examples


    def    a      (       self     :     Optional[int]   ,	SCREAMING_SNAKE_CASE__     :     List[str]   )      ->       Dict:
         lowerCAmelCase__		= self._read_tsv(os.path.join(SCREAMING_SNAKE_CASE__   ,	"XNLI-1.0/xnli.test.tsv"   )   )
         lowerCAmelCase__		= []
         for i, line in enumerate(SCREAMING_SNAKE_CASE__   ):
              if i == 0:
                   continue
              lowerCAmelCase__		= line[0]
              if language != self.language:
                   continue
              lowerCAmelCase__		= f'test-{i}'
              lowerCAmelCase__		= line[6]
              lowerCAmelCase__		= line[7]
              lowerCAmelCase__		= line[1]
              if not isinstance(SCREAMING_SNAKE_CASE__   ,	SCREAMING_SNAKE_CASE__   ):
                   raise ValueError(f'Training input {text_a} is not a string'   )
              if not isinstance(SCREAMING_SNAKE_CASE__   ,	SCREAMING_SNAKE_CASE__   ):
                   raise ValueError(f'Training input {text_b} is not a string'   )
              if not isinstance(SCREAMING_SNAKE_CASE__   ,	SCREAMING_SNAKE_CASE__   ):
                   raise ValueError(f'Training label {label} is not a string'   )
              examples.append(InputExample(guid=SCREAMING_SNAKE_CASE__   ,	text_a=SCREAMING_SNAKE_CASE__   ,	text_b=SCREAMING_SNAKE_CASE__   ,	label=SCREAMING_SNAKE_CASE__   )   )
         return examples


    def    a      (       self     :     str   )      ->       Optional[int]:
         return ["contradiction", "entailment", "neutral"]






UpperCamelCase								=     {
    'xnli': XnliProcessor,
}

UpperCamelCase								=     {
    'xnli': 'classification',
}

UpperCamelCase								=     {
    'xnli': 3,
}






import unittest
from pathlib import Path

from transformers import is_vision_available, load_tool
from transformers.testing_utils import get_tests_dir

from .test_tools_common import ToolTesterMixin


if is_vision_available():
     from PIL import Image





class  __lowerCamelCase       (    unittest.TestCase	,				UpperCamelCase__    ):




    """simple docstring"""

    def    a      (       self     :     Any   )      ->       Tuple:
         lowerCAmelCase__		= load_tool("image-captioning"   )
         self.tool.setup()
         lowerCAmelCase__		= load_tool("image-captioning"   ,	remote=SCREAMING_SNAKE_CASE__   )


    def    a      (       self     :     int   )      ->       List[str]:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.tool(SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )


    def    a      (       self     :     List[str]   )      ->       int:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.remote_tool(SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )


    def    a      (       self     :     Any   )      ->       Any:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.tool(image=SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )


    def    a      (       self     :     Dict   )      ->       Any:
         lowerCAmelCase__		= Image.open(Path(get_tests_dir("fixtures/tests_samples/COCO"   )   ) / "000000039769.png"   )
         lowerCAmelCase__		= self.remote_tool(image=SCREAMING_SNAKE_CASE__   )
         self.assertEqual(SCREAMING_SNAKE_CASE__   ,	"two cats sleeping on a couch"   )
