


"""simple docstring"""




import csv
import json
import os

import datasets


# TODO: Add BibTeX citation
# Find for instance the citation on arxiv or on the dataset repo/website
lowerCAmelCase__						=			"\\n@InProceedings{huggingface:dataset,\ntitle = {A great new dataset},\nauthor={huggingface, Inc.\n},\nyear={2020}\n}\n"

# TODO: Add description of the dataset here
# You can copy an official description
lowerCAmelCase__						=			"\\nThis new dataset is designed to solve this great NLP task and is crafted with a lot of care.\n"

# TODO: Add a link to an official homepage for the dataset here
lowerCAmelCase__						=			""

# TODO: Add the licence for the dataset here if you can find it
lowerCAmelCase__						=			""

# TODO: Add link to the official dataset URLs here
# The HuggingFace Datasets library doesn't host the datasets but only points to the original files.
# This can be an arbitrary nested dict/list of URLs (see below in `_split_generators` method)
lowerCAmelCase__						=			{
    "first_domain": "https://huggingface.co/great-new-dataset-first_domain.zip",
    "second_domain": "https://huggingface.co/great-new-dataset-second_domain.zip",
}







class 					lowerCAmelCase__	(    datasets.GeneratorBasedBuilder):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			datasets.Version("1.1.0")

     # This is an example of a dataset with multiple configurations.
     # If you don't want/need to define several sub-sets in your dataset,
     # just remove the BUILDER_CONFIG_CLASS and the BUILDER_CONFIGS attributes.

     # If you need to make complex sub-parts in the datasets with configurable options
     # You can create your own builder configuration class to store attribute, inheriting from datasets.BuilderConfig
     # BUILDER_CONFIG_CLASS = MyBuilderConfig

     # You will be able to load one or the other configurations in the following list with
     # data = datasets.load_dataset('my_dataset', 'first_domain')
     # data = datasets.load_dataset('my_dataset', 'second_domain')
     __SCREAMING_SNAKE_CASE        =			[
         datasets.BuilderConfig(name="first_domain"					,   version=SCREAMING_SNAKE_CASE__					,   description="This part of my dataset covers a first domain"),
         datasets.BuilderConfig(name="second_domain"					,   version=SCREAMING_SNAKE_CASE__					,   description="This part of my dataset covers a second domain"),
     ]

     __SCREAMING_SNAKE_CASE        =			'first_domain'  # It's not mandatory to have a default configuration. Just use one if it make sense.


     def 			_lowerCamelCase			(						self)      ->    Dict:

            if self.config.name == "first_domain":  # This is the name of the configuration selected in BUILDER_CONFIGS above
                   _A				:	Union[str, Any]       =			datasets.Features(
                       {
                           "sentence": datasets.Value("string"),
                           "option1": datasets.Value("string"),
                           "answer": datasets.Value("string")
                           # These are the features of your dataset like images, labels ...
                       })
            else:  # This is an example to show how to have different features for "first_domain" and "second_domain"
                   _A				:	Dict       =			datasets.Features(
                       {
                           "sentence": datasets.Value("string"),
                           "option2": datasets.Value("string"),
                           "second_domain_answer": datasets.Value("string")
                           # These are the features of your dataset like images, labels ...
                       })
            return datasets.DatasetInfo(
                # This is the description that will appear on the datasets page.
                description=_DESCRIPTION			,						features=__lowerCamelCase			,						homepage=_HOMEPAGE			,						license=_LICENSE			,						citation=_CITATION			,						)


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase)      ->    Dict:
            _A				:	Tuple       =			_URLS[self.config.name]
            _A				:	Any       =			dl_manager.download_and_extract(__lowerCamelCase)
            return [
                datasets.SplitGenerator(
                    name=datasets.Split.TRAIN			,						gen_kwargs={
                        "filepath": os.path.join(__lowerCamelCase			,						"train.jsonl"),
                        "split": "train",
                    }			,						),
                datasets.SplitGenerator(
                    name=datasets.Split.VALIDATION			,						gen_kwargs={
                        "filepath": os.path.join(__lowerCamelCase			,						"dev.jsonl"),
                        "split": "dev",
                    }			,						),
                datasets.SplitGenerator(
                    name=datasets.Split.TEST			,						gen_kwargs={
                        "filepath": os.path.join(__lowerCamelCase			,						"test.jsonl"),
                        "split": "test"
                    }			,						),
            ]


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase			,						__lowerCamelCase)      ->    Union[str, Any]:

            with open(__lowerCamelCase			,						encoding="utf-8") as f:
                   for key, row in enumerate(__lowerCamelCase):
                          _A				:	Tuple       =			json.loads(__lowerCamelCase)
                          if self.config.name == "first_domain":
                                 # Yields examples as (key, example) tuples
                                 yield key, {
                                     "sentence": data["sentence"],
                                     "option1": data["option1"],
                                     "answer": "" if split == "test" else data["answer"],
                                 }
                          else:
                                 yield key, {
                                     "sentence": data["sentence"],
                                     "option2": data["option2"],
                                     "second_domain_answer": "" if split == "test" else data["second_domain_answer"],
                                 }




import unittest

import numpy as np

from transformers.testing_utils import require_torch, require_vision
from transformers.utils import is_torch_available, is_vision_available

from ...test_image_processing_common import ImageProcessingSavingTestMixin


if is_torch_available():
    import torch

if is_vision_available():
    from PIL import Image

    from transformers import SwinaSRImageProcessor
    from transformers.image_transforms import get_image_size







class 					lowerCAmelCase__	(    unittest.TestCase):




     '''simple docstring'''


     def __init__(						self			,						__lowerCamelCase			,						__lowerCamelCase=7			,						__lowerCamelCase=3			,						__lowerCamelCase=1_8			,						__lowerCamelCase=3_0			,						__lowerCamelCase=4_0_0			,						__lowerCamelCase=True			,						__lowerCamelCase=1 / 2_5_5			,						__lowerCamelCase=True			,						__lowerCamelCase=8			,						)      ->    Optional[Any]:
            _A				:	List[str]       =			parent
            _A				:	str       =			batch_size
            _A				:	Any       =			num_channels
            _A				:	Any       =			image_size
            _A				:	Optional[int]       =			min_resolution
            _A				:	Union[str, Any]       =			max_resolution
            _A				:	Optional[Any]       =			do_rescale
            _A				:	str       =			rescale_factor
            _A				:	str       =			do_pad
            _A				:	Dict       =			pad_size


     def 			_lowerCamelCase			(						self)      ->    str:
            return {
                "do_rescale": self.do_rescale,
                "rescale_factor": self.rescale_factor,
                "do_pad": self.do_pad,
                "pad_size": self.pad_size,
            }


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase=False			,						__lowerCamelCase=False			,						__lowerCamelCase=False)      ->    str:
            assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

            if equal_resolution:
                   _A				:	List[str]       =			[]
                   for i in range(self.batch_size):
                          image_inputs.append(
                              np.random.randint(
                                  2_5_5			,						size=(self.num_channels, self.max_resolution, self.max_resolution)			,						dtype=np.uinta))
            else:
                   _A				:	List[str]       =			[]
                   for i in range(self.batch_size):
                          _A   ,      _A				:	int       =			np.random.choice(np.arange(self.min_resolution			,						self.max_resolution)			,						2)
                          image_inputs.append(np.random.randint(2_5_5			,						size=(self.num_channels, width, height)			,						dtype=np.uinta))

            if not numpify and not torchify:
                   # PIL expects the channel dimension as last dimension
                   _A				:	Optional[Any]       =			[Image.fromarray(np.moveaxis(__lowerCamelCase			,						0			,						-1)) for x in image_inputs]

            if torchify:
                   _A				:	Union[str, Any]       =			[torch.from_numpy(__lowerCamelCase) for x in image_inputs]

            return image_inputs







@require_torch
@require_vision
class 					lowerCAmelCase__	(    a					,   unittest.TestCase):




     '''simple docstring'''
     __SCREAMING_SNAKE_CASE        =			SwinaSRImageProcessor if is_vision_available() else None


     def 			_lowerCamelCase			(						self)      ->    Any:
            _A				:	int       =			SwinaSRImageProcessingTester(self)


     @property
     def 			_lowerCamelCase			(						self)      ->    Any:
            return self.image_processor_tester.prepare_image_processor_dict()


     def 			_lowerCamelCase			(						self)      ->    Union[str, Any]:
            _A				:	Tuple       =			self.image_processing_class(**self.image_processor_dict)
            self.assertTrue(hasattr(__lowerCamelCase			,						"do_rescale"))
            self.assertTrue(hasattr(__lowerCamelCase			,						"rescale_factor"))
            self.assertTrue(hasattr(__lowerCamelCase			,						"do_pad"))
            self.assertTrue(hasattr(__lowerCamelCase			,						"pad_size"))


     def 			_lowerCamelCase			(						self)      ->    Dict:
            pass


     def 			_lowerCamelCase			(						self			,						__lowerCamelCase)      ->    Tuple:
            _A   ,      _A				:	Dict       =			get_image_size(__lowerCamelCase)
            _A				:	Tuple       =			self.image_processor_tester.pad_size

            _A				:	Dict       =			(old_height // size + 1) * size - old_height
            _A				:	Any       =			(old_width // size + 1) * size - old_width
            return old_height + pad_height, old_width + pad_width


     def 			_lowerCamelCase			(						self)      ->    Dict:
            # Initialize image_processor
            _A				:	Optional[int]       =			self.image_processing_class(**self.image_processor_dict)
            # create random PIL images
            _A				:	Union[str, Any]       =			self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase)
            for image in image_inputs:
                   self.assertIsInstance(__lowerCamelCase			,						Image.Image)

            # Test not batched input
            _A				:	str       =			image_processor(image_inputs[0]			,						return_tensors="pt").pixel_values
            _A   ,      _A				:	int       =			self.calculate_expected_size(np.array(image_inputs[0]))
            self.assertEqual(
                encoded_images.shape			,						(
                    1,
                    self.image_processor_tester.num_channels,
                    expected_height,
                    expected_width,
                )			,						)


     def 			_lowerCamelCase			(						self)      ->    int:
            # Initialize image_processor
            _A				:	Any       =			self.image_processing_class(**self.image_processor_dict)
            # create random numpy tensors
            _A				:	int       =			self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase			,						numpify=__lowerCamelCase)
            for image in image_inputs:
                   self.assertIsInstance(__lowerCamelCase			,						np.ndarray)

            # Test not batched input
            _A				:	Union[str, Any]       =			image_processor(image_inputs[0]			,						return_tensors="pt").pixel_values
            _A   ,      _A				:	Union[str, Any]       =			self.calculate_expected_size(image_inputs[0])
            self.assertEqual(
                encoded_images.shape			,						(
                    1,
                    self.image_processor_tester.num_channels,
                    expected_height,
                    expected_width,
                )			,						)


     def 			_lowerCamelCase			(						self)      ->    Optional[Any]:
            # Initialize image_processor
            _A				:	str       =			self.image_processing_class(**self.image_processor_dict)
            # create random PyTorch tensors
            _A				:	Tuple       =			self.image_processor_tester.prepare_inputs(equal_resolution=__lowerCamelCase			,						torchify=__lowerCamelCase)
            for image in image_inputs:
                   self.assertIsInstance(__lowerCamelCase			,						torch.Tensor)

            # Test not batched input
            _A				:	List[str]       =			image_processor(image_inputs[0]			,						return_tensors="pt").pixel_values
            _A   ,      _A				:	List[str]       =			self.calculate_expected_size(image_inputs[0])
            self.assertEqual(
                encoded_images.shape			,						(
                    1,
                    self.image_processor_tester.num_channels,
                    expected_height,
                    expected_width,
                )			,						)
