
    ;3h.                       d Z ddlmZ ddlmZmZ ddlmZ ddlm	Z	m
Z
mZ ddlZddl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  G d de      Zeeej@                  j@                  z  ejB                  z  dz  eej@                  j@                  z  ejB                  z  dz  f   Z"e	rddl#m$Z$ ej@                  jK                           e        G d de             Z&y)zgr.ImageSlider() component.    )annotations)CallableSequence)Path)TYPE_CHECKINGAnyLiteralNhandle_file)document)image_utils)	Component)GradioRootModel	ImageData)Eventsc                      e Zd ZU ded<   y)
SliderDataz0tuple[ImageData | None, ImageData | None] | NonerootN)__name__
__module____qualname____annotations__     ]/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/imageslider.pyr   r      s    
::r   r   )Timerc                      e Zd ZU dZej
                  ej                  ej                  ej                  ej                  ej                  gZeZded<   ded<   	 dddddd	ddddd
d
dddd
ddd
ddd
ddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZddZ	 	 	 	 ddZddZddZddZ xZS )ImageSliderz
    Creates an image component that can be used to upload images (as an input) or display images (as an output).

    Demos: imageslider
    ULiteral['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F'] | None
image_mode#Literal['numpy', 'pil', 'filepath']typeNwebpRGBnumpyT   value2   i  )formatheightwidthr    r"   labeleveryinputs
show_labelshow_download_button	containerscale	min_widthinteractivevisibleelem_idelem_classesrenderkeypreserved_by_keyshow_fullscreen_buttonslider_position
max_heightc               \   || _         || _        || _        g d}||vrt        d| d|       || _        || _        || _        || _        || _        || _	        t        | -  |||	|
|||||||||||       | j                  dk(  rd| _        y
| j                  dk(  rd| _        y
d	| _        y
)a  
        Parameters:
            value: A tuple of PIL Image, numpy array, path or URL for the default value that ImageSlider component is going to take, this pair of images should be of equal size. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
            format: File format (e.g. "png" or "gif"). Used to save image if it does not already have a valid format (e.g. if the image is being returned to the frontend as a numpy array or PIL Image). The format should be supported by the PIL library. Applies both when this component is used as an input or output. This parameter has no effect on SVG files.
            height: The height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. This has no effect on the preprocessed tuple of image file or numpy array, but will affect the displayed image.
            width: The width of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. This has no effect on the preprocessed tuple of image file or numpy array, but will affect the displayed image.
            image_mode: The pixel format and color depth that the image should be loaded and preprocessed as. "RGB" will load the image as a color image, or "L" as black-and-white. See https://pillow.readthedocs.io/en/stable/handbook/concepts.html for other supported image modes and their meaning. This parameter has no effect on SVG or GIF files. If set to None, the image_mode will be inferred from the image file types (e.g. "RGBA" for a .png image, "RGB" in most other cases).
            type: The format the images are converted to before being passed into the prediction function. "numpy" converts the images to numpy arrays with shape (height, width, 3) and values from 0 to 255, "pil" converts the images to PIL image objects, "filepath" passes str paths to temporary files containing the images. To support animated GIFs in input, the `type` should be set to "filepath" or "pil". To support SVGs, the `type` should be set to "filepath".
            label: the label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
            every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
            inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
            show_label: if True, will display label.
            show_download_button: If True, will display button to download image. Only applies if interactive is False (e.g. if the component is used as an output).
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
            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.
            interactive: if True, will allow users to upload and edit an image; if False, can only be used to display images. If not provided, this is inferred based on whether the component is used as an input or output.
            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.
            render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
            key: in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.
            preserved_by_key: A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
            show_fullscreen_button: If True, will show a fullscreen icon in the corner of the component that allows user to view the image in fullscreen mode. If False, icon does not appear.
            slider_position: The position of the slider as a percentage of the width of the image, between 0 and 100.
            max_height: The maximum height of the image.
        )r%   pilfilepathz$Invalid value for parameter `type`: z. Please choose from one of: )r,   r-   r.   r/   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r'   r@   za tuple of filepaths to imagesr%   z+a tuple of numpy arrays representing imagesza tuple of PIL ImagesN)r)   r<   r=   
ValueErrorr"   r*   r+   r    r0   r;   super__init___value_description)selfr'   r)   r*   r+   r    r"   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   r<   r=   valid_types	__class__s                             r   rC   zImageSlider.__init__;   s    x .$2{"6tf<YZeYfg  	
$$8!&<#!#%- 	 	
& yyJ& - 	
 99' >	 	 - 	r   c                r   |y|j                   t        d      t        j                  |j                   d   | j                  | j
                  | j                  | j                        t        j                  |j                   d   | j                  | j
                  | j                  | j                        fS )z
        Parameters:
            payload: image data in the form of a SliderData object
        Returns:
            Passes the uploaded image as a tuple of `numpy.array`, `PIL.Image` or `str` filepath depending on `type`.
        NzPayload is None.r   )	cache_dirr)   r    r"      )r   rA   r   preprocess_imageGRADIO_CACHEr)   r    r"   )rE   payloads     r   
preprocesszImageSlider.preprocess   s     ?<</00((Q++{{??YY ((Q++{{??YY
 	
r   c                    |yt        t        j                  |d   | j                  | j                        t        j                  |d   | j                  | j                        f      S )z
        Parameters:
            value: Expects a tuple of `numpy.array`, `PIL.Image`, or `str` or `pathlib.Path` filepath to an image which is displayed.
        Returns:
            Returns the image as a `SliderData` object.
        Nr   )rI   r)   rJ   )r   )r   r   postprocess_imagerL   r)   )rE   r'   s     r   postprocesszImageSlider.postprocess   sf     =--!H(9(9$++ --!H(9(9$++		
 		
r   c                "    | j                         S N)api_inforE   s    r   api_info_as_outputzImageSlider.api_info_as_output   s    }}r   c                .    t        d      t        d      fS )NPhttps://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.pngr
   rU   s    r   example_payloadzImageSlider.example_payload   s$    b b	
 	
r   c                     y)N)rX   rX   r   rU   s    r   example_valuezImageSlider.example_value   s    
r   rS   )0r'   zimage_tuple | Callable | Noner)   strr*   int | str | Noner+   r]   r    r   r"   r!   r,   
str | Noner-   zTimer | float | Noner.   z7Component | Sequence[Component] | set[Component] | Noner/   bool | Noner0   boolr1   r`   r2   z
int | Noner3   intr4   r_   r5   r`   r6   r^   r7   list[str] | str | Noner8   r`   r9   z(int | str | tuple[int | str, ...] | Noner:   rb   r;   r`   r<   floatr=   ra   )rM   SliderData | Nonereturnzimage_tuple | None)r'   zptuple[np.ndarray | PIL.Image.Image | str | Path | None, np.ndarray | PIL.Image.Image | str | Path | None] | Nonere   rd   )re   zdict[str, Any])re   r   )r   r   r   __doc__r   clearchangestreamselectuploadinputEVENTSr   
data_modelr   rC   rN   rQ   rV   rY   r[   __classcell__)rG   s   @r   r   r   #   s    	F J	 .- 04d
 #'"& 4; &*JN"&%) #'"/38<3:'+!#?d
,d
 	d

 !d
  d
d
 2d
 d
 $d
  H!d
"  #d
$ #%d
& 'd
( )d
* +d
, !-d
. /d
0 1d
2 -3d
4 5d
6 67d
8 19d
: !%;d
< =d
> ?d
L
8

 

6

r   r   )'rf   
__future__r   collections.abcr   r   pathlibr   typingr   r   r	   r%   np	PIL.ImagePILgradio_clientr   gradio_client.documentationr   gradior   gradio.components.baser   gradio.data_classesr   r   gradio.eventsr   r   tupler\   Imagendarrayimage_tuplegradio.componentsr   initr   r   r   r   <module>r      s    ! " .  . .   % 0  , :  ; ; #))//BJJ&-sSYY__/Drzz/QTX/XX
 ' 		  
E
) E
 E
r   