
    eThc                        S SK r S SKrS SKrS SKrS SKJr  S SKJrJrJ	r	J
r
  S SKrS SKrSSKJr  SSKJr  SSKJrJrJrJrJrJrJrJrJrJrJr  \" 5       (       a  S SKJ r   \	" S	S
S9r!\RD                  " \#5      r$ " S S\5      r " S S
\5      r%\" \%RL                  5      \%l&        \%RL                  RN                  b5  \%RL                  RN                  RQ                  SSSS9\%RL                  l'        gg)    N)BytesIO)AnyOptionalTypeVarUnion   )custom_object_save)BatchFeature)IMAGE_PROCESSOR_NAMEPushToHubMixinadd_model_info_to_auto_map"add_model_info_to_custom_pipelinescached_file	copy_funcdownload_urlis_offline_modeis_remote_urlis_vision_availablelogging)ImageImageProcessorTypeImageProcessingMixin)boundc                       \ rS rSrSrSrg)r
   7   a  
Holds the output of the image processor specific `__call__` methods.

This class is derived from a python dictionary and can be used as a dictionary.

Args:
    data (`dict`):
        Dictionary of lists/arrays/tensors returned by the __call__ method ('pixel_values', etc.).
    tensor_type (`Union[None, str, TensorType]`, *optional*):
        You can give a tensor_type here to convert the lists of integers in PyTorch/TensorFlow/Numpy Tensors at
        initialization.
 N)__name__
__module____qualname____firstlineno____doc____static_attributes__r       Z/var/www/auris/envauris/lib/python3.13/site-packages/transformers/image_processing_base.pyr
   r
   7   s    r#   r
   c                   8   \ rS rSrSrSrS rS\4S jr\	     S!S\
\   S\\\R                  4   S	\\\\R                  4      S
\S\S\\\\4      S\S\4S jj5       rS"S\\\R                  4   S\4S jjr\	S\\\R                  4   S\\\\4   \\\4   4   4S j5       r\	S\\\4   4S j5       rS\\\4   4S jr\	S\\\R                  4   4S j5       rS\4S jrS\\\R                  4   4S jrS r\	S#S j5       rS\\\\   4   4S jrS r g)$r   G   z|
This is an image processor mixin used to provide saving/loading functionality for sequential and image feature
extractors.
Nc           
         UR                  SS5        UR                  SS5      U l        UR                  5        H  u  p# [        XU5        M     g! [         a%  n[
        R                  SU SU SU  35        UeSnAff = f)z'Set elements of `kwargs` as attributes.feature_extractor_typeNprocessor_classz
Can't set z with value z for )pop_processor_classitemssetattrAttributeErrorloggererror)selfkwargskeyvalueerrs        r$   __init__ImageProcessingMixin.__init__O   s~     	

+T2 &

+<d C ,,.JC5) ) " z#l5'tfMN	s    A
B  A;;B r)   c                     Xl         g)z%Sets processor class as an attribute.Nr+   )r1   r)   s     r$   _set_processor_class)ImageProcessingMixin._set_processor_class^   s     /r#   clspretrained_model_name_or_path	cache_dirforce_downloadlocal_files_onlytokenrevisionreturnc                     X'S'   X7S'   XGS'   XgS'   UR                  SS5      nUb+  [        R                  " S[        5        Ub  [	        S5      eUnUb  XWS	'   U R
                  " U40 UD6u  pU R                  " U	40 UD6$ )
a  
Instantiate a type of [`~image_processing_utils.ImageProcessingMixin`] from an image processor.

Args:
    pretrained_model_name_or_path (`str` or `os.PathLike`):
        This can be either:

        - a string, the *model id* of a pretrained image_processor hosted inside a model repo on
          huggingface.co.
        - a path to a *directory* containing a image processor file saved using the
          [`~image_processing_utils.ImageProcessingMixin.save_pretrained`] method, e.g.,
          `./my_model_directory/`.
        - a path or url to a saved image processor JSON *file*, e.g.,
          `./my_model_directory/preprocessor_config.json`.
    cache_dir (`str` or `os.PathLike`, *optional*):
        Path to a directory in which a downloaded pretrained model image processor should be cached if the
        standard cache should not be used.
    force_download (`bool`, *optional*, defaults to `False`):
        Whether or not to force to (re-)download the image processor files and override the cached versions if
        they exist.
    resume_download:
        Deprecated and ignored. All downloads are now resumed by default when possible.
        Will be removed in v5 of Transformers.
    proxies (`Dict[str, str]`, *optional*):
        A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
        'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
    token (`str` or `bool`, *optional*):
        The token to use as HTTP bearer authorization for remote files. If `True`, or not specified, will use
        the token generated when running `huggingface-cli login` (stored in `~/.huggingface`).
    revision (`str`, *optional*, defaults to `"main"`):
        The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
        git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
        identifier allowed by git.


        <Tip>

        To test a pull request you made on the Hub, you can pass `revision="refs/pr/<pr_number>"`.

        </Tip>

    return_unused_kwargs (`bool`, *optional*, defaults to `False`):
        If `False`, then this function returns just the final image processor object. If `True`, then this
        functions returns a `Tuple(image_processor, unused_kwargs)` where *unused_kwargs* is a dictionary
        consisting of the key/value pairs whose keys are not image processor attributes: i.e., the part of
        `kwargs` which has not been used to update `image_processor` and is otherwise ignored.
    subfolder (`str`, *optional*, defaults to `""`):
        In case the relevant files are located inside a subfolder of the model repo on huggingface.co, you can
        specify the folder name here.
    kwargs (`Dict[str, Any]`, *optional*):
        The values in kwargs of any keys which are image processor attributes will be used to override the
        loaded values. Behavior concerning key/value pairs whose keys are *not* image processor attributes is
        controlled by the `return_unused_kwargs` keyword parameter.

Returns:
    A image processor of type [`~image_processing_utils.ImageProcessingMixin`].

Examples:

```python
# We can't instantiate directly the base class *ImageProcessingMixin* so let's show the examples on a
# derived class: *CLIPImageProcessor*
image_processor = CLIPImageProcessor.from_pretrained(
    "openai/clip-vit-base-patch32"
)  # Download image_processing_config from huggingface.co and cache.
image_processor = CLIPImageProcessor.from_pretrained(
    "./test/saved_model/"
)  # E.g. image processor (or model) was saved using *save_pretrained('./test/saved_model/')*
image_processor = CLIPImageProcessor.from_pretrained("./test/saved_model/preprocessor_config.json")
image_processor = CLIPImageProcessor.from_pretrained(
    "openai/clip-vit-base-patch32", do_normalize=False, foo=False
)
assert image_processor.do_normalize is False
image_processor, unused_kwargs = CLIPImageProcessor.from_pretrained(
    "openai/clip-vit-base-patch32", do_normalize=False, foo=False, return_unused_kwargs=True
)
assert image_processor.do_normalize is False
assert unused_kwargs == {"foo": False}
```r>   r?   r@   rB   use_auth_tokenNrThe `use_auth_token` argument is deprecated and will be removed in v5 of Transformers. Please use `token` instead.V`token` and `use_auth_token` are both specified. Please set only the argument `token`.rA   )r*   warningswarnFutureWarning
ValueErrorget_image_processor_dict	from_dict)
r<   r=   r>   r?   r@   rA   rB   r2   rE   image_processor_dicts
             r$   from_pretrained$ImageProcessingMixin.from_pretrainedb   s    t ({#1 %5!"%z$4d;%MM E   l  #E#7O'*'C'CDa'lek'l$}}1<V<<r#   save_directorypush_to_hubc           	      H   UR                  SS5      nUb=  [        R                  " S[        5        UR	                  SS5      b  [        S5      eXCS'   [        R                  R                  U5      (       a  [        SU S35      e[        R                  " USS	9  U(       ar  UR                  S
S5      nUR                  SUR                  [        R                  R                  5      S   5      nU R                  " U40 UD6nU R                  U5      nU R                  b
  [!        XU S9  [        R                  R#                  U[$        5      nU R'                  U5        [(        R+                  SU 35        U(       a"  U R-                  UWWWUR	                  S5      S9  U/$ )a  
Save an image processor object to the directory `save_directory`, so that it can be re-loaded using the
[`~image_processing_utils.ImageProcessingMixin.from_pretrained`] class method.

Args:
    save_directory (`str` or `os.PathLike`):
        Directory where the image processor JSON file will be saved (will be created if it does not exist).
    push_to_hub (`bool`, *optional*, defaults to `False`):
        Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the
        repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
        namespace).
    kwargs (`Dict[str, Any]`, *optional*):
        Additional key word arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
rE   NrF   rA   rG   zProvided path (z#) should be a directory, not a fileT)exist_okcommit_messagerepo_id)configzImage processor saved in )rU   rA   )r*   rH   rI   rJ   getrK   ospathisfileAssertionErrormakedirssplitsep_create_repo_get_files_timestamps_auto_classr	   joinr   to_json_filer/   info_upload_modified_files)	r1   rQ   rR   r2   rE   rU   rV   files_timestampsoutput_image_processor_files	            r$   save_pretrained$ImageProcessingMixin.save_pretrained   s     $4d;%MM E zz'4(4 l  -7O77>>.)) ?>2BBe!fgg
NT2#ZZ(8$?NjjN,@,@,Mb,QRG'':6:G#99.I 'tDA ')ggll>CW&X#56/0K/LMN'' -jj) (  ,,,r#   c                 >   UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	S5      n	UR                  S
S5      n
UR                  SS5      nUR                  S[        5      nUR                  SS5      nUR                  SS5      nUb+  [        R                  " S[        5        Ub  [        S5      eUnSUS.nUb  XS'   [        5       (       a  U	(       d  [        R                  S5        Sn	[        U5      n[        R                  R                  U5      n[        R                  R                  U5      (       a  [        R                  R                  X5      n[        R                  R                  U5      (       a  UnSnO4[        U5      (       a  Un[!        U5      nOUn [#        UUUUUUU	UUU
US9n [)        USS9 nUR+                  5       nSSS5        [,        R.                  " W5      nU(       a  [        R                  S U 35        UU4$ [        R                  S W S!U 35        S"U;   a  [3        US"   U5      US"'   S#U;   a  [5        US#   U5      US#'   UU4$ ! [$         a    e [&         a    [%        SU SU SU S35      ef = f! , (       d  f       N= f! [,        R0                   a    [%        SU S35      ef = f)$aa  
From a `pretrained_model_name_or_path`, resolve to a dictionary of parameters, to be used for instantiating a
image processor of type [`~image_processor_utils.ImageProcessingMixin`] using `from_dict`.

Parameters:
    pretrained_model_name_or_path (`str` or `os.PathLike`):
        The identifier of the pre-trained checkpoint from which we want the dictionary of parameters.
    subfolder (`str`, *optional*, defaults to `""`):
        In case the relevant files are located inside a subfolder of the model repo on huggingface.co, you can
        specify the folder name here.
    image_processor_filename (`str`, *optional*, defaults to `"config.json"`):
        The name of the file in the model directory to use for the image processor config.

Returns:
    `Tuple[Dict, Dict]`: The dictionary(ies) that will be used to instantiate the image processor object.
r>   Nr?   Fresume_downloadproxiesrA   rE   r@   rB   	subfolder image_processor_filename_from_pipeline
_from_autorF   rG   image processor)	file_typefrom_auto_classusing_pipelinez+Offline mode: forcing local_files_only=TrueT)	r>   r?   rn   rm   r@   rA   
user_agentrB   ro   z Can't load image processor for 'z'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'z2' is the correct path to a directory containing a z fileutf-8encodingz"It looks like the config file at 'z' is not a valid JSON file.zloading configuration file z from cache at auto_mapcustom_pipelines)r*   r   rH   rI   rJ   rK   r   r/   rf   strrZ   r[   isdirrd   r\   r   r   r   OSError	ExceptionopenreadjsonloadsJSONDecodeErrorr   r   )r<   r=   r2   r>   r?   rm   rn   rA   rE   r@   rB   ro   rq   from_pipelinerv   rx   is_localimage_processor_fileresolved_image_processor_filereadertextrN   s                         r$   rL   -ImageProcessingMixin.get_image_processor_dict  sb   ( JJ{D1	$4e< **%6=**Y-

7D)$4d;!::&8%@::j$/JJ{B/	#)::.HJ^#_ 

#3T: **\59%MM E   l  #E#4Y
$+8'(%5KKEF#(+,I(J%77==!>?77==677#%77<<0M#h 77>>788,I)H899#@ ,89V,W)#; 0;1('#1#$3%5)%'1-4		3gF&{{} G#'::d#3  KK56S5TUV $V++ KK-.B-C?SpRqr 113M(46S4$Z0 "%99;]();<>[<$%78 $V++O    67T6U V99V8W X//G.HO  GF ## 	45R4SSno 	s0   ;J: 
K8 K'*K8 :*K$'
K51K8 8$LrN   c                    UR                  5       nUR                  SS5      nSU;   a  SU;   a  UR                  S5      US'   SU;   a  SU;   a  UR                  S5      US'   U " S0 UD6n/ nUR                  5        H4  u  pg[        XF5      (       d  M  [	        XFU5        UR                  U5        M6     U H  nUR                  US5        M     [        R                  SU 35        U(       a  XB4$ U$ )a  
Instantiates a type of [`~image_processing_utils.ImageProcessingMixin`] from a Python dictionary of parameters.

Args:
    image_processor_dict (`Dict[str, Any]`):
        Dictionary that will be used to instantiate the image processor object. Such a dictionary can be
        retrieved from a pretrained checkpoint by leveraging the
        [`~image_processing_utils.ImageProcessingMixin.to_dict`] method.
    kwargs (`Dict[str, Any]`):
        Additional parameters from which to initialize the image processor object.

Returns:
    [`~image_processing_utils.ImageProcessingMixin`]: The image processor object instantiated from those
    parameters.
return_unused_kwargsFsize	crop_sizeNzImage processor r   )copyr*   r,   hasattrr-   appendr/   rf   )r<   rN   r2   r   image_processor	to_remover3   r4   s           r$   rM   ImageProcessingMixin.from_dict  s    "  488:%zz*@%H
 V*> >+1::f+= (& [4H%H06

;0G -5 45 	 ,,.JC,,e4  % ) CJJsD!  	&&789"**""r#   c                 x    [         R                  " U R                  5      nU R                  R                  US'   U$ )z
Serializes this instance to a Python dictionary.

Returns:
    `Dict[str, Any]`: Dictionary of all the attributes that make up this image processor instance.
image_processor_type)r   deepcopy__dict__	__class__r   )r1   outputs     r$   to_dictImageProcessingMixin.to_dict  s0     t}}-)-)@)@%&r#   	json_filec                     [        USS9 nUR                  5       nSSS5        [        R                  " W5      nU " S0 UD6$ ! , (       d  f       N,= f)a  
Instantiates a image processor of type [`~image_processing_utils.ImageProcessingMixin`] from the path to a JSON
file of parameters.

Args:
    json_file (`str` or `os.PathLike`):
        Path to the JSON file containing the parameters.

Returns:
    A image processor of type [`~image_processing_utils.ImageProcessingMixin`]: The image_processor object
    instantiated from that JSON file.
ry   rz   Nr   )r   r   r   r   )r<   r   r   r   rN   s        r$   from_json_file#ImageProcessingMixin.from_json_file  sG     )g.&;;=D /#zz$/*)** /.s   A
Ac                    U R                  5       nUR                  5        H8  u  p#[        U[        R                  5      (       d  M&  UR                  5       X'   M:     UR                  SS5      nUb  XAS'   [        R                  " USSS9S-   $ )z
Serializes this instance to a JSON string.

Returns:
    `str`: String containing all the attributes that make up this feature_extractor instance in JSON format.
r+   Nr)      T)indent	sort_keys
)	r   r,   
isinstancenpndarraytolistr*   r   dumps)r1   
dictionaryr3   r4   r+   s        r$   to_json_string#ImageProcessingMixin.to_json_string  s}     \\^
$**,JC%,,"',,.
 - &>>*<dC',<()zz*Q$?$FFr#   json_file_pathc                     [        USSS9 nUR                  U R                  5       5        SSS5        g! , (       d  f       g= f)z
Save this instance to a JSON file.

Args:
    json_file_path (`str` or `os.PathLike`):
        Path to the JSON file in which this image_processor instance's parameters will be saved.
wry   rz   N)r   writer   )r1   r   writers      r$   re   !ImageProcessingMixin.to_json_file  s3     .#8FLL,,./ 988s	    5
Ac                 T    U R                   R                   SU R                  5        3$ )N )r   r   r   )r1   s    r$   __repr__ImageProcessingMixin.__repr__  s(    ..))*!D,?,?,A+BCCr#   c                     [        U[        5      (       d  UR                  nSSKJs  Jn  [        X!5      (       d  [        U S35      eXl        g)a  
Register this class with a given auto class. This should only be used for custom image processors as the ones
in the library are already mapped with `AutoImageProcessor `.

<Tip warning={true}>

This API is experimental and may have some slight breaking changes in the next releases.

</Tip>

Args:
    auto_class (`str` or `type`, *optional*, defaults to `"AutoImageProcessor "`):
        The auto class to register this new image processor with.
r   Nz is not a valid auto class.)	r   r~   r   transformers.models.automodelsautor   rK   rc   )r<   
auto_classauto_modules      r$   register_for_auto_class,ImageProcessingMixin.register_for_auto_class  sE      *c**#,,J66{//
|+FGHH$r#   image_url_or_urlsc                 v   SS0n[        U[        5      (       a!  U Vs/ s H  o0R                  U5      PM     sn$ [        U[        5      (       aO  [        R
                  " USUS9nUR                  5         [        R                  " [        UR                  5      5      $ [        S[        U5       35      es  snf )z
Convert a single or a list of urls into the corresponding `PIL.Image` objects.

If a single url is passed, the return value will be a single object. If a list is passed a list of objects is
returned.
z
User-AgentzuMozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36T)streamheadersz=only a single or a list of entries is supported but got type=)r   listfetch_imagesr~   requestsrY   raise_for_statusr   r   r   content	TypeErrortype)r1   r   r   xresponses        r$   r   !ImageProcessingMixin.fetch_images  s     !
 '..2CD2CQ%%a(2CDD)3//||$5dGTH%%'::gh&6&6788[\`ar\s[tuvv Es   B6r9   )NFFNmain)F)AutoImageProcessor)!r   r   r   r    r!   rc   r6   r~   r:   classmethodr   r   r   rZ   PathLiker   boolrO   rj   tupledictr   rL   rM   r   r   r   re   r   r   r   r   r"   r   r#   r$   r   r   G   s   
 K0C 0  8<$!&,0o=$%o=',S"++-='>o= E#r{{"234o= 	o=
 o= c4i()o= o= 
o= o=b;-eC4D.E ;-TX ;-z v,,1#r{{2B,Cv,	tCH~tCH~-	.v, v,p *#T#s(^ *# *#X
c3h 
 +uS"++-='> + +$G G*	05bkk1A+B 	0D % %2weCcN.C wr#   rt   r   zimage processor file)objectobject_classobject_files))r   r   rZ   rH   ior   typingr   r   r   r   numpyr   r   dynamic_module_utilsr	   feature_extraction_utilsr
   BaseBatchFeatureutilsr   r   r   r   r   r   r   r   r   r   r   PILr   r   
get_loggerr   r/   r   rR   r!   formatr   r#   r$   <module>r      s       	   0 0   4 F     19OP  
		H	%
#  `w> `wF $--A-M-M#N   ##++7/C/O/O/W/W/^/^ /CRh 0_ 0$$, 8r#   