
    ;3h[                        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 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 e
rddlmZ  e        G d de             Zy)zgr.DownloadButton() component.    )annotationsN)CallableSequence)Path)TYPE_CHECKINGLiteralhandle_file)document)	Component)FileData)Events)Timerc                       e Zd ZdZej
                  gZ	 	 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ed        Z xZS )DownloadButtonz
    Creates a button, that when clicked, allows a user to download a single file of arbitrary type.

    Demos: upload_and_download
    N	secondaryTlgvalue)everyinputsvariantvisiblesizeiconscale	min_widthinteractiveelem_idelem_classesrenderkeypreserved_by_keyc                   t         | _        || _        || _        || _        t
        |   |||||||||||	|
|       | j                  |      | _        y)ay
  
        Parameters:
            label: Text to display on the button. Defaults to "Download".
            value: A str or pathlib.Path filepath or URL to download, or a Callable that returns a str or pathlib.Path filepath or URL to download.
            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.
            variant: 'primary' for main call-to-action, 'secondary' for a more subdued style, 'stop' for a stop button.
            visible: If False, component will be hidden.
            size: size of the button. Can be "sm", "md", or "lg".
            icon: URL or path to the icon file to display within the button. If None, no icon will be displayed.
            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 False, the UploadButton will be in a disabled state.
            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.
        )labelr   r   r   r   r   r    r!   r"   r   r   r   r   N)	r   
data_modelr   r$   r   super__init__serve_static_filer   )selfr$   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   	__class__s                    a/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/download_button.pyr'   zDownloadButton.__init__   so    N #	
%-# 	 	
 **40	    c                t    |y|j                   }t        j                  d| j                        }||_        |S )z
        Parameters:
            payload: File information as a FileData object,
        Returns:
            (Rarely used) passes the file as a `str` into the function.
        NF)deletedir)pathtempfileNamedTemporaryFileGRADIO_CACHEname)r)   payload	file_namefiles       r+   
preprocesszDownloadButton.preprocess[   s:     ?LL	**%T=N=NO	r,   c                Z    |yt        t        |      t        |      j                        S )z
        Parameters:
            value: Expects a `str` or `pathlib.Path` filepath
        Returns:
            File information as a FileData object
        N)r0   	orig_name)r   strr   r4   )r)   r   s     r+   postprocesszDownloadButton.postprocessi   s'     =SZ4;3C3CDDr,   c                    t        d      S NzMhttps://github.com/gradio-app/gradio/raw/main/test/test_files/sample_file.pdfr	   r)   s    r+   example_payloadzDownloadButton.example_payloadt   s    [
 	
r,   c                     yr>    r?   s    r+   example_valuezDownloadButton.example_valuey   s    ^r,   c                     y)NFrB   r?   s    r+   skip_apizDownloadButton.skip_api|   s    r,   )DownloadN) r$   r;   r   zstr | Path | Callable | Noner   zTimer | float | Noner   z7Component | Sequence[Component] | set[Component] | Noner   z'Literal['primary', 'secondary', 'stop']r   boolr   zLiteral['sm', 'md', 'lg']r   
str | Noner   
int | Noner   rI   r   rG   r   rH   r   list[str] | str | Noner    rG   r!   z(int | str | tuple[int | str, ...] | Noner"   rJ   )r5   FileData | NonereturnrH   )r   zstr | Path | NonerL   rK   )rL   dict)rL   r;   )__name__
__module____qualname____doc__r   clickEVENTSr'   r8   r<   r@   rC   propertyrE   __classcell__)r*   s   @r+   r   r      s    ll^F  .2:1
 '+JN;F*.  $ "/38<3:%:1:1 ,:1
 $:1 H:1 9:1 :1 (:1 :1 :1 :1 :1 :1 -:1  !:1" 6#:1$ 1%:1x	E

_  r,   r   )rQ   
__future__r   r1   collections.abcr   r   pathlibr   typingr   r   gradio_clientr
   gradio_client.documentationr   gradio.components.baser   gradio.data_classesr   gradio.eventsr   gradio.componentsr   r   rB   r,   r+   <module>r`      sL    $ "  .  ) % 0 , (  ' 
hY h hr,   