
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 ChineseCLIPImageProcessor







class        A_   (			unittest.TestCase   ):




	'''simple docstring'''


	def __init__(       self		,    snake_case		,    snake_case=7		,    snake_case=3		,    snake_case=18		,    snake_case=30		,    snake_case=400		,    snake_case=True		,    snake_case=None		,    snake_case=True		,    snake_case=None		,    snake_case=True		,    snake_case=[0.48_145_466, 0.4_578_275, 0.40_821_073]		,    snake_case=[0.26_862_954, 0.26_130_258, 0.27_577_711]		,    snake_case=True		,    ):
		lowercase       =    size if size is not None else {'height': 224, 'width': 224}
		lowercase       =    crop_size if crop_size is not None else {'height': 18, 'width': 18}
		lowercase       =    parent
		lowercase       =    batch_size
		lowercase       =    num_channels
		lowercase       =    image_size
		lowercase       =    min_resolution
		lowercase       =    max_resolution
		lowercase       =    do_resize
		lowercase       =    size
		lowercase       =    do_center_crop
		lowercase       =    crop_size
		lowercase       =    do_normalize
		lowercase       =    image_mean
		lowercase       =    image_std
		lowercase       =    do_convert_rgb





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		return {
		    "do_resize": self.do_resize,
		    "size": self.size,
		    "do_center_crop": self.do_center_crop,
		    "crop_size": self.crop_size,
		    "do_normalize": self.do_normalize,
		    "image_mean": self.image_mean,
		    "image_std": self.image_std,
		    "do_convert_rgb": self.do_convert_rgb,
		}





	def 	SCREAMING_SNAKE_CASE__						(       self		,    snake_case=False		,    snake_case=False		,    snake_case=False       ):
		assert not (numpify and torchify), "You cannot specify both numpy and PyTorch tensors at the same time"

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

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

		if torchify:
			lowercase       =    [torch.from_numpy(snake_case       ) for x in image_inputs]

		return image_inputs







@require_torch
@require_vision
class        A_   (			__lowerCamelCase      ,	unittest.TestCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     int							 =       ChineseCLIPImageProcessor if is_vision_available() else None





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    ChineseCLIPImageProcessingTester(self		,    do_center_crop=snake_case       )





	@property
	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		return self.image_processor_tester.prepare_image_processor_dict()





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.image_processing_class(**self.image_processor_dict       )
		self.assertTrue(hasattr(snake_case		,    'do_resize'       )       )
		self.assertTrue(hasattr(snake_case		,    'size'       )       )
		self.assertTrue(hasattr(snake_case		,    'do_center_crop'       )       )
		self.assertTrue(hasattr(snake_case		,    'center_crop'       )       )
		self.assertTrue(hasattr(snake_case		,    'do_normalize'       )       )
		self.assertTrue(hasattr(snake_case		,    'image_mean'       )       )
		self.assertTrue(hasattr(snake_case		,    'image_std'       )       )
		self.assertTrue(hasattr(snake_case		,    'do_convert_rgb'       )       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.image_processing_class.from_dict(self.image_processor_dict       )
		self.assertEqual(image_processor.size		,    {'height': 224, 'width': 224}       )
		self.assertEqual(image_processor.crop_size		,    {'height': 18, 'width': 18}       )

		lowercase       =    self.image_processing_class.from_dict(self.image_processor_dict		,    size=42		,    crop_size=84       )
		self.assertEqual(image_processor.size		,    {'shortest_edge': 42}       )
		self.assertEqual(image_processor.crop_size		,    {'height': 84, 'width': 84}       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		pass





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		# Initialize image_processing
		lowercase       =    self.image_processing_class(**self.image_processor_dict       )
		# create random PIL images
		lowercase       =    self.image_processor_tester.prepare_inputs(equal_resolution=snake_case       )
		for image in image_inputs:
			self.assertIsInstance(snake_case		,    Image.Image       )

		# Test not batched input
		lowercase       =    image_processing(image_inputs[0]		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        1,
		        self.image_processor_tester.num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )

		# Test batched
		lowercase       =    image_processing(snake_case		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        self.image_processor_tester.batch_size,
		        self.image_processor_tester.num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		# Initialize image_processing
		lowercase       =    self.image_processing_class(**self.image_processor_dict       )
		# create random numpy tensors
		lowercase       =    self.image_processor_tester.prepare_inputs(equal_resolution=snake_case		,    numpify=snake_case       )
		for image in image_inputs:
			self.assertIsInstance(snake_case		,    np.ndarray       )

		# Test not batched input
		lowercase       =    image_processing(image_inputs[0]		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        1,
		        self.image_processor_tester.num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )

		# Test batched
		lowercase       =    image_processing(snake_case		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        self.image_processor_tester.batch_size,
		        self.image_processor_tester.num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		# Initialize image_processing
		lowercase       =    self.image_processing_class(**self.image_processor_dict       )
		# create random PyTorch tensors
		lowercase       =    self.image_processor_tester.prepare_inputs(equal_resolution=snake_case		,    torchify=snake_case       )
		for image in image_inputs:
			self.assertIsInstance(snake_case		,    torch.Tensor       )

		# Test not batched input
		lowercase       =    image_processing(image_inputs[0]		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        1,
		        self.image_processor_tester.num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )

		# Test batched
		lowercase       =    image_processing(snake_case		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        self.image_processor_tester.batch_size,
		        self.image_processor_tester.num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )







@require_torch
@require_vision
class        A_   (			__lowerCamelCase      ,	unittest.TestCase   ):




	'''simple docstring'''


	_UpperCamelCase     :     Any							 =       ChineseCLIPImageProcessor if is_vision_available() else None





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    ChineseCLIPImageProcessingTester(self		,    num_channels=4		,    do_center_crop=snake_case       )
		lowercase       =    3





	@property
	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		return self.image_processor_tester.prepare_image_processor_dict()





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		lowercase       =    self.image_processing_class(**self.image_processor_dict       )
		self.assertTrue(hasattr(snake_case		,    'do_resize'       )       )
		self.assertTrue(hasattr(snake_case		,    'size'       )       )
		self.assertTrue(hasattr(snake_case		,    'do_center_crop'       )       )
		self.assertTrue(hasattr(snake_case		,    'center_crop'       )       )
		self.assertTrue(hasattr(snake_case		,    'do_normalize'       )       )
		self.assertTrue(hasattr(snake_case		,    'image_mean'       )       )
		self.assertTrue(hasattr(snake_case		,    'image_std'       )       )
		self.assertTrue(hasattr(snake_case		,    'do_convert_rgb'       )       )





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		pass





	def 	SCREAMING_SNAKE_CASE__						(       self       ):
		# Initialize image_processing
		lowercase       =    self.image_processing_class(**self.image_processor_dict       )
		# create random PIL images
		lowercase       =    self.image_processor_tester.prepare_inputs(equal_resolution=snake_case       )
		for image in image_inputs:
			self.assertIsInstance(snake_case		,    Image.Image       )

		# Test not batched input
		lowercase       =    image_processing(image_inputs[0]		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        1,
		        self.expected_encoded_image_num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )

		# Test batched
		lowercase       =    image_processing(snake_case		,    return_tensors='pt'       ).pixel_values
		self.assertEqual(
		    encoded_images.shape		,    (
		        self.image_processor_tester.batch_size,
		        self.expected_encoded_image_num_channels,
		        self.image_processor_tester.crop_size['height'],
		        self.image_processor_tester.crop_size['width'],
		    )		,    )



import pprint

import requests

UpperCAmelCase	      = '''https://zenquotes.io/api'''






def 							UpperCAmelCase_		(							):
	return requests.get(API_ENDPOINT_URL + '/today'							).json()






def 							UpperCAmelCase_		(							):
	return requests.get(API_ENDPOINT_URL + '/random'							).json()


if __name__ == "__main__":
	UpperCAmelCase	      = random_quotes()
	pprint.pprint(response)

