


import argparse
import json
import os
import sys
import tempfile
import unittest
from argparse import Namespace
from dataclasses import dataclass, field
from enum import Enum
from pathlib import Path
from typing import List, Literal, Optional

import yaml

from transformers import HfArgumentParser, TrainingArguments
from transformers.hf_argparser import make_choice_type_function, string_to_bool


# Since Python 3.10, we can use the builtin `|` operator for Union types
# See PEP 604: https://peps.python.org/pep-0604
__lowerCAmelCase			=							sys.version_info >= (3, 10)




def        snake_case_					(  snake_case=None      ,							snake_case=None					)  ->    List[Any]:
       return field(default_factory=lambda: default      ,							metadata=snake_case					)





@dataclass
class   __a      :
 __lowercase			:							int
 __lowercase			:							float
 __lowercase			:							str
 __lowercase			:							bool





@dataclass
class   __a      :
 __lowercase			:							int       					=			42
 __lowercase			:							str       					=			field(default='toto'	,	metadata={'help': 'help message'}				)





@dataclass
class   __a      :
 __lowercase			:							bool       					=			False
 __lowercase			:							bool       					=			True
 __lowercase			:							Optional[bool]       					=			None





class   __a      (   __UpperCamelCase				):
 __lowercase			:							Dict       					=			'titi'
 __lowercase			:							List[str]       					=			'toto'





class   __a      (   __UpperCamelCase				):
 __lowercase			:							List[str]       					=			'titi'
 __lowercase			:							List[Any]       					=			'toto'
 __lowercase			:							Optional[Any]       					=			42





@dataclass
class   __a      :
 __lowercase			:							BasicEnum       					=			"toto"
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[Any]:




        '''simple docstring'''
        lowercase__:       Tuple        =       BasicEnum(self.foo			)





@dataclass
class   __a      :
 __lowercase			:							MixedTypeEnum       					=			"toto"
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       List[Any]        =       MixedTypeEnum(self.foo			)





@dataclass
class   __a      :
 __lowercase			:							Optional[int]       					=			None
 __lowercase			:							Optional[float]       					=			field(default=__UpperCamelCase	,	metadata={'help': 'help message'}				)
 __lowercase			:							Optional[str]       					=			None
 __lowercase			:							Optional[List[str]]       					=			list_field(default=[]				)
 __lowercase			:							Optional[List[int]]       					=			list_field(default=[]				)





@dataclass
class   __a      :
 __lowercase			:							List[int]       					=			list_field(default=[]				)
 __lowercase			:							List[int]       					=			list_field(default=[1, 2, 3]				)
 __lowercase			:							List[str]       					=			list_field(default=['Hallo', 'Bonjour', 'Hello']				)
 __lowercase			:							List[float]       					=			list_field(default=[0.1, 0.2, 0.3]				)





@dataclass
class   __a      :
 __lowercase			:							List[int]       					=			field()
 __lowercase			:							str       					=			field()
 __lowercase			:							BasicEnum       					=			field()
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    List[Any]:




        '''simple docstring'''
        lowercase__:       int        =       BasicEnum(self.required_enum			)





@dataclass
class   __a      :
 __lowercase			:							int
 __lowercase			:							"BasicEnum"       					=			field()
 __lowercase			:							"Optional[bool]"       					=			None
 __lowercase			:							"str"       					=			field(default='toto'	,	metadata={'help': 'help message'}				)
 __lowercase			:							"List[str]"       					=			list_field(default=['Hallo', 'Bonjour', 'Hello']				)


if is_python_no_less_than_3_10:





 @dataclass
 class   __a      :
  __lowercase			:							bool       					=			False
  __lowercase			:							bool       					=			True
  __lowercase			:							bool | None       					=			None





 @dataclass
 class   __a      :
  __lowercase			:							int | None       					=			None
  __lowercase			:							float | None       					=			field(default=__UpperCamelCase	,	metadata={'help': 'help message'}				)
  __lowercase			:							str | None       					=			None
  __lowercase			:							list[str] | None       					=			list_field(default=[]				)
  __lowercase			:							list[int] | None       					=			list_field(default=[]				)





class   __a      (   unittest.TestCase				):
 def 		SCREAMING_SNAKE_CASE__       (       self    ,			lowerCAmelCase__    ,			lowerCAmelCase__			) ->    Optional[int]:




        '''simple docstring'''
        self.assertEqual(len(a._actions			)    ,			len(b._actions			)			)
        for x, y in zip(a._actions    ,			b._actions			):
               lowercase__:       str        =       {k: v for k, v in vars(lowerCAmelCase__			).items() if k != 'container'}
               lowercase__:       List[str]        =       {k: v for k, v in vars(lowerCAmelCase__			).items() if k != 'container'}

               # Choices with mixed type have custom function as "type"
               # So we need to compare results directly for equality
               if xx.get('choices'    ,			lowerCAmelCase__			) and yy.get('choices'    ,			lowerCAmelCase__			):
                      for expected_choice in yy["choices"] + xx["choices"]:
                             self.assertEqual(xx['type'](lowerCAmelCase__			)    ,			yy['type'](lowerCAmelCase__			)			)
                      del xx["type"], yy["type"]

               self.assertEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Dict:




        '''simple docstring'''
        lowercase__:       List[str]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       Dict        =       argparse.ArgumentParser()
        expected.add_argument('--foo'    ,			type=lowerCAmelCase__    ,			required=lowerCAmelCase__			)
        expected.add_argument('--bar'    ,			type=lowerCAmelCase__    ,			required=lowerCAmelCase__			)
        expected.add_argument('--baz'    ,			type=lowerCAmelCase__    ,			required=lowerCAmelCase__			)
        expected.add_argument('--flag'    ,			type=lowerCAmelCase__    ,			default=lowerCAmelCase__    ,			const=lowerCAmelCase__    ,			nargs='?'			)
        self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)

        lowercase__:       Any        =       ['--foo', '1', '--baz', 'quux', '--bar', '0.5']
        ((lowercase__)      ,						):       Optional[int]        =       parser.parse_args_into_dataclasses(lowerCAmelCase__    ,			look_for_args_file=lowerCAmelCase__			)
        self.assertFalse(example.flag			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Optional[int]:




        '''simple docstring'''
        lowercase__:       List[str]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       Optional[int]        =       argparse.ArgumentParser()
        expected.add_argument('--foo'    ,			default=42    ,			type=lowerCAmelCase__			)
        expected.add_argument('--baz'    ,			default='toto'    ,			type=lowerCAmelCase__    ,			help='help message'			)
        self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Any:




        '''simple docstring'''
        lowercase__:       List[Any]        =       argparse.ArgumentParser()
        expected.add_argument('--foo'    ,			type=lowerCAmelCase__    ,			default=lowerCAmelCase__    ,			const=lowerCAmelCase__    ,			nargs='?'			)
        expected.add_argument('--baz'    ,			type=lowerCAmelCase__    ,			default=lowerCAmelCase__    ,			const=lowerCAmelCase__    ,			nargs='?'			)
        # A boolean no_* argument always has to come after its "default: True" regular counter-part
        # and its default must be set to False
        expected.add_argument('--no_baz'    ,			action='store_false'    ,			default=lowerCAmelCase__    ,			dest='baz'			)
        expected.add_argument('--opt'    ,			type=lowerCAmelCase__    ,			default=lowerCAmelCase__			)

        lowercase__:       Union[str, Any]        =       [WithDefaultBoolExample]
        if is_python_no_less_than_3_10:
               dataclass_types.append(lowerCAmelCase__			)

        for dataclass_type in dataclass_types:
               lowercase__:       int        =       HfArgumentParser(lowerCAmelCase__			)
               self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)

               lowercase__:       Any        =       parser.parse_args([]			)
               self.assertEqual(lowerCAmelCase__    ,			Namespace(foo=lowerCAmelCase__    ,			baz=lowerCAmelCase__    ,			opt=lowerCAmelCase__			)			)

               lowercase__:       Optional[Any]        =       parser.parse_args(['--foo', '--no_baz']			)
               self.assertEqual(lowerCAmelCase__    ,			Namespace(foo=lowerCAmelCase__    ,			baz=lowerCAmelCase__    ,			opt=lowerCAmelCase__			)			)

               lowercase__:       Optional[Any]        =       parser.parse_args(['--foo', '--baz']			)
               self.assertEqual(lowerCAmelCase__    ,			Namespace(foo=lowerCAmelCase__    ,			baz=lowerCAmelCase__    ,			opt=lowerCAmelCase__			)			)

               lowercase__:       Union[str, Any]        =       parser.parse_args(['--foo', 'True', '--baz', 'True', '--opt', 'True']			)
               self.assertEqual(lowerCAmelCase__    ,			Namespace(foo=lowerCAmelCase__    ,			baz=lowerCAmelCase__    ,			opt=lowerCAmelCase__			)			)

               lowercase__:       Union[str, Any]        =       parser.parse_args(['--foo', 'False', '--baz', 'False', '--opt', 'False']			)
               self.assertEqual(lowerCAmelCase__    ,			Namespace(foo=lowerCAmelCase__    ,			baz=lowerCAmelCase__    ,			opt=lowerCAmelCase__			)			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Tuple:




        '''simple docstring'''
        lowercase__:       List[str]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       List[Any]        =       argparse.ArgumentParser()
        expected.add_argument(
            '--foo'    ,			default='toto'    ,			choices=['titi', 'toto', 42]    ,			type=make_choice_type_function(['titi', 'toto', 42]			)    ,			)
        self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)

        lowercase__:       Optional[int]        =       parser.parse_args([]			)
        self.assertEqual(args.foo    ,			'toto'			)
        lowercase__:       List[str]        =       parser.parse_args_into_dataclasses([]			)[0]
        self.assertEqual(enum_ex.foo    ,			MixedTypeEnum.toto			)

        lowercase__:       Any        =       parser.parse_args(['--foo', 'titi']			)
        self.assertEqual(args.foo    ,			'titi'			)
        lowercase__:       Optional[Any]        =       parser.parse_args_into_dataclasses(['--foo', 'titi']			)[0]
        self.assertEqual(enum_ex.foo    ,			MixedTypeEnum.titi			)

        lowercase__:       List[str]        =       parser.parse_args(['--foo', '42']			)
        self.assertEqual(args.foo    ,			42			)
        lowercase__:       str        =       parser.parse_args_into_dataclasses(['--foo', '42']			)[0]
        self.assertEqual(enum_ex.foo    ,			MixedTypeEnum.fourtytwo			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Tuple:




        '''simple docstring'''





        @dataclass
        class   __a      :
         __lowercase			:							Literal["titi", "toto", 42]       					=			"toto"





        lowercase__:       Optional[Any]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       Optional[Any]        =       argparse.ArgumentParser()
        expected.add_argument(
            '--foo'    ,			default='toto'    ,			choices=('titi', 'toto', 42)    ,			type=make_choice_type_function(['titi', 'toto', 42]			)    ,			)
        self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)

        lowercase__:       Optional[int]        =       parser.parse_args([]			)
        self.assertEqual(args.foo    ,			'toto'			)

        lowercase__:       Union[str, Any]        =       parser.parse_args(['--foo', 'titi']			)
        self.assertEqual(args.foo    ,			'titi'			)

        lowercase__:       List[Any]        =       parser.parse_args(['--foo', '42']			)
        self.assertEqual(args.foo    ,			42			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Union[str, Any]:




        '''simple docstring'''
        lowercase__:       List[Any]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       str        =       argparse.ArgumentParser()
        expected.add_argument('--foo_int'    ,			nargs='+'    ,			default=[]    ,			type=lowerCAmelCase__			)
        expected.add_argument('--bar_int'    ,			nargs='+'    ,			default=[1, 2, 3]    ,			type=lowerCAmelCase__			)
        expected.add_argument('--foo_str'    ,			nargs='+'    ,			default=['Hallo', 'Bonjour', 'Hello']    ,			type=lowerCAmelCase__			)
        expected.add_argument('--foo_float'    ,			nargs='+'    ,			default=[0.1, 0.2, 0.3]    ,			type=lowerCAmelCase__			)

        self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)

        lowercase__:       List[Any]        =       parser.parse_args([]			)
        self.assertEqual(
            lowerCAmelCase__    ,			Namespace(foo_int=[]    ,			bar_int=[1, 2, 3]    ,			foo_str=['Hallo', 'Bonjour', 'Hello']    ,			foo_float=[0.1, 0.2, 0.3]			)    ,			)

        lowercase__:       Dict        =       parser.parse_args('--foo_int 1 --bar_int 2 3 --foo_str a b c --foo_float 0.1 0.7'.split()			)
        self.assertEqual(lowerCAmelCase__    ,			Namespace(foo_int=[1]    ,			bar_int=[2, 3]    ,			foo_str=['a', 'b', 'c']    ,			foo_float=[0.1, 0.7]			)			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Union[str, Any]:




        '''simple docstring'''
        lowercase__:       int        =       argparse.ArgumentParser()
        expected.add_argument('--foo'    ,			default=lowerCAmelCase__    ,			type=lowerCAmelCase__			)
        expected.add_argument('--bar'    ,			default=lowerCAmelCase__    ,			type=lowerCAmelCase__    ,			help='help message'			)
        expected.add_argument('--baz'    ,			default=lowerCAmelCase__    ,			type=lowerCAmelCase__			)
        expected.add_argument('--ces'    ,			nargs='+'    ,			default=[]    ,			type=lowerCAmelCase__			)
        expected.add_argument('--des'    ,			nargs='+'    ,			default=[]    ,			type=lowerCAmelCase__			)

        lowercase__:       Optional[int]        =       [OptionalExample]
        if is_python_no_less_than_3_10:
               dataclass_types.append(lowerCAmelCase__			)

        for dataclass_type in dataclass_types:
               lowercase__:       Tuple        =       HfArgumentParser(lowerCAmelCase__			)

               self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)

               lowercase__:       Any        =       parser.parse_args([]			)
               self.assertEqual(lowerCAmelCase__    ,			Namespace(foo=lowerCAmelCase__    ,			bar=lowerCAmelCase__    ,			baz=lowerCAmelCase__    ,			ces=[]    ,			des=[]			)			)

               lowercase__:       Optional[Any]        =       parser.parse_args('--foo 12 --bar 3.14 --baz 42 --ces a b c --des 1 2 3'.split()			)
               self.assertEqual(lowerCAmelCase__    ,			Namespace(foo=12    ,			bar=3.1_4    ,			baz='42'    ,			ces=['a', 'b', 'c']    ,			des=[1, 2, 3]			)			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    str:




        '''simple docstring'''
        lowercase__:       str        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       List[Any]        =       argparse.ArgumentParser()
        expected.add_argument('--required_list'    ,			nargs='+'    ,			type=lowerCAmelCase__    ,			required=lowerCAmelCase__			)
        expected.add_argument('--required_str'    ,			type=lowerCAmelCase__    ,			required=lowerCAmelCase__			)
        expected.add_argument(
            '--required_enum'    ,			type=make_choice_type_function(['titi', 'toto']			)    ,			choices=['titi', 'toto']    ,			required=lowerCAmelCase__    ,			)
        self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Any:




        '''simple docstring'''
        lowercase__:       Any        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       Any        =       argparse.ArgumentParser()
        expected.add_argument('--foo'    ,			type=lowerCAmelCase__    ,			required=lowerCAmelCase__			)
        expected.add_argument(
            '--required_enum'    ,			type=make_choice_type_function(['titi', 'toto']			)    ,			choices=['titi', 'toto']    ,			required=lowerCAmelCase__    ,			)
        expected.add_argument('--opt'    ,			type=lowerCAmelCase__    ,			default=lowerCAmelCase__			)
        expected.add_argument('--baz'    ,			default='toto'    ,			type=lowerCAmelCase__    ,			help='help message'			)
        expected.add_argument('--foo_str'    ,			nargs='+'    ,			default=['Hallo', 'Bonjour', 'Hello']    ,			type=lowerCAmelCase__			)
        self.argparsersEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Any:




        '''simple docstring'''
        lowercase__:       Union[str, Any]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       List[Any]        =       {
            'foo': 12,
            'bar': 3.1_4,
            'baz': '42',
            'flag': True,
        }

        lowercase__:       Any        =       parser.parse_dict(lowerCAmelCase__			)[0]
        lowercase__:       int        =       BasicExample(**lowerCAmelCase__			)
        self.assertEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    str:




        '''simple docstring'''
        lowercase__:       str        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       Union[str, Any]        =       {
            'foo': 12,
            'bar': 3.1_4,
            'baz': '42',
            'flag': True,
            'extra': 42,
        }

        self.assertRaises(lowerCAmelCase__    ,			parser.parse_dict    ,			lowerCAmelCase__    ,			allow_extra_keys=lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    int:




        '''simple docstring'''
        lowercase__:       Optional[Any]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       str        =       {
            'foo': 12,
            'bar': 3.1_4,
            'baz': '42',
            'flag': True,
        }
        with tempfile.TemporaryDirectory() as tmp_dir:
               lowercase__:       Any        =       os.path.join(lowerCAmelCase__    ,			'temp_json'			)
               os.mkdir(lowerCAmelCase__			)
               with open(temp_local_path + '.json'    ,			'w+'			) as f:
                      json.dump(lowerCAmelCase__    ,			lowerCAmelCase__			)
               lowercase__:       Any        =       parser.parse_yaml_file(Path(temp_local_path + '.json'			)			)[0]

        lowercase__:       List[Any]        =       BasicExample(**lowerCAmelCase__			)
        self.assertEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    str:




        '''simple docstring'''
        lowercase__:       List[Any]        =       HfArgumentParser(lowerCAmelCase__			)

        lowercase__:       Union[str, Any]        =       {
            'foo': 12,
            'bar': 3.1_4,
            'baz': '42',
            'flag': True,
        }
        with tempfile.TemporaryDirectory() as tmp_dir:
               lowercase__:       Tuple        =       os.path.join(lowerCAmelCase__    ,			'temp_yaml'			)
               os.mkdir(lowerCAmelCase__			)
               with open(temp_local_path + '.yaml'    ,			'w+'			) as f:
                      yaml.dump(lowerCAmelCase__    ,			lowerCAmelCase__			)
               lowercase__:       Any        =       parser.parse_yaml_file(Path(temp_local_path + '.yaml'			)			)[0]
        lowercase__:       Any        =       BasicExample(**lowerCAmelCase__			)
        self.assertEqual(lowerCAmelCase__    ,			lowerCAmelCase__			)
 def 		SCREAMING_SNAKE_CASE__       (       self			) ->    Tuple:




        '''simple docstring'''
        lowercase__:       Dict        =       HfArgumentParser(lowerCAmelCase__			)
        self.assertIsNotNone(lowerCAmelCase__			)






import torch

from diffusers import StableDiffusionPipeline


__lowerCAmelCase			=							'''path-to-your-trained-model'''
__lowerCAmelCase			=							StableDiffusionPipeline.from_pretrained(model_id, torch_dtype=torch.floataa).to('''cuda''')

__lowerCAmelCase			=							'''A photo of sks dog in a bucket'''
__lowerCAmelCase			=							pipe(prompt, num_inference_steps=50, guidance_scale=7.5).images[0]

image.save('''dog-bucket.png''')


