Ë
    ÛÓ^jäO  ã                   óŠ  — U d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	m
Z
mZ ddlmZmZmZmZmZmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZm Z m!Z!  ejD                  e#«      Z$er e«       Zee%e&e%dz  e%dz  f   f   e'd<   n eg d¢«      Z( ejR                  e(«        ejT                  «       D ]  \  Z+Z,e,Z- e«       sdZ-e-ee+<   Œ  eee«      Z.de%fd„Z/	 	 	 	 	 	 d de%ej`                  z  de%ej`                  z  dz  de1de2e%e%f   dz  de1e%z  dz  de%dz  de1fd„Z3 ed¬«       G d„ d«      «       Z4ddgZ5y)!zAutoVideoProcessor class.é    N)ÚOrderedDict)ÚTYPE_CHECKINGé   )ÚPreTrainedConfig)Úget_class_from_dynamic_moduleÚresolve_trust_remote_code)ÚCONFIG_NAMEÚIMAGE_PROCESSOR_NAMEÚPROCESSOR_NAMEÚVIDEO_PROCESSOR_NAMEÚcached_fileÚis_torchvision_availableÚloggingÚsafe_load_json_file)Úrequires)ÚBaseVideoProcessoré   )Ú_LazyAutoMapping)ÚVIDEO_PROCESSOR_MAPPING_NAMES)ÚCONFIG_MAPPING_NAMESÚ
AutoConfigÚmodel_type_to_module_nameÚ!replace_list_option_in_docstringsr   ))Úcosmos3_omniÚQwen3VLVideoProcessor)Ú	exaone4_5ÚQwen2VLVideoProcessor)ÚinstructblipÚInstructBlipVideoVideoProcessor)Úpe_audio_videoÚPeVideoVideoProcessor)Úqwen2_5_omnir   )Ú
qwen2_5_vlr   )Úqwen3_5r   )Úqwen3_5_moer   )Úqwen3_omni_moer   )Úqwen3_vl_moer   )Ú
videoprismÚLlavaOnevisionVideoProcessorÚ
class_namec                 ó’  — t        j                  «       D ]=  \  }}| |k(  sŒt        |«      }t        j                  d|› �d«      }	 t        || «      c S  t        j                  j                  «       D ]  }t        |dd «      | k(  sŒ|c S  t        j                  d«      }t        || «      rt        || «      S y # t        $ r Y Œ°w xY w)Nú.ztransformers.modelsÚ__name__Útransformers)r   Úitemsr   Ú	importlibÚimport_moduleÚgetattrÚAttributeErrorÚVIDEO_PROCESSOR_MAPPINGÚ_extra_contentÚvaluesÚhasattr)r*   Úmodule_nameÚ	extractorÚmoduleÚmain_modules        úy/var/www/ramen.bs-engineer-server.com/venv/lib/python3.12/site-packages/transformers/models/auto/video_processing_auto.pyÚvideo_processor_class_from_namer=   T   sÔ   € Ü"?×"EÑ"EÓ"Gò Ñˆ�YØ˜Ó"Ü3°KÓ@ˆKä×,Ñ,¨q°°Ð->Ð@UÓVˆFðÜ˜v zÓ2Ò2ðô -×;Ñ;×BÑBÓDò ˆ	Ü�9˜j¨$Ó/°:Ó=ØÒðô ×)Ñ)¨.Ó9€KÜˆ{˜JÔ'Ü�{ JÓ/Ð/àøô "ò Ùðús   ÁB:Â:	CÃCÚpretrained_model_name_or_pathÚ	cache_dirÚforce_downloadÚproxiesÚtokenÚrevisionÚlocal_files_onlyc                 ó<  — t        | t        ||||||dd¬«
      }t        t        fD �	cg c]  }	t        | |	||||||ddd¬«      x}
	 �|
‘Œ }}	|r|d   nd}|s|st        j                  d«       i S i }|�t        |«      }d|v r|d   }|�|€t        |«      }|S c c}	w )aþ
  
    Loads the video processor configuration from a pretrained model video processor configuration.

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

            - a string, the *model id* of a pretrained model configuration hosted inside a model repo on
              huggingface.co.
            - a path to a *directory* containing a configuration file saved using the
              [`~BaseVideoProcessor.save_pretrained`] method, e.g., `./my_model_directory/`.

        cache_dir (`str` or `os.PathLike`, *optional*):
            Path to a directory in which a downloaded pretrained model configuration 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 configuration files and override the cached versions if they
            exist.
        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`, will use the token generated
            when running `hf auth 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.
        local_files_only (`bool`, *optional*, defaults to `False`):
            If `True`, will only try to load the video processor configuration from local files.

    <Tip>

    Passing `token=True` is required when you want to use a private model.

    </Tip>

    Returns:
        `Dict`: The configuration of the video processor.

    Examples:

    ```python
    # Download configuration from huggingface.co and cache.
    video_processor_config = get_video_processor_config("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")
    # This model does not have a video processor config so the result will be an empty dict.
    video_processor_config = get_video_processor_config("FacebookAI/xlm-roberta-base")

    # Save a pretrained video processor locally and you can reload its config
    from transformers import AutoVideoProcessor

    video_processor = AutoVideoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")
    video_processor.save_pretrained("video-processor-test")
    video_processor = get_video_processor_config("video-processor-test")
    ```F)	Úfilenamer?   r@   rA   rB   rC   rD   Ú _raise_exceptions_for_gated_repoÚ%_raise_exceptions_for_missing_entries)
rF   r?   r@   rA   rB   rC   rD   rG   rH   Ú'_raise_exceptions_for_connection_errorsNr   z8Could not locate the video processor configuration file.Úvideo_processor)r   r   r   r
   ÚloggerÚinfor   )r>   r?   r@   rA   rB   rC   rD   ÚkwargsÚresolved_processor_filerF   Úresolved_fileÚresolved_video_processor_filesÚresolved_video_processor_fileÚvideo_processor_dictÚprocessor_dicts                  r<   Úget_video_processor_configrT   l   s  € ôD *Ø%ÜØØ%ØØØØ)Ø).Ø.3ôÐô .Ô/CÐDö&àä(Ø-Ø!Ø#Ø-ØØØ!Ø!1Ø16Ø6;Ø8=ôð ˆMð ðò 	ð&Ð"ð &ñ( JhÐ$BÀ1Ò$EÐmqÐ!ñ )Ñ1HÜ�‰ÐNÔOØˆ	ð
 ÐØÐ*Ü,Ð-DÓEˆØ Ñ.Ø#1Ð2CÑ#DÐ à$Ð0Ð5IÐ5QÜ2Ð3PÓQÐàÐùòO&s   ¨"B)ÚvisionÚtorchvision)Úbackendsc                   óP   — e Zd ZdZd„ Ze ee«      d„ «       «       Ze		 dd„«       Z
y)ÚAutoVideoProcessora%  
    This is a generic video processor class that will be instantiated as one of the video processor classes of the
    library when created with the [`AutoVideoProcessor.from_pretrained`] class method.

    This class cannot be instantiated directly using `__init__()` (throws an error).
    c                 ó   — t        d«      ‚)Nz‡AutoVideoProcessor is designed to be instantiated using the `AutoVideoProcessor.from_pretrained(pretrained_model_name_or_path)` method.)ÚOSError)Úselfs    r<   Ú__init__zAutoVideoProcessor.__init__í   s   € Üðdó
ð 	
ó    c                 ó’  — |j                  dd«      }|j                  dd«      }d|d<   t        j                  |fi |¤Ž\  }}|j                  dd«      }d}	d|j                  di «      v r|d   d   }	|€c|	€a|j                  d	d«      }
|
�|
j	                  d
d«      }t        |«      �|}d|j                  di «      v r|d   d   }|j	                  d
d«      }	|€_	 t        |t        «      st        j                  |fd|i|¤Ž}t        |dd«      }t        |d«      rd|j                  v r|j                  d   }	|�t        |«      }|	du}|duxs t        |«      t        v }|xr0 |xs t        t        |«         j                   j#                  d«       }|r*d|	v r|	j%                  d«      d   }nd}t'        |||||«      }|rK|rI|sG|	}t)        ||fi |¤Ž}|j                  dd«      }|j+                  «         |j                  |g|¢­i |¤ŽS |� |j                  |g|¢­i |¤ŽS t        |«      t        v r*t        t        |«         }|� |j                  |g|¢­i |¤ŽS t-        «       st        |› d�«      ‚t        d|› dt.        › dt0        › dt0        › ddj3                  d„ t4        D «       «      › �
«      ‚# t        $ r Y �ŒŒw xY w)a   
        Instantiate one of the video processor classes of the library from a pretrained model vocabulary.

        The video processor class to instantiate is selected based on the `model_type` property of the config object
        (either passed as an argument or loaded from `pretrained_model_name_or_path` if possible), or when it's
        missing, by falling back to using pattern matching on `pretrained_model_name_or_path`:

        List options

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

                - a string, the *model id* of a pretrained video_processor hosted inside a model repo on
                  huggingface.co.
                - a path to a *directory* containing a video processor file saved using the
                  [`~video_processing_utils.BaseVideoProcessor.save_pretrained`] method, e.g.,
                  `./my_model_directory/`.
                - a path to a saved video 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 video 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 video processor files and override the cached versions if
                they exist.
            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`, will use the token generated
                when running `hf auth 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.
            return_unused_kwargs (`bool`, *optional*, defaults to `False`):
                If `False`, then this function returns just the final video processor object. If `True`, then this
                functions returns a `Tuple(video_processor, unused_kwargs)` where *unused_kwargs* is a dictionary
                consisting of the key/value pairs whose keys are not video processor attributes: i.e., the part of
                `kwargs` which has not been used to update `video_processor` and is otherwise ignored.
            trust_remote_code (`bool`, *optional*, defaults to `False`):
                Whether or not to allow for custom models defined on the Hub in their own modeling files. This option
                should only be set to `True` for repositories you trust and in which you have read the code, as it will
                execute code present on the Hub on your local machine.
            kwargs (`dict[str, Any]`, *optional*):
                The values in kwargs of any keys which are video processor attributes will be used to override the
                loaded values. Behavior concerning key/value pairs whose keys are *not* video processor attributes is
                controlled by the `return_unused_kwargs` keyword parameter.

        <Tip>

        Passing `token=True` is required when you want to use a private model.

        </Tip>

        Examples:

        ```python
        >>> from transformers import AutoVideoProcessor

        >>> # Download video processor from huggingface.co and cache.
        >>> video_processor = AutoVideoProcessor.from_pretrained("llava-hf/llava-onevision-qwen2-0.5b-ov-hf")

        >>> # If video processor files are in a directory (e.g. video processor was saved using *save_pretrained('./test/saved_model/')*)
        >>> # video_processor = AutoVideoProcessor.from_pretrained("./test/saved_model/")
        ```ÚconfigNÚtrust_remote_codeTÚ
_from_autoÚvideo_processor_typerY   Úauto_mapÚimage_processor_typeÚImageProcessorÚVideoProcessorÚAutoImageProcessorztransformers.z--r   Úcode_revisionzT requires `torchvision` to be installed. Please install `torchvision` and try again.z Unrecognized video processor in z2. Should have a `video_processor_type` key in its z of z3, or one of the following `model_type` keys in its z: z, c              3   ó    K  — | ]  }|–— Œ y ­w)N© )Ú.0Úcs     r<   ú	<genexpr>z5AutoVideoProcessor.from_pretrained.<locals>.<genexpr>‹  s   è ø€ Ò@jÀqÄÑ@jùs   ‚)Úpopr   Úget_video_processor_dictÚgetÚreplacer=   Ú
isinstancer   r   Úfrom_pretrainedr2   r7   rd   Ú
ValueErrorÚtyper4   Ú
__module__Ú
startswithÚsplitr   r   Úregister_for_auto_classr   r   r	   Újoinr   )Úclsr>   ÚinputsrM   r`   ra   Úconfig_dictÚ_Úvideo_processor_classÚvideo_processor_auto_mapÚimage_processor_classÚvideo_processor_class_inferredÚimage_processor_auto_mapÚhas_remote_codeÚhas_local_codeÚexplicit_local_codeÚupstream_repoÚ	class_refs                     r<   rt   z"AutoVideoProcessor.from_pretrainedó   s‡  € ðL —‘˜H dÓ+ˆØ"ŸJ™JÐ':¸DÓAÐØ#ˆˆ|Ñä+×DÑDÐEbÑmÐflÑm‰ˆ�QØ +§¡Ð0FÈÓ MÐØ#'Ð Ø ;§?¡?°:¸rÓ#BÑBØ'2°:Ñ'>Ð?SÑ'TÐ$ð !Ð(Ð-EÐ-MØ$/§O¡OÐ4JÈDÓ$QÐ!Ø$Ð0Ø1F×1NÑ1NÐO_ÐaqÓ1rÐ.ô 3Ð3QÓRÐ^Ø,JÐ)Ø# {§¡°zÀ2Ó'FÑFØ+6°zÑ+BÐCWÑ+XÐ(Ø+C×+KÑ+KÐL\Ð^nÓ+oÐ(ð !Ð(ðÜ! &Ô*:Ô;Ü'×7Ñ7Ø5ñØIZðØ^dñ�Fô
 )0°Ð8NÐPTÓ(UÐ%Ü˜6 :Ô.Ð3GÈ6Ï?É?Ñ3ZØ/5¯©Ð?SÑ/TÐ,ð !Ð,Ü$CÐDYÓ$ZÐ!à2¸$Ð>ˆØ.°dÐ:Òe¼dÀ6»lÔNeÐ>eˆØ,ò 1Ø!ÒJÔ%<¼TÀ&»\Ñ%Jß
‰*—Z‘Z Ó0ð21Ðñ ØÐ/Ñ/Ø 8× >Ñ >¸tÓ DÀQÑ G‘à $�Ü 9Ø!Ð#@À.ÐRaÐcpó!Ðñ Ñ0Ñ9LØ0ˆIÜ$AÀ)ÐMjÑ$uÐntÑ$uÐ!Ø—
‘
˜?¨DÓ1ˆAØ!×9Ñ9Ô;Ø8Ð(×8Ñ8Ð9VÐjÐY_ÒjÐciÑjÐjØ"Ð.Ø8Ð(×8Ñ8Ð9VÐjÐY_ÒjÐciÑjÐjä�&‹\Ô4Ñ4Ü$;¼DÀ»LÑ$IÐ!Ø$Ð0Ø<Ð,×<Ñ<Ð=ZÐnÐ]cÒnÐgmÑnÐnô (Ô)ÜØ0Ð1ð  2Fð  Góð ô Ø.Ð/LÐ.Mð N1Ü1EÐ0FÀdÌ;È-ð X(Ü(3 }°B°t·y±yÑ@jÔLiÔ@jÓ7jÐ6kðmó
ð 	
øôU ò ò ðús   ÃAJ9 Ê9	KËKc                 ó4   — t         j                  | ||¬«       y)a7  
        Register a new video processor for this class.

        Args:
            config_class ([`PreTrainedConfig`]):
                The configuration corresponding to the model to register.
            video_processor_class ([`BaseVideoProcessor`]):
                The video processor to register.
        )Úexist_okN)r4   Úregister)Úconfig_classr€   r‹   s      r<   rŒ   zAutoVideoProcessor.registerŽ  s   € ô 	 ×(Ñ(¨Ð7LÐW_Ð(Õ`r^   N)F)r-   rw   Ú__qualname__Ú__doc__r]   Úclassmethodr   r   rt   ÚstaticmethodrŒ   rk   r^   r<   rY   rY   ä   sM   „ ñò
ð Ù&Ð'DÓEñW
ó Fó ðW
ðr ð òaó ñar^   rY   r4   )NFNNNF)6r�   r0   ÚosÚcollectionsr   Útypingr   Úconfiguration_utilsr   Údynamic_module_utilsr   r   Úutilsr	   r
   r   r   r   r   r   r   Úutils.import_utilsr   Úvideo_processing_utilsr   Úauto_factoryr   Úauto_mappingsr   Úconfiguration_autor   r   r   r   Ú
get_loggerr-   rK   ÚstrÚtupleÚ__annotations__Ú%MISSING_VIDEO_PROCESSOR_MAPPING_NAMESÚupdater/   Ú
model_typeÚvideo_processorsÚfast_video_processor_classr4   r=   ÚPathLikeÚboolÚdictrT   rY   Ú__all__rk   r^   r<   ú<module>rª      sÙ  ðò  ã Û 	Ý #Ý  õ 4ß \÷	÷ 	ó 	õ +Ý 8Ý *Ý 8÷ó ð 
ˆ×	Ñ	˜HÓ	%€ñ ñ VaÓUbÐ! ;¨s°E¸#À¹*ÀcÈDÁjÐ:PÑ4QÐ/QÑ#RÔbñ -8ò	
ó-Ð)ð )Ð!×(Ñ(Ð)NÔOà$GÐ$A×$GÑ$GÓ$Iò KÑ €JÐ Ø!1Ðñ $Ô%Ø%)Ð"à0JÐ! *Ò-ðKñ +Ð+?ÐA^Ó_Ð ð°ó ð4 +/Ø Ø%)Ø#ØØ"ñu Ø#&¨¯©Ñ#4ðu à�R—[‘[Ñ  4Ñ'ðu ð ðu ð �#�s�(‰^˜dÑ"ð	u ð
 �#‰:˜Ñðu ð �D‰jðu ð óu ñp 
Ð,Ô-÷xað xaó .ðxaðv %Ð&:Ð
;�r^   