




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 						SCREAMING_SNAKE_CASE__		(unittest.TestCase						,				_a ):
     def 					A__			(	self  :		int	):



       """simple docstring"""
       lowerCAmelCase__								=			load_tool('''image-question-answering'''	)
       self.tool.setup()
       lowerCAmelCase__								=			load_tool('''image-question-answering'''					,	remote=__lowerCamelCase	)
     def 					A__			(	self  :		List[Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''	)	) / '''000000039769.png'''	)
       lowerCAmelCase__								=			self.tool(__lowerCamelCase					,	'''How many cats are sleeping on the couch?'''	)
       self.assertEqual(__lowerCamelCase					,	'''2'''	)
     def 					A__			(	self  :		Optional[int]	):



       """simple docstring"""
       lowerCAmelCase__								=			Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''	)	) / '''000000039769.png'''	)
       lowerCAmelCase__								=			self.remote_tool(__lowerCamelCase					,	'''How many cats are sleeping on the couch?'''	)
       self.assertEqual(__lowerCamelCase					,	'''2'''	)
     def 					A__			(	self  :		Any	):



       """simple docstring"""
       lowerCAmelCase__								=			Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''	)	) / '''000000039769.png'''	)
       lowerCAmelCase__								=			self.tool(image=__lowerCamelCase					,	question='''How many cats are sleeping on the couch?'''	)
       self.assertEqual(__lowerCamelCase					,	'''2'''	)



     def 					A__			(	self  :		int	):



       """simple docstring"""
       lowerCAmelCase__								=			Image.open(Path(get_tests_dir('''fixtures/tests_samples/COCO'''	)	) / '''000000039769.png'''	)
       lowerCAmelCase__								=			self.remote_tool(image=__lowerCamelCase					,	question='''How many cats are sleeping on the couch?'''	)
       self.assertEqual(__lowerCamelCase					,	'''2'''	)







import os

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


__magic_name__     :     str  							=					logging.get_logger(__name__)





class 						SCREAMING_SNAKE_CASE__		(_a ):
     def __init__(	self  :		Any					,	__lowerCamelCase  :		Any					,	__lowerCamelCase  :		Optional[int]=None	):



       """simple docstring"""
       lowerCAmelCase__								=			language
       lowerCAmelCase__								=			train_language
     def 					A__			(	self  :		str					,	__lowerCamelCase  :		List[str]	):



       """simple docstring"""
       lowerCAmelCase__								=			self.language if self.train_language is None else self.train_language
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	F"""XNLI-MT-1.0/multinli/multinli.train.{lg}.tsv"""	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         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(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples
     def 					A__			(	self  :		Dict					,	__lowerCamelCase  :		Union[str, Any]	):



       """simple docstring"""
       lowerCAmelCase__								=			self._read_tsv(os.path.join(__lowerCamelCase					,	'''XNLI-1.0/xnli.test.tsv'''	)	)
       lowerCAmelCase__								=			[]
       for i, line in enumerate(__lowerCamelCase	):
         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(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_a} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training input {text_b} is not a string"""	)
         if not isinstance(__lowerCamelCase					,	__lowerCamelCase	):
           raise ValueError(F"""Training label {label} is not a string"""	)
         examples.append(InputExample(guid=__lowerCamelCase					,	text_a=__lowerCamelCase					,	text_b=__lowerCamelCase					,	label=__lowerCamelCase	)	)
       return examples



     def 					A__			(	self  :		List[str]	):



       """simple docstring"""
       return ["contradiction", "entailment", "neutral"]



__magic_name__     :     Tuple  							=					{
    """xnli""": XnliProcessor,
}

__magic_name__     :     List[Any]  							=					{
    """xnli""": """classification""",
}

__magic_name__     :     str  							=					{
    """xnli""": 3,
}

