U
    ”Ê¹jÁ  ã                   @   st   d dl Z d dlmZmZmZmZ d dlmZ d dlm	Z	m
Z
 d dlmZmZmZ G dd„ deƒZG dd	„ d	eƒZdS )
é    N)ÚAnyÚDictÚOptionalÚUnion)ÚInferenceProviderMapping)ÚRequestParametersÚ_as_dict)ÚBaseConversationalTaskÚTaskProviderHelperÚfilter_nonec                       sf   e Zd Z‡ fdd„Zeeedœdd„Zeeee	e dœdd„Z
deeef e	e ed
œdd„Z‡  ZS )ÚHyperbolicTextToImageTaskc                    s   t ƒ jdddd� d S )NÚ
hyperbolicúhttps://api.hyperbolic.xyzztext-to-image)ÚproviderÚbase_urlÚtask)ÚsuperÚ__init__)Úself©Ú	__class__© ún/var/www/html/bwave/python/venv/lib/python3.8/site-packages/huggingface_hub/inference/_providers/hyperbolic.pyr   
   s    z"HyperbolicTextToImageTask.__init__)Úmapped_modelÚapi_keyÚreturnc                 C   s   dS )Nz/v1/images/generationsr   )r   r   r   r   r   r   Ú_prepare_route   s    z(HyperbolicTextToImageTask._prepare_route)ÚinputsÚ
parametersÚprovider_mapping_infor   c                 C   sh   |j }t|ƒ}d|kr$| d¡|d< d|kr:| d¡|d< d|krJd|d< d|krZd|d< ||dœ|–S )	NZnum_inference_stepsZstepsZguidance_scaleZ	cfg_scaleÚwidthi   Úheight)ÚpromptZ
model_name)Zprovider_idr   Úpop)r   r   r   r   r   r   r   r   Ú_prepare_payload_as_dict   s    z2HyperbolicTextToImageTask._prepare_payload_as_dictN)ÚresponseÚrequest_paramsr   c                 C   s   t |ƒ}t |d d d ¡S )NZimagesr   Úimage)r   Úbase64Ú	b64decode)r   r%   r&   Zresponse_dictr   r   r   Úget_response    s    z&HyperbolicTextToImageTask.get_response)N)Ú__name__Ú
__module__Ú__qualname__r   Ústrr   r   r   r   r   r$   r   Úbytesr   r*   Ú__classcell__r   r   r   r   r   	   s     þr   c                       s&   e Zd ZdZedœ‡ fdd„Z‡  ZS )ÚHyperbolicTextGenerationTaskzf
    Special case for Hyperbolic, where text-generation task is handled as a conversational task.
    )r   c                    s   t ƒ jddd� || _d S )Nr   r   )r   r   )r   r   r   )r   r   r   r   r   r   *   s
    þz%HyperbolicTextGenerationTask.__init__)r+   r,   r-   Ú__doc__r.   r   r0   r   r   r   r   r1   %   s   r1   )r(   Útypingr   r   r   r   Zhuggingface_hub.hf_apir   Z!huggingface_hub.inference._commonr   r   Z,huggingface_hub.inference._providers._commonr	   r
   r   r   r1   r   r   r   r   Ú<module>   s   