U
    ·ÜŸjÆ  ã                   @  sÊ   d dl mZ d dl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 ddlmZ dd	lmZ erxd d
lmZ dddœdd„ZG dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ dƒZdS )é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚcast)ÚArgumentParseré   )Ú
get_clientÚprint_modelé   )Ú	NOT_GIVENÚNotGivenÚ
NotGivenOr)Ú	BaseModel)ÚBufferReader)Ú_SubParsersActionz!_SubParsersAction[ArgumentParser]ÚNone)Ú	subparserÚreturnc                 C  s„  |   d¡}|jddtd� |jddtdd� |jd	d
tdd� |jddtddd� |jdtdd� |jtjtd� |   d¡}|jddtd� |jddtdd� |jd	d
tdd� |jddtddd� |jddtddd� |jdtdd� |jddtddd� |jtjt	d� |   d¡}|jddtd� |jd	d
tdd� |jddtddd� |jddtddd� |jdtdd� |jtj
td� d S )Nzimages.generatez-mz--model)Útypez-pz--promptT)r   Úrequiredz-nz--num-imagesé   )r   Údefaultz-sz--sizeZ	1024x1024zSize of the output image)r   r   Úhelpz--response-formatÚurl)ÚfuncZ
args_modelzimages.editz-Iz--imagez@Image to modify. Should be a local path and a PNG encoded image.)r   r   r   z-Mz--maskFz†Path to a mask image. It should be the same size as the image you're editing and a RGBA PNG image. The Alpha channel acts as the mask.zimages.create_variation)Ú
add_parserÚadd_argumentÚstrÚintÚset_defaultsÚCLIImageÚcreateÚCLIImageCreateArgsÚeditÚCLIImageEditArgsÚcreate_variationÚCLIImageCreateVariationArgs)r   Úsub© r(   ú9/tmp/pip-unpacked-wheel-2qj3ofc_/openai/cli/_api/image.pyÚregister   sR    

ûû
ûr*   c                   @  s:   e Zd ZU ded< ded< ded< ded< eZded< d	S )
r"   r   Úpromptr   Ú
num_imagesÚsizeÚresponse_formatúNotGivenOr[str]ÚmodelN©Ú__name__Ú
__module__Ú__qualname__Ú__annotations__r   r0   r(   r(   r(   r)   r"   =   s
   
r"   c                   @  s:   e Zd ZU ded< ded< ded< ded< eZded< d	S )
r&   r   Úimager   r,   r-   r.   r/   r0   Nr1   r(   r(   r(   r)   r&   E   s
   
r&   c                   @  sN   e Zd ZU ded< ded< ded< ded< ded< eZded	< eZded
< dS )r$   r   r6   r   r,   r-   r.   r+   r/   Úmaskr0   N)r2   r3   r4   r5   r   r7   r0   r(   r(   r(   r)   r$   M   s   
r$   c                   @  sH   e Zd Zedddœdd„ƒZedddœdd„ƒZed	ddœd
d„ƒZdS )r    r"   r   )Úargsr   c                 C  s:   t ƒ jj| j| j| jtt| jƒtt| j	ƒd�}t
|ƒ d S )N)r0   r+   Únr-   r.   )r   ÚimagesÚgenerater0   r+   r,   r   r   r-   r.   r	   )r8   r6   r(   r(   r)   r!   X   s    

ù	zCLIImage.creater&   c              	   C  sd   t | jdƒ�}t| ¡ dd�}W 5 Q R X tƒ jj| jd|f| jt	t
| jƒt	t
| jƒd�}t|ƒ d S )NÚrbzUpload progress©Údescr6   )r0   r6   r9   r-   r.   )Úopenr6   r   Úreadr   r:   r%   r0   r,   r   r   r-   r.   r	   )r8   Úfile_readerÚbuffer_readerr6   r(   r(   r)   r%   e   s    

ù	zCLIImage.create_variationr$   c              
   C  s¶   t | jdƒ�}t| ¡ dd�}W 5 Q R X t| jtƒr:t}n(t | jdƒ�}t| ¡ dd�}W 5 Q R X tƒ j	j
| j| jd|f| jt|tƒsŽd|fn|tt| jƒtt| jƒd�}t|ƒ d S )Nr<   zImage upload progressr=   zMask progressr6   r7   )r0   r+   r6   r9   r7   r-   r.   )r?   r6   r   r@   Ú
isinstancer7   r   r   r   r:   r#   r0   r+   r,   r   r   r-   r.   r	   )r8   rA   rB   r7   r6   r(   r(   r)   r#   u   s     

÷zCLIImage.editN)r2   r3   r4   Ústaticmethodr!   r%   r#   r(   r(   r(   r)   r    W   s   r    N)Ú
__future__r   Útypingr   r   r   Úargparser   Ú_utilsr   r	   Ú_typesr   r   r   Z_modelsr   Z	_progressr   r   r*   r"   r&   r$   r    r(   r(   r(   r)   Ú<module>   s   .
