§
    «˜ºhƒ   ã                   ó¬   — d dl Z d dl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mZmZmZmZ ddlmZ  ej        e¦  «        Zg d¢Z G d	„ d
¦  «        ZdS )é    N)ÚAnyÚDictÚListÚOptionalÚUnioné   )Ú	constants)ÚHfApi)Úbuild_hf_headersÚget_sessionÚis_pillow_availableÚloggingÚvalidate_hf_hub_args)Ú_deprecate_method)ztext-classificationztoken-classificationztable-question-answeringzquestion-answeringzzero-shot-classificationÚtranslationÚsummarizationÚconversationalzfeature-extractionztext-generationztext2text-generationz	fill-maskzsentence-similarityztext-to-speechzautomatic-speech-recognitionzaudio-to-audiozaudio-classificationzvoice-activity-detectionzimage-classificationzobject-detectionzimage-segmentationztext-to-imagezimage-to-imageztabular-classificationztabular-regressionc                   ó  — e Zd ZdZe edd¬¦  «        	 	 	 ddedee         d	ee         d
efd„¦   «         ¦   «         Z	d„ Z
	 	 	 	 ddeeeeee         eee                  f                  dee         dee         dedef
d„ZdS )ÚInferenceApia­  Client to configure requests and make calls to the HuggingFace Inference API.

    Example:

    ```python
    >>> from huggingface_hub.inference_api import InferenceApi

    >>> # Mask-fill example
    >>> inference = InferenceApi("bert-base-uncased")
    >>> inference(inputs="The goal of life is [MASK].")
    [{'sequence': 'the goal of life is life.', 'score': 0.10933292657136917, 'token': 2166, 'token_str': 'life'}]

    >>> # Question Answering example
    >>> inference = InferenceApi("deepset/roberta-base-squad2")
    >>> inputs = {
    ...     "question": "What's my name?",
    ...     "context": "My name is Clara and I live in Berkeley.",
    ... }
    >>> inference(inputs)
    {'score': 0.9326569437980652, 'start': 11, 'end': 16, 'answer': 'Clara'}

    >>> # Zero-shot example
    >>> inference = InferenceApi("typeform/distilbert-base-uncased-mnli")
    >>> inputs = "Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!"
    >>> params = {"candidate_labels": ["refund", "legal", "faq"]}
    >>> inference(inputs, params)
    {'sequence': 'Hi, I recently bought a device from your company but it is not working as advertised and I would like to get reimbursed!', 'labels': ['refund', 'faq', 'legal'], 'scores': [0.9378499388694763, 0.04914155602455139, 0.013008488342165947]}

    >>> # Overriding configured task
    >>> inference = InferenceApi("bert-base-uncased", task="feature-extraction")

    >>> # Text-to-image
    >>> inference = InferenceApi("stabilityai/stable-diffusion-2-1")
    >>> inference("cat")
    <PIL.PngImagePlugin.PngImageFile image (...)>

    >>> # Return as raw response to parse the output yourself
    >>> inference = InferenceApi("mio/amadeus")
    >>> response = inference("hello world", raw_response=True)
    >>> response.headers
    {"Content-Type": "audio/flac", ...}
    >>> response.content # raw bytes from server
    b'(...)'
    ```
    z1.0zù`InferenceApi` client is deprecated in favor of the more feature-complete `InferenceClient`. Check out this guide to learn how to convert your script to use it: https://huggingface.co/docs/huggingface_hub/guides/inference#legacy-inferenceapi-client.)ÚversionÚmessageNFÚrepo_idÚtaskÚtokenÚgpuc                 óÈ  — d|dœ| _         t          |¬¦  «        | _        t          |¬¦  «                             |¬¦  «        }|j        s|st          d¦  «        ‚|rI||j        k    r>|t          vrt          d|› d�¦  «        ‚t           	                    d¦  «         || _
        n|j        €
J d
¦   «         ‚|j        | _
        t          j        › d| j
        › d|› �| _        d	S )ak  Inits headers and API call information.

        Args:
            repo_id (``str``):
                Id of repository (e.g. `user/bert-base-uncased`).
            task (``str``, `optional`, defaults ``None``):
                Whether to force a task instead of using task specified in the
                repository.
            token (`str`, `optional`):
                The API token to use as HTTP bearer authorization. This is not
                the authentication token. You can find the token in
                https://huggingface.co/settings/token. Alternatively, you can
                find both your organizations and personal API tokens using
                `HfApi().whoami(token)`.
            gpu (`bool`, `optional`, defaults `False`):
                Whether to use GPU instead of CPU for inference(requires Startup
                plan at least).
        T)Úwait_for_modelÚuse_gpu)r   )r   z²Task not specified in the repository. Please add it to the model card using pipeline_tag (https://huggingface.co/docs#how-is-a-models-type-of-inference-api-and-widget-determined)zInvalid task z. Make sure it's valid.zlYou're using a different task than the one specified in the repository. Be sure to know what you're doing :)NzPipeline tag cannot be Nonez
/pipeline/ú/)Úoptionsr   Úheadersr
   Ú
model_infoÚpipeline_tagÚ
ValueErrorÚ	ALL_TASKSÚloggerÚwarningr   r	   ÚINFERENCE_ENDPOINTÚapi_url)Úselfr   r   r   r   r"   s         úe/var/www/html/services/rag-service/venv/lib/python3.11/site-packages/huggingface_hub/inference_api.pyÚ__init__zInferenceApi.__init__]   s  € ðD +/¸3Ð?Ð?ˆŒÝ'¨eÐ4Ñ4Ô4ˆŒõ  Ð'Ñ'Ô'×2Ò2¸7Ð2ÑCÔCˆ
ØÔ&ð 	¨tð 	Ýðmñô ð ð ð 	0�D˜JÔ3Ò3Ð3Ø�9Ð$Ð$Ý Ð!N°Ð!NÐ!NÐ!NÑOÔOÐOå�NŠNðDñô ð ð ˆDŒIˆIàÔ*Ð6Ð6Ð8UÑ6Ô6Ð6Ø"Ô/ˆDŒIå#Ô6ÐWÐWÀ$Ä)ÐWÐWÈgÐWÐWˆŒˆˆó    c                 ó8   — d| j         › d| j        › d| j        › d�S )NzInferenceAPI(api_url='z	', task='z', options=ú))r)   r   r    )r*   s    r+   Ú__repr__zInferenceApi.__repr__š   s+   € àd¨¬ÐdÐd¸t¼yÐdÐdÐUYÔUaÐdÐdÐdÐdr-   ÚinputsÚparamsÚdataÚraw_responseÚreturnc                 ó   — d| j         i}|r||d<   |r||d<   t          ¦   «                              | j        | j        ||¬¦  «        }|r|S |j                             d¦  «        pd}|                     d¦  «        rXt          ¦   «         st          d| j	        › d	�¦  «        ‚d
dl
m} |                     t          j        |j        ¦  «        ¦  «        S |dk    r|                     ¦   «         S t#          |› d�¦  «        ‚)a
  Make a call to the Inference API.

        Args:
            inputs (`str` or `Dict` or `List[str]` or `List[List[str]]`, *optional*):
                Inputs for the prediction.
            params (`Dict`, *optional*):
                Additional parameters for the models. Will be sent as `parameters` in the
                payload.
            data (`bytes`, *optional*):
                Bytes content of the request. In this case, leave `inputs` and `params` empty.
            raw_response (`bool`, defaults to `False`):
                If `True`, the raw `Response` object is returned. You can parse its content
                as preferred. By default, the content is parsed into a more practical format
                (json dictionary or PIL Image for example).
        r    r1   Ú
parameters)r!   Újsonr3   zContent-TypeÚ ÚimagezTask 'z·' returned as image but Pillow is not installed. Please install it (`pip install Pillow`) or pass `raw_response=True` to get the raw `Response` object and parse the image by yourself.r   )ÚImagezapplication/jsonzˆ output type is not implemented yet. You can pass `raw_response=True` to get the raw `Response` object and parse the output by yourself.)r    r   Úpostr)   r!   ÚgetÚ
startswithr   ÚImportErrorr   ÚPILr;   ÚopenÚioÚBytesIOÚcontentr8   ÚNotImplementedError)	r*   r1   r2   r3   r4   ÚpayloadÚresponseÚcontent_typer;   s	            r+   Ú__call__zInferenceApi.__call__ž   sJ  € ð0 �t”|ð#
ˆð ð 	'Ø &ˆG�HÑØð 	+Ø$*ˆG�LÑ!õ ‘=”=×%Ò% d¤l¸D¼LÈwÐ]aÐ%ÑbÔbˆð ð 	ØˆOð  Ô'×+Ò+¨NÑ;Ô;ÐA¸rˆØ×"Ò" 7Ñ+Ô+ð 	Ý&Ñ(Ô(ð Ý!ð.˜TœYð .ð .ð .ñô ð ð "Ð!Ð!Ð!Ð!Ð!à—:’:�bœj¨Ô)9Ñ:Ô:Ñ;Ô;Ð;ØÐ/Ò/Ð/Ø—=’=‘?”?Ð"å%Øð 'ð 'ð 'ñô ð r-   )NNF)NNNF)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Ústrr   Úboolr,   r0   r   r   r   Úbytesr   rI   © r-   r+   r   r   .   sB  € € € € € ð,ð ,ð\ ØÐØðhðñ ô ð #Ø#Øð2Xð 2Xàð2Xð �sŒmð2Xð ˜Œ}ð	2Xð
 ð2Xð 2Xð 2Xñô ñ Ôð2Xðheð eð eð JNØ!%Ø $Ø"ð;ð ;à˜˜s D¨$¨s¬)°T¸$¸s¼)´_ÐDÔEÔFð;ð ˜”ð;ð �uŒoð	;ð
 ð;ð 
ð;ð ;ð ;ð ;ð ;ð ;r-   r   )rB   Útypingr   r   r   r   r   r9   r	   Úhf_apir
   Úutilsr   r   r   r   r   Úutils._deprecationr   Ú
get_loggerrJ   r&   r%   r   rQ   r-   r+   ú<module>rW      sú   ðØ 	€	€	€	Ø 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3Ð 3à Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð Ø dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dÐ dØ 1Ð 1Ð 1Ð 1Ð 1Ð 1ð 
ˆÔ	˜HÑ	%Ô	%€ðð ð €	ðBkð kð kð kð kñ kô kð kð kð kr-   