






'''simple docstring'''





import json
import os
import tempfile
import unittest

from transformers.modelcard import ModelCard


class 				snake_case__     (			unittest.TestCase):




					def 						A     (       self       :						List[Any]     )  ->    Dict:
								UpperCAmelCase_     :   Any       =   {
								    '''model_details''': {
								        '''Organization''': '''testing''',
								        '''Model date''': '''today''',
								        '''Model version''': '''v2.1, Developed by Test Corp in 2019.''',
								        '''Architecture''': '''Convolutional Neural Network.''',
								    },
								    '''metrics''': '''BLEU and ROUGE-1''',
								    '''evaluation_data''': {
								        '''Datasets''': {'''BLEU''': '''My-great-dataset-v1''', '''ROUGE-1''': '''My-short-dataset-v2.1'''},
								        '''Preprocessing''': '''See details on https://arxiv.org/pdf/1810.03993.pdf''',
								    },
								    '''training_data''': {
								        '''Dataset''': '''English Wikipedia dump dated 2018-12-01''',
								        '''Preprocessing''': (
								            '''Using SentencePiece vocabulary of size 52k tokens. See details on'''
								            ''' https://arxiv.org/pdf/1810.03993.pdf'''
								        ),
								    },
								    '''quantitative_analyses''': {'''BLEU''': 55.1, '''ROUGE-1''': 76},
								}




					def 						A     (       self       :						Union[str, Any]     )  ->    Optional[int]:
								UpperCAmelCase_     :   Optional[Any]       =   ModelCard.from_dict(self.inputs_dict     )
								self.assertTrue(hasattr(_A							,				'''model_details'''     )     )
								self.assertTrue(hasattr(_A							,				'''intended_use'''     )     )
								self.assertTrue(hasattr(_A							,				'''factors'''     )     )
								self.assertTrue(hasattr(_A							,				'''metrics'''     )     )
								self.assertTrue(hasattr(_A							,				'''evaluation_data'''     )     )
								self.assertTrue(hasattr(_A							,				'''training_data'''     )     )
								self.assertTrue(hasattr(_A							,				'''quantitative_analyses'''     )     )
								self.assertTrue(hasattr(_A							,				'''ethical_considerations'''     )     )
								self.assertTrue(hasattr(_A							,				'''caveats_and_recommendations'''     )     )




					def 						A     (       self       :						List[Any]     )  ->    List[str]:
								UpperCAmelCase_     :   Any       =   ModelCard.from_dict(self.inputs_dict     )
								UpperCAmelCase_     :   str       =   json.loads(modelcard.to_json_string()     )
								for key, value in self.inputs_dict.items():
											self.assertEqual(obj[key]							,				_A     )




					def 						A     (       self       :						List[Any]     )  ->    Optional[Any]:
								UpperCAmelCase_     :   Dict       =   ModelCard.from_dict(self.inputs_dict     )

								with tempfile.TemporaryDirectory() as tmpdirname:
											UpperCAmelCase_     :   List[Any]       =   os.path.join(_A							,				'''modelcard.json'''     )
											model_card_first.to_json_file(_A     )
											UpperCAmelCase_     :   Tuple       =   ModelCard.from_json_file(_A     )

								self.assertEqual(model_card_second.to_dict()							,				model_card_first.to_dict()     )





					def 						A     (       self       :						Optional[Any]     )  ->    List[Any]:
								UpperCAmelCase_     :   Dict       =   ModelCard.from_dict(self.inputs_dict     )

								with tempfile.TemporaryDirectory() as tmpdirname:
											model_card_first.save_pretrained(_A     )
											UpperCAmelCase_     :   Optional[Any]       =   ModelCard.from_pretrained(_A     )

								self.assertEqual(model_card_second.to_dict()							,				model_card_first.to_dict()     )










'''simple docstring'''





from __future__ import annotations

from collections import deque
from enum import Enum
from math import atana, degrees
from sys import maxsize


class 				snake_case__     (			UpperCamelCase):
					a_       =			1
					a_       =			2
					a_       =			3




					def __repr__(       self       :						str     )  ->    Optional[int]:
								return F"{self.__class__.__name__}.{self.name}"






def __UpperCAmelCase (			A			:	tuple[int, int]	,   A			:	int	,   A			:	int						)  -> float:
			UpperCAmelCase_  ,     UpperCAmelCase_     :   Any       =   point
			return degrees(atana(y - miny	,   x - minx						)						)
def __UpperCAmelCase (			A			:	tuple[int, int]	,   A			:	tuple[int, int]	,   A			:	tuple[int, int]						)  -> Direction:
			UpperCAmelCase_  ,     UpperCAmelCase_     :   Tuple       =   starting
			UpperCAmelCase_  ,     UpperCAmelCase_     :   Optional[Any]       =   via
			UpperCAmelCase_  ,     UpperCAmelCase_     :   Optional[int]       =   target
			UpperCAmelCase_     :   Optional[int]       =   degrees(atana(ya - ya	,   xa - xa						)						)
			via_angle %= 3_6_0
			UpperCAmelCase_     :   Dict       =   degrees(atana(ya - ya	,   xa - xa						)						)
			target_angle %= 3_6_0
			# t-
			#  \ \
			#   \ v
			#    \|
			#     s
			# via_angle is always lower than target_angle, if direction is left.
			# If they are same, it means they are on a same line of convex hull.
			if target_angle > via_angle:
						return Direction.left
			elif target_angle == via_angle:
						return Direction.straight
			else:
						return Direction.right







def __UpperCAmelCase (			A			:	list[tuple[int, int]]						)  -> list[tuple[int, int]]:

			if len(A						) <= 2:
						# There is no convex hull
						raise ValueError('''graham_scan: argument must contain more than 3 points.'''						)
			if len(A						) == 3:
						return points
			# find the lowest and the most left point
			UpperCAmelCase_     :   List[str]       =   0
			UpperCAmelCase_  ,     UpperCAmelCase_     :   List[Any]       =   maxsize, maxsize
			for i, point in enumerate(A						):
						UpperCAmelCase_     :   str       =   point[0]
						UpperCAmelCase_     :   List[Any]       =   point[1]
						if y < miny:
									UpperCAmelCase_     :   int       =   y
									UpperCAmelCase_     :   Dict       =   x
									UpperCAmelCase_     :   Any       =   i
						if y == miny and x < minx:
									UpperCAmelCase_     :   str       =   x
									UpperCAmelCase_     :   Optional[int]       =   i

    # remove the lowest and the most left point from points for preparing for sort
			points.pop(A						)

			UpperCAmelCase_     :   Optional[Any]       =   sorted(A	,   key=lambda A						: angle_comparer(A	,   A	,   A						)						)
			# This insert actually costs complexity,
			# and you should instead add (minx, miny) into stack later.
			# I'm using insert just for easy understanding.
			sorted_points.insert(0	,   (minx, miny)						)

			UpperCAmelCase_     :   deque[tuple[int, int]]       =   deque()
			stack.append(sorted_points[0]						)
			stack.append(sorted_points[1]						)
			stack.append(sorted_points[2]						)
			# In any ways, the first 3 points line are towards left.
			# Because we sort them the angle from minx, miny.
			UpperCAmelCase_     :   Any       =   Direction.left

			for i in range(3	,   len(A						)						):
						while True:
									UpperCAmelCase_     :   Any       =   stack[-2]
									UpperCAmelCase_     :   List[Any]       =   stack[-1]
									UpperCAmelCase_     :   Any       =   sorted_points[i]
									UpperCAmelCase_     :   Tuple       =   check_direction(A	,   A	,   A						)

									if next_direction == Direction.left:
												UpperCAmelCase_     :   Optional[Any]       =   Direction.left
												break
									if next_direction == Direction.straight:
												if current_direction == Direction.left:
															# We keep current_direction as left.
															# Because if the straight line keeps as straight,
															# we want to know if this straight line is towards left.
															break
												elif current_direction == Direction.right:
															# If the straight line is towards right,
															# every previous points on those straigh line is not convex hull.
															stack.pop()
									if next_direction == Direction.right:
												stack.pop()
						stack.append(sorted_points[i]						)
			return list(A						)


