o
    e*                     @  s   d Z ddlmZ ddlmZ ddlmZmZmZ ddl	Z
ddlmZ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 ed e G dd deeeZdS )zgr.Gallery() component.    )annotations)Path)AnyCallableLiteralN)documentset_documentation_group)GallerySerializable)Image)utils)IOComponent	_Keywords)warn_deprecationwarn_style_method_deprecation)EventListenerMethod
Selectable	componentc                   @  s   e Zd ZdZ	d5ddddddddddddddddddd6d$d%Zeejddddddddddddddfd7d'd(Zd)d* Z	d8d/d0Z
dddddddd1d9d3d4ZdS ):GalleryaW  
    Used to display a list of images as a gallery that can be scrolled through.
    Preprocessing: this component does *not* accept input.
    Postprocessing: expects a list of images in any format, {List[numpy.array | PIL.Image | str | pathlib.Path]}, or a {List} of (image, {str} caption) tuples and displays them.

    Demos: fake_gan
    NT      )labelevery
show_label	containerscale	min_widthvisibleelem_idelem_classescolumnsrowsheightpreview
object_fitallow_previewshow_share_buttonshow_download_buttonvalueFlist[np.ndarray | _Image.Image | str | Path | tuple] | Callable | Noner   
str | Noner   float | Noner   bool | Noner   boolr   
int | Noner   intr   r   r   list[str] | str | Noner   int | tuple | Noner    r!   int | float | Noner"   r#   @Literal['contain', 'cover', 'fill', 'none', 'scale-down'] | Noner$   r%   r&   c                K  s   || _ || _|| _|| _|| _|| _|du rt dun|| _|  	 |du r,t dun|| _	t
j| f||||||||	|
|d
| dS )a  
        Parameters:
            value: List of images to display in the gallery by default. If callable, the function will be called whenever the app loads to set the initial value of the component.
            label: component name in interface.
            every: If `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. Queue must be enabled. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.
            show_label: if True, will display label.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative width compared to adjacent Components in a Row. For example, if Component A has scale=2, and Component B has scale=1, A will be twice as wide as B. Should be an integer.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
            columns: Represents the number of images that should be shown in one row, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). if fewer that 6 are given then the last will be used for all subsequent breakpoints
            rows: Represents the number of rows in the image grid, for each of the six standard screen sizes (<576px, <768px, <992px, <1200px, <1400px, >1400px). if fewer that 6 are given then the last will be used for all subsequent breakpoints
            height: The height of the gallery component, in pixels. If more images are displayed than can fit in the height, a scrollbar will appear.
            preview: If True, will display the Gallery in preview mode, which shows all of the images as thumbnails and allows the user to click on them to view them in full size.
            object_fit: CSS object-fit property for the thumbnail images in the gallery. Can be "contain", "cover", "fill", "none", or "scale-down".
            allow_preview: If True, images in the gallery will be enlarged when they are clicked. Default is True.
            show_share_button: If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.
            show_download_button: If True, will show a download button in the corner of the selected image. If False, the icon does not appear. Default is True.

        N)
r   r   r   r   r   r   r   r   r   r'   )	grid_cols	grid_rowsr!   r"   r#   r$   r   Z	get_spacer&   r%   r   __init__)selfr'   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   kwargs r8   ID:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/gallery.pyr5   "   s@   0
zGallery.__init__(Any | Literal[_Keywords.NO_VALUE] | Nonec                 C  sh   i d|d|d|d|d|d|d| d|d	|d
|	d|
d|d|d|d|dd}|S )Nr   r   r   r   r   r   r'   r3   r4   r!   r"   r#   r$   r%   r&   Z__type__updater8   )r'   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   Zupdated_configr8   r8   r9   r;   w   sD   	
zGallery.updatec              
   C  s4   | j | j| j| j| j| j| j| j| jd	t	
| S )N)	r'   r3   r4   r!   r"   r#   r$   r%   r&   )r'   r3   r4   r!   r"   r#   r$   r%   r&   r   
get_config)r6   r8   r8   r9   r<      s   
zGallery.get_configy`list[np.ndarray | _Image.Image | str] | list[tuple[np.ndarray | _Image.Image | str, str]] | Nonereturn	list[str]c                 C  s  |du rg S g }|D ]~}d}t |ttfr|\}}t |tjr5| j|| jd}tt	|}| j
| n:t |tjrQ| j|| jd}tt	|}| j
| nt |ttfrft|r`|}n| |}n	tdt| |dur||ddd|g q
||ddd q
|S )z
        Parameters:
            y: list of images, or list of (image, caption) tuples
        Returns:
            list of string file paths to images in temp directory
        N)dirzCannot process type as image: T)namedatais_file)
isinstancetuplelistnpZndarrayZimg_array_to_temp_fileZDEFAULT_TEMP_DIRstrr   abspathZ
temp_filesadd_Imager
   Zpil_to_temp_filer   Zvalidate_urlZmake_temp_copy_if_needed
ValueErrortypeappend)r6   r=   outputZimgcaptionfile	file_pathr8   r8   r9   postprocess   s4   
zGallery.postprocess)gridr   r    r!   r   r"   r#   rU   c          	      K  st   t   |durtd || _|dur|| _|dur|| _|dur#|| _|dur*|| _|dur1|| _|dur8|| _| S )zc
        This method is deprecated. Please set these arguments in the constructor instead.
        NzYThe 'grid' parameter will be deprecated. Please use 'columns' in the constructor instead.)r   r   r3   r4   r!   r"   r#   r   )	r6   rU   r   r    r!   r   r"   r#   r7   r8   r8   r9   style   s&   zGallery.style)N)$r'   r(   r   r)   r   r*   r   r+   r   r,   r   r-   r   r.   r   r,   r   r)   r   r/   r   r0   r    r0   r!   r1   r"   r+   r#   r2   r$   r,   r%   r+   r&   r+   )r'   r:   r   r)   r   r+   r   r+   r   r-   r   r-   r   r+   r   r0   r    r0   r!   r1   r"   r+   r#   r2   r$   r+   r%   r+   r&   r+   )r=   r>   r?   r@   )rU   r0   r   r0   r    r0   r!   r)   r   r+   r"   r+   r#   r)   )__name__
__module____qualname____doc__r5   staticmethodr   ZNO_VALUEr;   r<   rT   rV   r8   r8   r8   r9   r      sb    U&
/r   )rZ   
__future__r   pathlibr   typingr   r   r   numpyrH   Zgradio_client.documentationr   r   Zgradio_client.serializingr	   ZPILr
   rL   Zgradior   Zgradio.components.baser   r   Zgradio.deprecationr   r   Zgradio.eventsr   r   r   r8   r8   r8   r9   <module>   s    