o
    e                     @  s   d Z ddlmZ ddlZddl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mZmZ ddlmZ dd	lmZmZmZ dd
lmZ ed e G dd deeeeeee	ZdS )zgr.Slider() component.    )annotationsN)AnyCallableLiteral)documentset_documentation_group)NumberSerializable)FormComponentIOComponent	_Keywords)warn_style_method_deprecation)
Changeable	InputableReleaseable)NeighborInterpretable	componentc                   @  s   e Zd ZdZ			d?ddddddddddddddd@d"d#ZdAd&d'ZdBd)d*Zd+d, Zd-d. Ze	e
jdddddddddddfdCd0d1ZdDd3d4ZdEdFd7d8ZdGd:d;Zdd<dHd=d>ZdS )ISlidera  
    Creates a slider that ranges from `minimum` to `maximum` with a step size of `step`.
    Preprocessing: passes slider value as a {float} into the function.
    Postprocessing: expects an {int} or {float} returned from function and sets slider value to it as long as it is within range.
    Examples-format: A {float} or {int} representing the slider's value.

    Demos: sentence_builder, slider_release, generate_tone, titanic_survival, interface_random_slider, blocks_random_slider
    Guides: create-your-own-friends-with-a-gan
    r   d   NT   F)steplabelinfoevery
show_label	containerscale	min_widthinteractivevisibleelem_idelem_classes	randomizeminimumfloatmaximumvaluefloat | Callable | Noner   float | Noner   
str | Noner   r   r   bool | Noner   boolr   
int | Noner   intr   r   r   r    list[str] | str | Noner!   c                K  s   || _ || _|du r|| }tt|d }d| | _n|| _|r&| j}tj| f|||||	|
||||||d| t	|  dS )a  
        Parameters:
            minimum: minimum value for slider.
            maximum: maximum value for slider.
            value: default value. If callable, the function will be called whenever the app loads to set the initial value of the component. Ignored if randomized=True.
            step: increment between slider values.
            label: component name in interface.
            info: additional component description.
            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.
            interactive: if True, slider will be adjustable; if False, adjusting will be disabled. 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.
            randomize: If True, the value of the slider when the app loads is taken uniformly at random from the range given by the minimum and maximum.
        N   
   )r   r   r   r   r   r   r   r   r   r   r    r%   )
r"   r$   mathfloorlog10r   get_random_valuer
   __init__r   )selfr"   r$   r%   r   r   r   r   r   r   r   r   r   r   r   r    r!   kwargs
differencepower r9   HD:\Projects\ConvertPro\env\Lib\site-packages\gradio/components/slider.pyr4   )   s8   (zSlider.__init__returndict[str, dict | bool]c                 C  s    dd| j  d| j dddS )Nnumberznumeric value between z and )typedescriptionF)r   Zserialized_info)r"   r$   r5   r9   r9   r:   api_infom   s
   zSlider.api_infodict[str, Any]c                 C  s   | j | j dS )N)rawZ
serializedr"   r@   r9   r9   r:   example_inputsv   s   zSlider.example_inputsc                 C  s    | j | j| j| jdt| S )N)r"   r$   r   r%   )r"   r$   r   r%   r
   
get_configr@   r9   r9   r:   rF   |   s   zSlider.get_configc                 C  sd   t | j| j | j }td|}| j|| j  }tt| jd d d dd}|r0t	||}|S )Nr   .)
r,   r$   r"   r   randomrandintmaxstrfindround)r5   Zn_stepsr   r%   Z
n_decimalsr9   r9   r:   r3      s    
zSlider.get_random_value*float | Literal[_Keywords.NO_VALUE] | Nonec                 C  s    |||||||||	|
|| ddS )Nupdate)r"   r$   r   r   r   r   r   r   r   r   r   r%   Z__type__r9   )r%   r"   r$   r   r   r   r   r   r   r   r   r   r9   r9   r:   rP      s   zSlider.updateyc                 C  s   |du r| j S |S )z
        Any postprocessing needed to be performed on function output.
        Parameters:
            y: numeric output
        Returns:
            numeric output or minimum number if None
        NrD   )r5   rQ   r9   r9   r:   postprocess   s   zSlider.postprocess   stepsc                 C  s
   || _ | S )a  
        Calculates interpretation scores of numeric values ranging between the minimum and maximum values of the slider.
        Parameters:
            steps: Number of neighboring values to measure between the minimum and maximum values of the slider range.
        )interpretation_steps)r5   rT   r9   r9   r:   set_interpret_parameters   s   zSlider.set_interpret_parameterstuple[object, dict]c                 C  s   t | j| j| j i fS )N)npZlinspacer"   r$   rU   tolist)r5   xr9   r9   r:   get_interpretation_neighbors   s   z#Slider.get_interpretation_neighbors)r   c                C  s   t   |dur
|| _| S )zc
        This method is deprecated. Please set these arguments in the constructor instead.
        N)r   r   )r5   r   r9   r9   r:   style   s   zSlider.style)r   r   N) r"   r#   r$   r#   r%   r&   r   r'   r   r(   r   r(   r   r'   r   r)   r   r*   r   r+   r   r,   r   r)   r   r*   r   r(   r    r-   r!   r*   )r;   r<   )r;   rB   )r%   rO   r"   r'   r$   r'   r   r'   r   r(   r   r(   r   r)   r   r)   r   r+   r   r+   r   r)   r   r)   )rQ   r'   r;   r'   )rS   )rT   r,   r;   r   )r;   rW   )r   r)   )__name__
__module____qualname____doc__r4   rA   rE   rF   r3   staticmethodr   ZNO_VALUErP   rR   rV   r[   r\   r9   r9   r9   r:   r      sV    

D
		



		r   )r`   
__future__r   r0   rI   typingr   r   r   numpyrX   Zgradio_client.documentationr   r   Zgradio_client.serializingr   Zgradio.components.baser	   r
   r   Zgradio.deprecationr   Zgradio.eventsr   r   r   Zgradio.interpretationr   r   r9   r9   r9   r:   <module>   s.    

