
    ;3h8                    8   d Z ddlmZ ddl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mZ dd
lmZmZ ddlmZ ddlmZmZ ddl m!Z! ddl"m#Z# e
rddl$m%Z% ejL                  jO                           e        G d dee             Z&y)zgr.Image() component.    )annotationsN)CallableSequence)Path)TYPE_CHECKINGAnyLiteralhandle_file)document)image_utilsutils)	ComponentStreamingInput)WebcamOptions)Base64ImageData	ImageData)Events)I18nData)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dd
dd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fdZ	 	 	 	 ddZ	 	 	 	 ddZddZd ZddZddZ xZS )ImageaB  
    Creates an image component that can be used to upload images (as an input) or display images (as an output).

    Demos: sepia_filter, fake_diffusion
    Guides: image-classification-in-pytorch, image-classification-in-tensorflow, image-classification-with-vision-transformers, create-your-own-friends-with-a-gan
    ULiteral['1', 'L', 'P', 'RGB', 'RGBA', 'CMYK', 'YCbCr', 'LAB', 'HSV', 'I', 'F'] | None
image_mode#Literal['numpy', 'pil', 'filepath']typeNwebpRGBnumpyT   Fvalue)formatheightwidthr   sourcesr   labeleveryinputs
show_labelshow_download_button	containerscale	min_widthinteractivevisible	streamingelem_idelem_classesrenderkeypreserved_by_keymirror_webcamwebcam_optionsshow_share_buttonplaceholdershow_fullscreen_buttonwebcam_constraintsc               J   || _         ||n	t               | _        |&t        j                  d       || j                  _        |&t        j                  d       || j                  _        g d}||vrt        d| d|       || _        || _	        || _
        || _        g d}||rdgng d| _        n t        |t              r	|g| _        n|| _        | j                  D ]  } | |vst        d	|        || _        || _        |r| j                  dgk7  rt        d
      |t#        j$                         dun|| _        || _        || _        t,        !| ]  ||	|
||||||||||||       | j                  dk(  rd| _        y| j                  dk(  rd| _        yd| _        y)a~  
        Parameters:
            value: A PIL Image, numpy array, path or URL for the default value that Image component is going to take. 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 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 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 type (e.g. "RGBA" for a .png image, "RGB" in most other cases).
            sources: List of sources for the image. "upload" creates a box where user can drop an image file, "webcam" allows user to take snapshot from their webcam, "clipboard" allows users to paste an image from the clipboard. If None, defaults to ["upload", "webcam", "clipboard"] if streaming is False, otherwise defaults to ["webcam"].
            type: The format the image is converted before being passed into the prediction function. "numpy" converts the image to a numpy array with shape (height, width, 3) and values from 0 to 255, "pil" converts the image to a PIL image object, "filepath" passes a str path to a temporary file containing the image. 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.
            streaming: If True when used in a `live` interface, will automatically stream webcam feed. Only valid is source is 'webcam'. If the component is an output component, will automatically convert images to base64.
            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.
            mirror_webcam: If True webcam will be mirrored. 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.
            placeholder: Custom text for the upload area. Overrides default upload messages when provided. Accepts new lines and `#` to designate a heading.
            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.
            webcam_constraints: A dictionary that allows developers to specify custom media constraints for the webcam stream. This parameter provides flexibility to control the video stream's properties, such as resolution and front or rear camera on mobile devices. See $demo/webcam_constraints
        NzThe `mirror_webcam` parameter is deprecated. Please use the `webcam_options` parameter with a `gr.WebcamOptions` instance instead.zThe `webcam_constraints` parameter is deprecated. Please use the `webcam_options` parameter with a `gr.WebcamOptions` instance instead.)r   pilfilepathz$Invalid value for parameter `type`: z. Please choose from one of: )uploadwebcam	clipboardr@   z0`sources` must a list consisting of elements in gImage streaming only available if sources is ['webcam']. Streaming not supported with multiple sources.)r&   r'   r(   r)   r+   r,   r-   r.   r/   r1   r2   r3   r4   r5   r!   r>   za filepath to an imager   z#a numpy array representing an imageza PIL Image)r"   r   r7   warningswarnmirrorconstraints
ValueErrorr   r#   r$   r   r%   
isinstancestrr0   r*   r   	get_spacer8   r:   r9   super__init___value_description)"selfr!   r"   r#   r$   r   r%   r   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   valid_typesvalid_sourcessource	__class__s"                                    W/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/image.pyrL   zImage.__init__6   s   R  -8Nmo 	 $MM U *7D&)MM Z /AD+2{"6tf<YZeYfg  	
$9?'
-N L %#9DL"DLll 	F]* F}oV 	
 #$8!(3y 
 !( __d*" 	
 '=#&!#%- 	 	
& yyJ& % 	
 99' 6	 	 # 	    c                    t        j                  || j                  | j                  | j                  | j
                        S )z
        Parameters:
            payload: image data in the form of a FileData object
        Returns:
            Passes the uploaded image as a `numpy.array`, `PIL.Image` or `str` filepath depending on `type`.
        )	cache_dirr"   r   r   )r   preprocess_imageGRADIO_CACHEr"   r   r   )rN   payloads     rS   
preprocesszImage.preprocess   s8     ++'';;
 	
rT   c                Z    t        j                  || j                  | j                        S )z
        Parameters:
            value: Expects a `numpy.array`, `PIL.Image`, or `str` or `pathlib.Path` filepath to an image which is displayed.
        Returns:
            Returns the image as a `FileData` object.
        )rV   r"   )r   postprocess_imagerX   r"   )rN   r!   s     rS   postprocesszImage.postprocess   s*     ,,'';;
 	
rT   c                    | j                   dk(  r(t        j                         }|j                  dd        |S | j	                         S )Nbase64description)r0   r   model_json_schemapopapi_info)rN   schemas     rS   api_info_as_outputzImage.api_info_as_output   s;    >>X%$668FJJ}d+M}}rT   c                T    | j                   r| j                  dgk7  rt        d      y y )Nr@   rB   )r0   r%   rG   rN   s    rS   check_streamablezImage.check_streamable   s-    >>dllxj8y  9>rT   c                    t        d      S NzPhttps://raw.githubusercontent.com/gradio-app/gradio/main/test/test_files/bus.pngr
   rg   s    rS   example_payloadzImage.example_payload   s    ^
 	
rT   c                     yrj    rg   s    rS   example_valuezImage.example_value  s    arT   )N):r!   z4str | PIL.Image.Image | np.ndarray | Callable | Noner"   rI   r#   int | str | Noner$   ro   r   r   r%   z`list[Literal['upload', 'webcam', 'clipboard']] | Literal['upload', 'webcam', 'clipboard'] | Noner   r   r&   zstr | I18nData | Noner'   zTimer | float | Noner(   z7Component | Sequence[Component] | set[Component] | Noner)   bool | Noner*   boolr+   rq   r,   z
int | Noner-   intr.   rp   r/   rq   r0   rq   r1   
str | Noner2   list[str] | str | Noner3   rq   r4   z(int | str | tuple[int | str, ...] | Noner5   rt   r6   rp   r7   zWebcamOptions | Noner8   rp   r9   rs   r:   rq   r;   zdict[str, Any] | None)rY   zImageData | Nonereturnz)np.ndarray | PIL.Image.Image | str | None)r!   z0np.ndarray | PIL.Image.Image | str | Path | Noneru   z"ImageData | Base64ImageData | None)ru   zdict[str, Any])ru   r   )__name__
__module____qualname____doc__r   clearchangestreamselectr?   inputEVENTSr   
data_model__annotations__rL   rZ   r]   re   rh   rk   rn   __classcell__)rR   s   @rS   r   r      sR    	F J	
 .- GKY
 #'"& 
 4;'+&*JN"&%) #'"/38<3:%)/3)-"&'+48QY
CY
 	Y

 !Y
  Y
Y
Y
$ 2%Y
& %'Y
( $)Y
* H+Y
,  -Y
. #/Y
0 1Y
2 3Y
4 5Y
6 !7Y
8 9Y
: ;Y
< =Y
> -?Y
@ AY
B 6CY
D 1EY
F #GY
H -IY
J 'KY
L  MY
N !%OY
P 2QY
v
'
	2
"
E
	+


brT   r   )(ry   
__future__r   rC   collections.abcr   r   pathlibr   typingr   r   r	   r   np	PIL.ImagePILgradio_clientr   gradio_client.documentationr   gradior   r   gradio.components.baser   r   gradio.components.image_editorr   gradio.data_classesr   r   gradio.eventsr   gradio.i18nr   gradio.componentsr   r   initrm   rT   rS   <module>r      sq     "  .  . .   % 0 % < 8 :    ' 		  
gbNI gb gbrT   