
    g              !       .   d dl Z d dlZd dlZd dlmZ d dl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 dd
lmZ ddlmZmZ ddlmZmZ ddlm Z m!Z! ddl"m#Z#m$Z$ ddl%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z: ddl;m<Z< ddl=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZEmFZFmGZG ddlHmIZI ddlJmKZK ddlLmMZM ddlNmOZO ddlPmQZQ ddlRmSZS ddlTmUZU ddlVmWZW ddlXmYZY dd lZm[Z[ dd!l\m]Z] dd"l^m_Z_m`Z` dd#lambZbmcZc dd$ldmeZemfZfmgZg dd%lhmiZi dd&ljmkZk dd'llmmZm dd(lnmoZompZpmqZqmrZr dd)lsmtZt dd*lumvZv dd+lwmxZx dd,lymzZzm{Z{ dd-l|m}Z} dd.l~mZ  e6            rd dlZdd/lmZmZmZmZmZmZmZmZmZmZmZ  e7            r8d dlZdd0lmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ erdd1lmZ dd2lmZ dd3lmZ  e8j        e          Zd4d5d6d7d8Zi d9e:d: e7            refnd:d;d<d=iid>d?d@e<d: e7            reefnd:d;d<dAiidBd?d7emd: e7            reefnd:d;d<dCiidDd?dEeM e6            refnd: e7            refnd:d;dFdFdGidBd?d4ei e6            refnd: e7            refnd:d;dHdHdGidDd?d5er e6            refnd: e7            refnd:d;dIdIdGidDd?dJe` e6            refnd: e7            refnd:d;dKdKdGidDd?dLec e7            refnd: e6            refnd:d;dMdMdGidDdNd6ev e7            refnd:d:d;d<dOiidBdNdPeK e7            refnd:d:d;d<dQiidBdNdReO e6            refnd: e7            refnd:d;dSdSdGidDd?dTee e6            refnd: e7            refnd:d;dUdVdGidDd?dWeg e6            refnd: e7            refnd:d;dXdXdGid;dXdXdGid;dXdXdGidYdDd?dZef e6            refnd: e7            refnd:d;dXdXdGidDd?d[ek e6            refnd: e7            refnd:d;d\d\dGidDd?d]e{ e6            refnd: e7            refnd:d^d_dGd^d_dGd`dDd?dae} e6            refnd: e7            refnd:d;dbdbdGidBd?exd: e7            refnd:d;d<dciidBd?eQ e6            refnd: e7            refnd:d;dddddGided?eS e6            refnd: e7            refnd:d;dddddGided?eUd: e7            reefnd:d;d<dfiidBd?eY e6            refnd: e7            refnd:d;dgdgdGidBd?e]d: e7            refnd:d;d<dhiidBd?ed: e7            refnd:d;d<diiidBd?eId: e7            re fnd:d;d<djiided?etd: e7            refnd:d;d<dkiidld?e[d: e7            refnd:d;d<dmiidBd?eWd: e7            re!fnd:d;d<dniided?doZ e            Z e            Z e            ZdphZdqdrhZe                                D ]\  ZZeds         dDk    r+e                    e           e                    e           <eds         dtv re                    e           \eds         duv r+e                    e           e                    e           eds         dBk    r edve dweds                     eEeex          Zdye	e         fdzZdd;ed{e
e         dyefd|Zd}edyeeeef         fd~Zd Z	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd}ed;e
eeddf                  de
eeef                  de
eee+df                  de
eeef                  de
eeef                  de
eee)f                  de
e         de
e         ded{e
eeef                  de
eeedf                  de
e         deeef         de
e         dyeBf dZdS )    N)Path)TYPE_CHECKINGAnyDictListOptionalTupleUnion)
model_info   )PretrainedConfig)get_class_from_dynamic_module)PreTrainedFeatureExtractor)BaseImageProcessor)
AutoConfig)FEATURE_EXTRACTOR_MAPPINGAutoFeatureExtractor)IMAGE_PROCESSOR_MAPPINGAutoImageProcessor)AutoModelForDepthEstimationAutoModelForImageToImage)PROCESSOR_MAPPINGAutoProcessor)TOKENIZER_MAPPINGAutoTokenizer)ProcessorMixin)PreTrainedTokenizer)CONFIG_NAMEHUGGINGFACE_CO_RESOLVE_ENDPOINTcached_fileextract_commit_hashfind_adapter_config_fileis_kenlm_availableis_offline_modeis_peft_availableis_pyctcdecode_availableis_tf_availableis_torch_availablelogging   )AudioClassificationPipeline)"AutomaticSpeechRecognitionPipeline)
ArgumentHandlerCsvPipelineDataFormatJsonPipelineDataFormatPipedPipelineDataFormatPipelinePipelineDataFormatPipelineExceptionPipelineRegistryget_default_model_and_revisioninfer_framework_load_model)DepthEstimationPipeline)!DocumentQuestionAnsweringPipeline)FeatureExtractionPipeline)FillMaskPipeline)ImageClassificationPipeline)ImageFeatureExtractionPipeline)ImageSegmentationPipeline)ImageToImagePipeline)ImageToTextPipeline)MaskGenerationPipeline)ObjectDetectionPipeline) QuestionAnsweringArgumentHandlerQuestionAnsweringPipeline)%TableQuestionAnsweringArgumentHandlerTableQuestionAnsweringPipeline)SummarizationPipelineText2TextGenerationPipelineTranslationPipeline)TextClassificationPipeline)TextGenerationPipeline)TextToAudioPipeline)AggregationStrategyNerPipeline"TokenClassificationArgumentHandlerTokenClassificationPipeline)VideoClassificationPipeline)VisualQuestionAnsweringPipeline)#ZeroShotAudioClassificationPipeline)%ZeroShotClassificationArgumentHandlerZeroShotClassificationPipeline)#ZeroShotImageClassificationPipeline)ZeroShotObjectDetectionPipeline)TFAutoModelTFAutoModelForCausalLM!TFAutoModelForImageClassificationTFAutoModelForMaskedLMTFAutoModelForQuestionAnsweringTFAutoModelForSeq2SeqLM$TFAutoModelForSequenceClassification$TFAutoModelForTableQuestionAnswering!TFAutoModelForTokenClassificationTFAutoModelForVision2Seq)TFAutoModelForZeroShotImageClassification)	AutoModelAutoModelForAudioClassificationAutoModelForCausalLMAutoModelForCTC%AutoModelForDocumentQuestionAnsweringAutoModelForImageClassificationAutoModelForImageSegmentationAutoModelForMaskedLMAutoModelForMaskGenerationAutoModelForObjectDetectionAutoModelForQuestionAnswering AutoModelForSemanticSegmentationAutoModelForSeq2SeqLM"AutoModelForSequenceClassificationAutoModelForSpeechSeq2Seq"AutoModelForTableQuestionAnsweringAutoModelForTextToSpectrogramAutoModelForTextToWaveformAutoModelForTokenClassificationAutoModelForVideoClassificationAutoModelForVision2Seq#AutoModelForVisualQuestionAnswering'AutoModelForZeroShotImageClassification#AutoModelForZeroShotObjectDetection)TFPreTrainedModel)PreTrainedModel)PreTrainedTokenizerFastztext-classificationztoken-classificationzvisual-question-answeringztext-to-audio)zsentiment-analysisnervqaztext-to-speechzaudio-classification modelpt)zsuperb/wav2vec2-base-superb-ks372e048audio)impltfr   defaulttypezautomatic-speech-recognition)zfacebook/wav2vec2-base-960h22aad52
multimodal)zsuno/bark-small1dbd7a1textzfeature-extraction)z distilbert/distilbert-base-cased6ea8117)r   r   )z:distilbert/distilbert-base-uncased-finetuned-sst-2-english714eb0f)z0dbmdz/bert-large-cased-finetuned-conll03-english4c53496zquestion-answering)z0distilbert/distilbert-base-cased-distilled-squad564e9b5ztable-question-answering)zgoogle/tapas-base-finetuned-wtqe3dde19)r   r   r   r   r   )zdandelin/vilt-b32-finetuned-vqad0a1f6azdocument-question-answering)zimpira/layoutlm-document-qabeed3c4z	fill-mask)zdistilbert/distilroberta-basefb53ab8summarization)zsshleifer/distilbart-cnn-12-6a4f8f3e)zgoogle-t5/t5-smalldf1b051translation)zgoogle-t5/t5-basea9723ea))enfr)r   de)r   roztext2text-generationztext-generation)zopenai-community/gpt2607a30dzzero-shot-classification)zfacebook/bart-large-mnlid7645e1)zFacebookAI/roberta-large-mnli2a8f12d)r   configzzero-shot-image-classification)zopenai/clip-vit-base-patch323d74acf)zlaion/clap-htsat-fusedcca9e28)zgoogle/vit-base-patch16-2243f49326image)z facebook/detr-resnet-50-panopticd53b52a)zydshieh/vit-gpt2-coco-en5bebf1e)zfacebook/detr-resnet-501d5f47b)zgoogle/owlvit-base-patch32cbc355f)zIntel/dpt-largebc15f29)z(MCG-NJU/videomae-base-finetuned-kinetics488eb9avideo)zfacebook/sam-vit-huge87aecf0)z!caidas/swin2SR-classical-sr-x2-64cee1c92)zzero-shot-audio-classificationzimage-classificationzimage-feature-extractionzimage-segmentationzimage-to-textzobject-detectionzzero-shot-object-detectionzdepth-estimationzvideo-classificationzmask-generationzimage-to-imageSpeechEncoderDecoderConfigVisionEncoderDecoderConfigVisionTextDualEncoderConfigr   >   r   r   >   r   zSUPPORTED_TASK z contains invalid type )supported_taskstask_aliasesreturnc                  4    t                                           S )z3
    Returns a list of supported task strings.
    )PIPELINE_REGISTRYget_supported_tasksr       [/var/www/html/ai-engine/env/lib/python3.11/site-packages/transformers/pipelines/__init__.pyr   r     s     00222r   tokenc                    |                     dd           }|-t          j        dt                     |t	          d          |}t                      rt          d          	 t          | |          }n$# t          $ r}t          d|           d }~ww xY w|j	        st          d|  d          t          |d	d
          d
k    rt          d|j         d          |j	        }|S )Nuse_auth_tokenrThe `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`.zMYou cannot infer task automatically within `pipeline` when using offline mode)r   z=Instantiating a pipeline without a task set raised an error: z
The model zS does not seem to have a correct `pipeline_tag` set to infer the task automaticallylibrary_nametransformersz$This model is meant to be used with z not with transformers)popwarningswarnFutureWarning
ValueErrorr$   RuntimeErrorr   	Exceptionpipeline_taggetattrr   )r   r   deprecated_kwargsr   infoetasks          r   get_taskr     s8   &**+;TBBN! A	
 	
 	
 uvvv ljkkk`%u--- ` ` `^[\^^___` 
ssss
 
 	
 t^^44FFk$BSkkklllDKs   $A6 6
B BBr   c                 6    t                               |           S )a  
    Checks an incoming task string, to validate it's correct and return the default Pipeline and Model classes, and
    default models if they exist.

    Args:
        task (`str`):
            The task defining which pipeline will be returned. Currently accepted tasks are:

            - `"audio-classification"`
            - `"automatic-speech-recognition"`
            - `"conversational"`
            - `"depth-estimation"`
            - `"document-question-answering"`
            - `"feature-extraction"`
            - `"fill-mask"`
            - `"image-classification"`
            - `"image-feature-extraction"`
            - `"image-segmentation"`
            - `"image-to-text"`
            - `"image-to-image"`
            - `"object-detection"`
            - `"question-answering"`
            - `"summarization"`
            - `"table-question-answering"`
            - `"text2text-generation"`
            - `"text-classification"` (alias `"sentiment-analysis"` available)
            - `"text-generation"`
            - `"text-to-audio"` (alias `"text-to-speech"` available)
            - `"token-classification"` (alias `"ner"` available)
            - `"translation"`
            - `"translation_xx_to_yy"`
            - `"video-classification"`
            - `"visual-question-answering"` (alias `"vqa"` available)
            - `"zero-shot-classification"`
            - `"zero-shot-image-classification"`
            - `"zero-shot-object-detection"`

    Returns:
        (normalized_task: `str`, task_defaults: `dict`, task_options: (`tuple`, None)) The normalized task name
        (removed alias and options). The actual dictionary required to initialize the pipeline and some extra task
        options for parametrized tasks like "translation_XX_to_YY"


    )r   
check_task)r   s    r   r   r     s    Z ''---r   c                 j   dd l d| vrt          d          |                     dd          }t          |t                    r|g}t          fd|D                       | d<   |                     dd          }t          |t                    r|g}t          fd|D                       | d<   | d fS )	Nr   r   zNThis model introduces a custom pipeline without specifying its implementation.r   r   c              3   8   K   | ]}t          |          V  d S Nr   .0cr   s     r   	<genexpr>z$clean_custom_task.<locals>.<genexpr>"  -      MMGL!44MMMMMMr   r   c              3   8   K   | ]}t          |          V  d S r   r   r   s     r   r   z$clean_custom_task.<locals>.<genexpr>&  r   r   )r   r   get
isinstancestrtuple)	task_infopt_class_namestf_class_namesr   s      @r   clean_custom_taskr     s    Yklll]]4,,N.#&& *()MMMMnMMMMMIdO]]4,,N.#&& *()MMMMnMMMMMIdOd?r   Tr{   rz   r   	tokenizerr|   feature_extractorimage_processor	processor	frameworkrevisionuse_fastdeviceztorch.devicetrust_remote_codemodel_kwargspipeline_classc                    |i }|                     dd          }|-t          j        dt                     |
t	          d          |}
|                     dd          }|                     dd          }||
||d}| |t          d          ||t          d	          ||t          d
          t          |t                    rt          |          }|d}t          |t                    r|}n|t          |t                    r|}t          |t                    sA|?t          |t          fddd|                    d          d|}t          ||          |d<   nt          |dd          |d<   t          |t                    r"t          j        |f| |d||}|j        |d<   n|t          |t                    rt%                      rd |                                D             }t)          ||d         |d         |d                   }|Ft+          |dd          5 }t-          j        |          }|d         }ddd           n# 1 swxY w Y   t          j        |f| |d||}|j        |d<   i }|t1          t          |di                     dk    r|j        }| v|durrt1          |          dk    r(t5          |                                          d         } n7t          dd                    |                                                     | :|8t          |t                    st          d| d          t;          ||
          } | |v rF| }t=          ||                    \  }}|)|st	          d          |d         } t?          | |fd|i|}ntA          |           \  }}}||d         }|tC          |||          \  }}!||n|!}tD          #                    d | d!| d"tH           d#| d$	           ||d<   |5t          |t                    r t          j        |fd%| i||}|j        |d<   |4d&|v rt	          d'          |tD          #                    d(           ||d&<   |Wd)|v rt	          d*          t          |t                    r*tK          tL          |          rt          tL          |          }||d)<   t          |t                    r|nd}"t          |t                    s|(|d+         |d,         d-}#tO          |f|#||| d.||\  }}|j(        }$|j(        j        |d<   tS          |$          tT          v p|$j+        du}%tS          |$          tX          v p|du}&tS          |$          tZ          v p|du}'tS          |$          t\          v p|du}(|%o|j/        }%|&o|j0        }&|'o|j1        }'|(o|j2        }(|'r|&rd}&|3|%s1|tf          vr(|$j4        j5        tl          v s|$j4        j5        tn          v rd/}%| |'s|tp          vr|$j4        j5        tn          v rd/}'| |&s|tr          vr|$j4        j5        tl          v rd/}&| tf          v rd}%| tr          v rd}&| tp          v rd}'|%r|?t          |"t                    r|"}n't          |t                    r|}ntu          d0          t          |t          tv          f          rt          |tv                    r-|d                              d1|	          }	|d         })|d         }*n,|})|<                                }*|*                     d)d           t{          j        |)f|	| d2||*}|'r|Yt          |"t                    r|"}nAt          |t                    r|}n)|t          |t|                    r|}ntu          d3          t          |t          tv          f          rt          j        |fd%| i||}|&r|?t          |"t                    r|"}n't          |t                    r|}ntu          d4          t          |t          tv          f          rt          j        |fd%| i||}|jA        rd|jA        B                    d5          rIt          |"t                    r3	 ddlC}+dd6lDmE}, t          jG        H                    |"          st          jG        I                    |"          r|,J                    |"          }-nGt          jG                            |,jK        d7          }.|,jL        }/|.|/g}0|,M                    |"|08          }-|-|d9<   n# t          $ rz}1tD          #                    d:|" d;|1            t                      stD          #                    d<           t                      stD          #                    d=           Y d}1~1nd}1~1ww xY w|(r|?t          |"t                    r|"}n't          |t                    r|}ntu          d>          t          |t          tv          f          rKt          j        |fd%| i||}t          |t                    s t          d?tS          |           d@          | dAk    rR|j(        jT        rF|j(        jT        D ]9}2|2U                    dA          r"|2} t          j        dB|  dCt                      n:|||dD<   |||dE<   |||d)<   |||dF<   |||dG<   |||dH<    |dJ||| dI|S )KaD-  
    Utility factory method to build a [`Pipeline`].

    A pipeline consists of:

        - One or more components for pre-processing model inputs, such as a [tokenizer](tokenizer),
        [image_processor](image_processor), [feature_extractor](feature_extractor), or [processor](processors).
        - A [model](model) that generates predictions from the inputs.
        - Optional post-processing steps to refine the model's output, which can also be handled by processors.

    <Tip>
    While there are such optional arguments as `tokenizer`, `feature_extractor`, `image_processor`, and `processor`,
    they shouldn't be specified all at once. If these components are not provided, `pipeline` will try to load
    required ones automatically. In case you want to provide these components explicitly, please refer to a
    specific pipeline in order to get more details regarding what components are required.
    </Tip>

    Args:
        task (`str`):
            The task defining which pipeline will be returned. Currently accepted tasks are:

            - `"audio-classification"`: will return a [`AudioClassificationPipeline`].
            - `"automatic-speech-recognition"`: will return a [`AutomaticSpeechRecognitionPipeline`].
            - `"depth-estimation"`: will return a [`DepthEstimationPipeline`].
            - `"document-question-answering"`: will return a [`DocumentQuestionAnsweringPipeline`].
            - `"feature-extraction"`: will return a [`FeatureExtractionPipeline`].
            - `"fill-mask"`: will return a [`FillMaskPipeline`]:.
            - `"image-classification"`: will return a [`ImageClassificationPipeline`].
            - `"image-feature-extraction"`: will return an [`ImageFeatureExtractionPipeline`].
            - `"image-segmentation"`: will return a [`ImageSegmentationPipeline`].
            - `"image-to-image"`: will return a [`ImageToImagePipeline`].
            - `"image-to-text"`: will return a [`ImageToTextPipeline`].
            - `"mask-generation"`: will return a [`MaskGenerationPipeline`].
            - `"object-detection"`: will return a [`ObjectDetectionPipeline`].
            - `"question-answering"`: will return a [`QuestionAnsweringPipeline`].
            - `"summarization"`: will return a [`SummarizationPipeline`].
            - `"table-question-answering"`: will return a [`TableQuestionAnsweringPipeline`].
            - `"text2text-generation"`: will return a [`Text2TextGenerationPipeline`].
            - `"text-classification"` (alias `"sentiment-analysis"` available): will return a
              [`TextClassificationPipeline`].
            - `"text-generation"`: will return a [`TextGenerationPipeline`]:.
            - `"text-to-audio"` (alias `"text-to-speech"` available): will return a [`TextToAudioPipeline`]:.
            - `"token-classification"` (alias `"ner"` available): will return a [`TokenClassificationPipeline`].
            - `"translation"`: will return a [`TranslationPipeline`].
            - `"translation_xx_to_yy"`: will return a [`TranslationPipeline`].
            - `"video-classification"`: will return a [`VideoClassificationPipeline`].
            - `"visual-question-answering"`: will return a [`VisualQuestionAnsweringPipeline`].
            - `"zero-shot-classification"`: will return a [`ZeroShotClassificationPipeline`].
            - `"zero-shot-image-classification"`: will return a [`ZeroShotImageClassificationPipeline`].
            - `"zero-shot-audio-classification"`: will return a [`ZeroShotAudioClassificationPipeline`].
            - `"zero-shot-object-detection"`: will return a [`ZeroShotObjectDetectionPipeline`].

        model (`str` or [`PreTrainedModel`] or [`TFPreTrainedModel`], *optional*):
            The model that will be used by the pipeline to make predictions. This can be a model identifier or an
            actual instance of a pretrained model inheriting from [`PreTrainedModel`] (for PyTorch) or
            [`TFPreTrainedModel`] (for TensorFlow).

            If not provided, the default for the `task` will be loaded.
        config (`str` or [`PretrainedConfig`], *optional*):
            The configuration that will be used by the pipeline to instantiate the model. This can be a model
            identifier or an actual pretrained model configuration inheriting from [`PretrainedConfig`].

            If not provided, the default configuration file for the requested model will be used. That means that if
            `model` is given, its default configuration will be used. However, if `model` is not supplied, this
            `task`'s default model's config is used instead.
        tokenizer (`str` or [`PreTrainedTokenizer`], *optional*):
            The tokenizer that will be used by the pipeline to encode data for the model. This can be a model
            identifier or an actual pretrained tokenizer inheriting from [`PreTrainedTokenizer`].

            If not provided, the default tokenizer for the given `model` will be loaded (if it is a string). If `model`
            is not specified or not a string, then the default tokenizer for `config` is loaded (if it is a string).
            However, if `config` is also not given or not a string, then the default tokenizer for the given `task`
            will be loaded.
        feature_extractor (`str` or [`PreTrainedFeatureExtractor`], *optional*):
            The feature extractor that will be used by the pipeline to encode data for the model. This can be a model
            identifier or an actual pretrained feature extractor inheriting from [`PreTrainedFeatureExtractor`].

            Feature extractors are used for non-NLP models, such as Speech or Vision models as well as multi-modal
            models. Multi-modal models will also require a tokenizer to be passed.

            If not provided, the default feature extractor for the given `model` will be loaded (if it is a string). If
            `model` is not specified or not a string, then the default feature extractor for `config` is loaded (if it
            is a string). However, if `config` is also not given or not a string, then the default feature extractor
            for the given `task` will be loaded.
        image_processor (`str` or [`BaseImageProcessor`], *optional*):
            The image processor that will be used by the pipeline to preprocess images for the model. This can be a
            model identifier or an actual image processor inheriting from [`BaseImageProcessor`].

            Image processors are used for Vision models and multi-modal models that require image inputs. Multi-modal
            models will also require a tokenizer to be passed.

            If not provided, the default image processor for the given `model` will be loaded (if it is a string). If
            `model` is not specified or not a string, then the default image processor for `config` is loaded (if it is
            a string).
        processor (`str` or [`ProcessorMixin`], *optional*):
            The processor that will be used by the pipeline to preprocess data for the model. This can be a model
            identifier or an actual processor inheriting from [`ProcessorMixin`].

            Processors are used for multi-modal models that require multi-modal inputs, for example, a model that
            requires both text and image inputs.

            If not provided, the default processor for the given `model` will be loaded (if it is a string). If `model`
            is not specified or not a string, then the default processor for `config` is loaded (if it is a string).
        framework (`str`, *optional*):
            The framework to use, either `"pt"` for PyTorch or `"tf"` for TensorFlow. The specified framework must be
            installed.

            If no framework is specified, will default to the one currently installed. If no framework is specified and
            both frameworks are installed, will default to the framework of the `model`, or to PyTorch if no model is
            provided.
        revision (`str`, *optional*, defaults to `"main"`):
            When passing a task name or a string model identifier: 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.
        use_fast (`bool`, *optional*, defaults to `True`):
            Whether or not to use a Fast tokenizer if possible (a [`PreTrainedTokenizerFast`]).
        use_auth_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 `huggingface-cli login` (stored in `~/.huggingface`).
        device (`int` or `str` or `torch.device`):
            Defines the device (*e.g.*, `"cpu"`, `"cuda:1"`, `"mps"`, or a GPU ordinal rank like `1`) on which this
            pipeline will be allocated.
        device_map (`str` or `Dict[str, Union[int, str, torch.device]`, *optional*):
            Sent directly as `model_kwargs` (just a simpler shortcut). When `accelerate` library is present, set
            `device_map="auto"` to compute the most optimized `device_map` automatically (see
            [here](https://huggingface.co/docs/accelerate/main/en/package_reference/big_modeling#accelerate.cpu_offload)
            for more information).

            <Tip warning={true}>

            Do not use `device_map` AND `device` at the same time as they will conflict

            </Tip>

        torch_dtype (`str` or `torch.dtype`, *optional*):
            Sent directly as `model_kwargs` (just a simpler shortcut) to use the available precision for this model
            (`torch.float16`, `torch.bfloat16`, ... or `"auto"`).
        trust_remote_code (`bool`, *optional*, defaults to `False`):
            Whether or not to allow for custom code defined on the Hub in their own modeling, configuration,
            tokenization or even pipeline 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.
        model_kwargs (`Dict[str, Any]`, *optional*):
            Additional dictionary of keyword arguments passed along to the model's `from_pretrained(...,
            **model_kwargs)` function.
        kwargs (`Dict[str, Any]`, *optional*):
            Additional keyword arguments passed along to the specific pipeline init (see the documentation for the
            corresponding pipeline class for possible values).

    Returns:
        [`Pipeline`]: A suitable pipeline for the task.

    Examples:

    ```python
    >>> from transformers import pipeline, AutoModelForTokenClassification, AutoTokenizer

    >>> # Sentiment analysis pipeline
    >>> analyzer = pipeline("sentiment-analysis")

    >>> # Question answering pipeline, specifying the checkpoint identifier
    >>> oracle = pipeline(
    ...     "question-answering", model="distilbert/distilbert-base-cased-distilled-squad", tokenizer="google-bert/bert-base-cased"
    ... )

    >>> # Named entity recognition pipeline, passing in a specific model and tokenizer
    >>> model = AutoModelForTokenClassification.from_pretrained("dbmdz/bert-large-cased-finetuned-conll03-english")
    >>> tokenizer = AutoTokenizer.from_pretrained("google-bert/bert-base-cased")
    >>> recognizer = pipeline("ner", model=model, tokenizer=tokenizer)
    ```Nr   r   r   code_revision_commit_hash)r   r   r   r   z}Impossible to instantiate a pipeline without either a task or a model being specified. Please provide a task class or a modela  Impossible to instantiate a pipeline with tokenizer specified but not the model as the provided tokenizer may not be compatible with the default model. Please provide a PreTrainedModel class or a path/identifier to a pretrained model when providing tokenizer.a  Impossible to instantiate a pipeline with feature_extractor specified but not the model as the provided feature_extractor may not be compatible with the default model. Please provide a PreTrainedModel class or a path/identifier to a pretrained model when providing feature_extractor.F	cache_dir) _raise_exceptions_for_gated_repo%_raise_exceptions_for_missing_entries'_raise_exceptions_for_connection_errorsr   )_from_pipeliner   c                 &    i | ]\  }}|d k    ||S )r   r   )r   kvs      r   
<dictcomp>zpipeline.<locals>.<dictcomp>6  s)    [[[DAq!GZBZBZ1aBZBZBZr   r   r   )r   r   r   rzutf-8)encodingbase_model_name_or_pathcustom_pipelinesr   r*   zhWe can't infer the task automatically for this model as there are multiple tasks available. Pick one in z, z_Inferring the task automatically requires to check the hub with a model_id defined as a `str`. z is not a valid model_id.zLoading this pipeline requires you to execute the code in the pipeline file in that repo on your local machine. Make sure you have read the code there to avoid malicious use, then set the option `trust_remote_code=True` to remove this error.r   z$No model was supplied, defaulted to z and revision z (/zb).
Using a pipeline without specifying a model name and revision in production is not recommended.r   
device_mapzYou cannot use both `pipeline(... device_map=..., model_kwargs={"device_map":...})` as those arguments might conflict, use only one.)zBoth `device` and `device_map` are specified. `device` will override `device_map`. You will most likely encounter unexpected behavior. Please remove `device` and keep `device_map`.torch_dtypezYou cannot use both `pipeline(... torch_dtype=..., model_kwargs={"torch_dtype":...})` as those arguments might conflict, use only one.)r   r   )r   r   )model_classesr   r   r   TzImpossible to guess which tokenizer to use. Please provide a PreTrainedTokenizer class or a path/identifier to a pretrained tokenizer.r   )r   r   zImpossible to guess which image processor to use. Please provide a PreTrainedImageProcessor class or a path/identifier to a pretrained image processor.zImpossible to guess which feature extractor to use. Please provide a PreTrainedFeatureExtractor class or a path/identifier to a pretrained feature extractor.WithLM)BeamSearchDecoderCTC*)allow_patternsdecoderz!Could not load the `decoder` for z . Defaulting to raw CTC. Error: z*Try to install `kenlm`: `pip install kenlmz6Try to install `pyctcdecode`: `pip install pyctcdecodeztImpossible to guess which processor to use. Please provide a processor instance or a path/identifier to a processor.zOProcessor was loaded, but it is not an instance of `ProcessorMixin`. Got type `z}` instead. Please check that you specified correct pipeline task for the model and model has processor implemented and saved.r   zO"translation" task was used, instead of "translation_XX_to_YY", defaulting to ""r   r   r   r   r   )r   r   r   r   )Wr   r   r   r   r   r   r   r   r   r   r    r   r   r!   r   r   from_pretrainedr   r%   itemsr"   openjsonloadlenr   listkeysjoinr   r   r   r   r5   loggerwarningr   hasattrtorchr6   r   r   r   tokenizer_classr   r   r   _load_tokenizer_load_feature_extractor_load_image_processor_load_processorNO_TOKENIZER_TASKS	__class____name__MULTI_MODEL_AUDIO_CONFIGSMULTI_MODEL_VISION_CONFIGSNO_IMAGE_PROCESSOR_TASKSNO_FEATURE_EXTRACTOR_TASKSr   r   copyr   r   r   r   _processor_classendswithkenlmpyctcdecoder  ospathisdirisfileload_from_dir$_LANGUAGE_MODEL_SERIALIZED_DIRECTORY_ALPHABET_SERIALIZED_FILENAMEload_from_hf_hubImportErrorr#   r&   r   r   	TypeErrortask_specific_params
startswithUserWarning)3r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   kwargsr   r   commit_hash
hub_kwargspretrained_model_name_or_pathresolved_config_file_hub_kwargsmaybe_adapter_pathfadapter_configcustom_tasksnormalized_tasktargeted_tasktask_options	class_refdefault_revision
model_namer   model_configload_tokenizerload_feature_extractorload_image_processorload_processortokenizer_identifiertokenizer_kwargsr#  r  r  language_model_globalphabet_filenamer  r   keys3                                                      r   pipelinerL  *  s>   z  "%%&6==N! A	
 	
 	
 uvvvJJ55M**^T22K .#	 J |5
 
 	
 }.O
 
 	

 }*6\
 
 	

 % E

(,%fc"" 	2,2))^
5# 6 6^,1)&"233 	O8U8a#.-$ 276;8=&**;77$ $ $ $  *==QS^)_)_J~&&)0)N)NJ~& &# 9+
#'}
 
HR
Vb
 
 &,%8
>""	Juc22 	F[[J,<,<,>,>[[[K!9 )#J/'7	" " " "-,cGDDD F%)Yq\\N*+DEEF F F F F F F F F F F F F F F +
"&m
 
GQ
Ua
 
 &,%8
>"Lc'&2Db"I"IJJQNN.<-U::<  A%%L--//003"?"ii(9(9(;(;<<? ?  
 |)%%% 	44 4 4   u%% |&7T8J&K&K#|!$  U  
 &f-I:  , 	 N 8B$7G7G4!*62N }"@PY[g"h"h'3889In5 n nn n;n n>Cn n n	
 	
 	

 "*
:>j44>/iidiji\hiiF)/)<J~&<''<   NNq   &0\"L((<   k3'' 	6GE;,G,G 	6!%55K&1]#$UC00:dJ % 

!2,T2-:MNN5
'
 
 
 
 
	5 <L!&!:J~,''+<<h@\dh@hN!,//3LLmPaimPm--1HHgOcgLg,''+<<U	QU@UN $F(FN3^8^/XN4X#F(FN  ' 6 '!& 	 	#555 "+/HHH%.2LLL $ 	 #;;;"+/III
  $!& 	"#==="+/HHH
 "&!!!
 )))!&'''$ *c** 	&		FC(( "		  q   i#u.. 	)U++ :$Q<++JAA'0|$#,Q<  '0$#/#4#4#6#6  $$]D999%5$/7 PZ^n I  "*c** ",FC(( "( #.:>OQc3d3d."3  7   oU|44 	0@ 048BFR O  /a$*c** 
$.!!FC(( $*!!  9   '#u66 	a 4 D!! !26!:D!HT! !
 "2a%6??IIa z3//a
a LLL@@@@@@w}}Z00 sBGNN:4N4N s"6"D"DZ"P"P.0gll0UWZ/ /+ -A,^)*=?P)Q"6"G"G
cq"G"r"r(/F9%%" a a aNN#vz#v#vst#v#vwww-// U'STTT355 a'_```a  *c** 
&		FC(( "		  &   i#u.. 	%5issPTsXbsfrssIi88 i!%ii i i   }!B<4 	 	C~~m,, mfjmmm    '{$&7"# +}"$3 !!x'{>PPPPPPs,   ,IIIB*e
 

gA0g		gr   )NNNNNNNNNTNNNNNNN)r
  r%  r   pathlibr   typingr   r   r   r   r   r	   r
   huggingface_hubr   configuration_utilsr   dynamic_module_utilsr   feature_extraction_utilsr   image_processing_utilsr   models.auto.configuration_autor   #models.auto.feature_extraction_autor   r   !models.auto.image_processing_autor   r   models.auto.modeling_autor   r   models.auto.processing_autor   r   models.auto.tokenization_autor   r   processing_utilsr   tokenization_utilsr   utilsr   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   audio_classificationr+   automatic_speech_recognitionr,   baser-   r.   r/   r0   r1   r2   r3   r4   r5   r6   depth_estimationr7   document_question_answeringr8   feature_extractionr9   	fill_maskr:   image_classificationr;   image_feature_extractionr<   image_segmentationr=   image_to_imager>   image_to_textr?   mask_generationr@   object_detectionrA   question_answeringrB   rC   table_question_answeringrD   rE   text2text_generationrF   rG   rH   text_classificationrI   text_generationrJ   text_to_audiorK   token_classificationrL   rM   rN   rO   video_classificationrP   visual_question_answeringrQ   zero_shot_audio_classificationrR   zero_shot_classificationrS   rT   zero_shot_image_classificationrU   zero_shot_object_detectionrV   
tensorflowr   models.auto.modeling_tf_autorW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   ra   r  rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   modeling_tf_utilsrz   modeling_utilsr{   tokenization_utils_fastr|   
get_loggerr  r  TASK_ALIASESSUPPORTED_TASKSsetr  r  r  r  r  r  r   valuesaddr   r   r   r   r   r   r   boolintrL  r   r   r   <module>r     s    				        I I I I I I I I I I I I I I I I I I & & & & & & 2 2 2 2 2 2 @ @ @ @ @ @ A A A A A A 7 7 7 7 7 7 7 7 7 7 7 7 a a a a a a a a [ [ [ [ [ [ [ [ ] ] ] ] ] ] ] ] J J J J J J J J L L L L L L L L - - - - - - 4 4 4 4 4 4                            > = = = = = L L L L L L                        6 5 5 5 5 5 J J J J J J 9 9 9 9 9 9 ' ' ' ' ' ' = = = = = = D D D D D D 9 9 9 9 9 9 0 0 0 0 0 0 . . . . . . 3 3 3 3 3 3 5 5 5 5 5 5 [ [ [ [ [ [ [ [ k k k k k k k k i i i i i i i i i i ; ; ; ; ; ; 3 3 3 3 3 3 . . . . . .            > = = = = = F F F F F F O O O O O O k k k k k k k k O O O O O O G G G G G G ?                            LLL                                                   8  B555555000000AAAAAA 
	H	%	%
 0!&%	 O+4F4F4H4HP.00bd$QRS O #2>P>P>R>RZ 9::XZd$NOP% %O #M_M_MaMai)+HIIgid$BCD O, ) / 1 19{nnr0022:yllEE 
  -OD *9H9J9JR355PR7I7I7K7KS133QS__ 
  EO\ +6Eo6G6GO022R4F4F4H4HP.00bUU 
  ]Ot )4CO4E4EM.0022D2D2F2FN,..BUU 
  uOL .7I7I7K7KS133QS9H9J9JR355PRDD 
 ! !MOd  /8J8J8L8LT244RTdJK
 " "eOv "1:L:L:N:NV466TVdFG
 $ $wOH  +:?+<+<D%''"););)=)=E#%%2BB 
  IO` %,;O,=,=E&((2*<*<*>*>F$&&BHPqrr
  aOt #,;O,=,=E&((2*<*<*>*>F$&&B"+KSs$t$tu"+KSs$t$tu"+KSs$t$tu
 

 
 
uOJ +,;O,=,=E&((2*<*<*>*>F$&&B$DLlmmn KOX &+:?+<+<D%''"););)=)=E#%%2$HPtuuv YOf .9H9J9JR355PR7I7I7K7KS133QS >B 
 >B 	
 	
 ! !gOF %3>Mo>O>OW8::UW<N<N<P<PX688VXAA 
 ' 'GO` 40022:yll;

 
' 
' ,6Eo6G6GO022R4F4F4H4HP.00b@@ 
   / / 1 19{nnr0022:yll@@ 
 ! ! *SeSeSgSgo,.NOOmod$STU  $-<_->->F'))B+=+=+?+?G%''R== 
   (0B0B0D0DL*,,"d$JKL  08J8J8L8LT244RTd$MNO# # (0B0B0D0DL*,,"d$BCD  ,4F4F4H4HP.00bd$[\]  '/A/A/C/CK)++d$HIJ  %-?-?-A-AI'))rd$TUV QO O Ob !SUU 355 SUU  :: :<YZ #))++ 
Z 
ZLD&f~"&&t,,, $$T****	-	-	-t$$$$	9	$	$t$$$ $$T****	<	'	'jX4XXvXXYYY 
( %$_S_``` 3T#Y 3 3 3 3 C  c    6-.S -.U3c>2 -. -. -. -.`  " JN59VZJN@D6:#"(,8<(,#'$(#b	Q b	Q
b	QE#02EEFGb	Q U3 0012b	Q c#68QQRS	b	Q
  c+E&E FGb	Q eC);$;<=b	Q c>123b	Q }b	Q smb	Q b	Q E#t)$%b	Q U3^345b	Q  ~b	Q  sCx.!b	Q" SM#b	Q& 'b	Q b	Q b	Q b	Q b	Q b	Qr   