
    g
P                       U d dl mZ d dlZd dlmZ d dlmZ d dlmZm	Z	m
Z
mZmZ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mZmZmZ d dlmZm Z m!Z!m"Z"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.m/Z/m0Z0m1Z1 erd dl2m3Z3 ee4e5f   Z6de7d<    e
de4d      Z8 e
de5d      Z9e G d d             Z: G d d      Z;y)    )annotationsN)	dataclass)dedent)TYPE_CHECKINGLiteralTypeVarUnioncastoverload)	TypeAlias)current_form_id)JSNumberJSNumberBoundsException)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)!StreamlitInvalidNumberFormatErrorStreamlitJSNumberBoundsErrorStreamlitMixedNumericTypesErrorStreamlitValueAboveMaxErrorStreamlitValueBelowMinError)NumberInput)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsget_session_stateregister_widget)DeltaGeneratorr   Number	IntOrNoneFloatOrNonec                  @    e Zd ZU ded<   ded<   ddZ	 d		 	 	 	 	 d
dZy)NumberInputSerdeNumber | Nonevalueint	data_typec                    |S N )selfvs     \/var/www/openai/venv/lib/python3.12/site-packages/streamlit/elements/widgets/number_input.py	serializezNumberInputSerde.serializeE   s        c                z    ||n| j                   }|(| j                  t        j                  k(  rt	        |      }|S r0   )r,   r.   NumberInputProtoINTr-   )r2   ui_value	widget_idvals       r4   deserializezNumberInputSerde.deserializeH   s9     *2)=X4::?t~~1A1E1EEc(C
r6   N)r3   r+   returnr+   ) )r:   r+   r;   strr>   r+   )__name__
__module____qualname____annotations__r5   r=   r1   r6   r4   r*   r*   @   s4    N 9;%25	r6   r*   c                     e Zd Ze	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 ddddddddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 dddddddddddd	
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
       Ze	 	 	 ddddddddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Ze	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z ed      	 	 	 	 	 	 	 	 	 	 ddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 	 	 	 	 	 dddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZedd       Zy) NumberInputMixinNminFvisible)placeholderdisabledlabel_visibilityc                    y r0   r1   r2   label	min_value	max_valuer,   stepformatkeyhelp	on_changeargskwargsrI   rJ   rK   s                  r4   number_inputzNumberInputMixin.number_input\        	r6   )r,   rQ   rR   rS   rT   rU   rV   rW   rI   rJ   rK   c                    y r0   r1   rM   s                  r4   rX   zNumberInputMixin.number_inputl        	r6   )
rQ   rR   rS   rT   rU   rV   rW   rI   rJ   rK   c                    y r0   r1   rM   s                  r4   rX   zNumberInputMixin.number_input{   r[   r6   )	rR   rS   rT   rU   rV   rW   rI   rJ   rK   c       
             y r0   r1   rM   s                  r4   rX   zNumberInputMixin.number_input   r[   r6   c                    y r0   r1   rM   s                  r4   rX   zNumberInputMixin.number_input   rY   r6   rX   c               V    t               }| j                  |||||||||	|
|||||      S )a  Display a numeric input widget.

        .. note::
            Integer values exceeding +/- ``(1<<53) - 1`` cannot be accurately
            stored or returned by the widget due to serialization contstraints
            between the Python server and JavaScript client. You must handle
            such numbers as floats, leading to a loss in precision.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this input is for.
            The label can optionally contain GitHub-flavored Markdown of the
            following types: Bold, Italics, Strikethroughs, Inline Code, Links,
            and Images. Images display like icons, with a max height equal to
            the font height.

            Unsupported Markdown elements are unwrapped so only their children
            (text contents) render. Display unsupported elements as literal
            characters by backslash-escaping them. E.g.,
            ``"1\. Not an ordered list"``.

            See the ``body`` parameter of |st.markdown|_ for additional,
            supported Markdown directives.

            For accessibility reasons, you should never set an empty label, but
            you can hide it with ``label_visibility`` if needed. In the future,
            we may disallow empty labels by raising an exception.

            .. |st.markdown| replace:: ``st.markdown``
            .. _st.markdown: https://docs.streamlit.io/develop/api-reference/text/st.markdown

        min_value : int, float, or None
            The minimum permitted value.
            If None, there will be no minimum.

        max_value : int, float, or None
            The maximum permitted value.
            If None, there will be no maximum.

        value : int, float, "min" or None
            The value of this widget when it first renders. If ``None``, will initialize
            empty and return ``None`` until the user provides input.
            If "min" (default), will initialize with min_value, or 0.0 if
            min_value is None.

        step : int, float, or None
            The stepping interval.
            Defaults to 1 if the value is an int, 0.01 otherwise.
            If the value is not specified, the format parameter will be used.

        format : str or None
            A printf-style format string controlling how the interface should
            display numbers. The output must be purely numeric. This does not
            impact the return value of the widget. Formatting is handled by
            `sprintf.js <https://github.com/alexei/sprintf.js>`_.

            For example, ``format="%0.1f"`` adjusts the displayed decimal
            precision to only show one digit after the decimal.

        key : str or int
            An optional string or integer to use as the unique key for the widget.
            If this is omitted, a key will be generated for the widget
            based on its content. No two widgets may have the same key.

        help : str or None
            A tooltip that gets displayed next to the widget label. Streamlit
            only displays the tooltip when ``label_visibility="visible"``. If
            this is ``None`` (default), no tooltip is displayed.

            The tooltip can optionally contain GitHub-flavored Markdown,
            including the Markdown directives described in the ``body``
            parameter of ``st.markdown``.

        on_change : callable
            An optional callback invoked when this number_input's value changes.

        args : tuple
            An optional tuple of args to pass to the callback.

        kwargs : dict
            An optional dict of kwargs to pass to the callback.

        placeholder : str or None
            An optional string displayed when the number input is empty.
            If None, no placeholder is displayed.

        disabled : bool
            An optional boolean that disables the number input if set to
            ``True``. The default is ``False``.

        label_visibility : "visible", "hidden", or "collapsed"
            The visibility of the label. The default is ``"visible"``. If this
            is ``"hidden"``, Streamlit displays an empty spacer instead of the
            label, which can help keep the widget alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        Returns
        -------
        int or float or None
            The current value of the numeric input widget or ``None`` if the widget
            is empty. The return type will match the data type of the value parameter.

        Example
        -------
        >>> import streamlit as st
        >>>
        >>> number = st.number_input("Insert a number")
        >>> st.write("The current number is ", number)

        .. output::
           https://doc-number-input.streamlit.app/
           height: 260px

        To initialize an empty number input, use ``None`` as the value:

        >>> import streamlit as st
        >>>
        >>> number = st.number_input(
        ...     "Insert a number", value=None, placeholder="Type a number..."
        ... )
        >>> st.write("The current number is ", number)

        .. output::
           https://doc-number-input-empty.streamlit.app/
           height: 260px

        )rN   rO   rP   r,   rQ   rR   rS   rT   rU   rV   rW   rI   rJ   rK   ctx)r   _number_input)r2   rN   rO   rP   r,   rQ   rR   rS   rT   rU   rV   rW   rI   rJ   rK   r`   s                   r4   rX   zNumberInputMixin.number_input   sR    f !"!!#- " 
 	
r6   )rI   rJ   rK   r`   c                  t        |      }t        | j                  ||	|dk7  r|nd        t        ||       t	        d|t        | j                        ||||||||d n
t        |            }||||g}t        d |D              }t        d |D              }|s|st        ||||      t               j                  }|||v r||   d }|dk(  r||}n|r|rd}n|rd	}nd}t        |t        j                        }t        |t              }|	|r|sd
}nd
}||rdnd}|dv r|rd	d l}|j!                  d| d       n#|d   dk(  r|rd	d l}|j!                  d| d       ||rdnd}	 t        |dz         |xr |}||||kD  rt)        ||      ||||k  rt+        ||      	 |r|t-        j.                  t1        |      d       |t-        j.                  t1        |      d       |t-        j.                  t1        |      d       |t-        j.                  t1        |      d       n`|t-        j2                  |d       |t-        j2                  |d       |t-        j2                  |d       |t-        j2                  |d       |rt8        j:                  nt8        j<                  }t9               }||_        ||_         ||_!        |||_"        |t        |      |_#        t        | j                        |_$        ||_%        tM        |      |jN                  _(        |tS        |      |_*        |||_+        d
|_,        |||_-        d
|_.        |||_/        |||_0        tc        ||      }te        |j>                  |	|
||jf                  |jh                  |d      }|jj                  r$|jP                  |jP                  |_(        d
|_6        | j                  jo                  d|       |jP                  S # t"        t$        f$ r t'        |      w xY w# t4        $ r}t7        t        |            d }~ww xY w)NrG   )default_valuerX   )
user_keyform_idrN   rO   rP   r,   rQ   rR   rT   rI   c              3  p   K   | ].  }t        |t        j                  t        d       t        f       0 y wr0   )
isinstancenumbersIntegraltyper@   .0as     r4   	<genexpr>z1NumberInputMixin._number_input.<locals>.<genexpr>~  s0      
& q7++T$Z=>&s   46c              3  \   K   | ]$  }t        |t        t        d       t        f       & y wr0   )rg   floatrj   r@   rk   s     r4   rn   z1NumberInputMixin._number_input.<locals>.<genexpr>  s'      
=NJq5$t*c23=Ns   *,)r,   rO   rP   rQ   g        r   T%dz%0.2f)rq   z%uz%iz<Warning: NumberInput value below has type float, but format z displays as integer.fz[Warning: NumberInput value below has type int so is displayed as int despite format string .   g{Gz?   )r,   rO   )r,   rP   z`min_value`z`max_value`z`step`z`value`double_value)on_change_handlerrV   rW   deserializer
serializerr`   
value_type)8r   r   dgr   r   r   r@   allr   r#   filtered_staterg   rh   ri   rp   	streamlitwarning	TypeError
ValueErrorr   r   r   r   validate_int_boundsr-   validate_float_boundsr   r   r8   r9   FLOATidr.   rN   defaultrI   re   rJ   r   rK   r,   r   rT   rG   has_minmaxhas_maxrQ   rR   r*   r$   r=   r5   value_changed	set_value_enqueue)r2   rN   rO   rP   r,   rQ   rR   rS   rT   rU   rV   rW   rI   rJ   rK   r`   
element_idnumber_input_argsall_int_argsall_float_argssession_state	int_valuefloat_valuestall_intser.   number_input_protoserdewidget_states                                 r4   ra   zNumberInputMixin._number_inputP  s   & SkGG#(E>%t		
 	#5*:;4#DGG, + 3[9I

 '	5$? 
&
 

  
=N
 
 N1^gnrss)+::?sm3c8J8REE>$!.ug&6&67	 .=N 	 #>&TGF ''K"JJ%h&;= BZ39"JJ;;A(!E
 <!1tD	<&1* - U%69u;L-EYOO  U%69u;L-EYOO	7(00YO(00YO#00THE$00UYG(229mL(229mL#224B$225)D -5$((:J:P:P	-/ *'0$#( ).&"-0-=*%4TWW%="&.#4T5
++1 &,Tl# %.")-& %.")-&&*#(.% 	2&!!'**%	
 %%!!-+7+=+="(+/();<!!!s :& 	<3F;;	<F ' 	7.s1v66	7s%   -P .C'P# P #	Q,Q  Qc                    t        d|       S )zGet our DeltaGenerator.r%   )r
   )r2   s    r4   r|   zNumberInputMixin.dg  s     $d++r6   )	NrG   NNNNNNN)rN   r@   rO   r-   rP   
int | Noner,   IntOrNone | Literal['min']rQ   r   rR   
str | NonerS   
Key | NonerT   r   rU   WidgetCallback | NonerV   WidgetArgs | NonerW   WidgetKwargs | NonerI   r   rJ   boolrK   r   r>   int | IntOrNoner0   )rN   r@   rO   r   rP   r-   r,   r   rQ   r   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rI   r   rJ   r   rK   r   r>   r   )NN)rN   r@   rO   r   rP   r   r,   r-   rQ   r   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rI   r   rJ   r   rK   r   r>   r-   )NNrG   )rN   r@   rO   r   rP   r   r,   r   rQ   r-   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rI   r   rJ   r   rK   r   r>   r   )
NNrG   NNNNNNN)rN   r@   rO   float | NonerP   r   r,   zFloatOrNone | Literal['min']rQ   r   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rI   r   rJ   r   rK   r   r>   zfloat | FloatOrNone)rN   r@   rO   r+   rP   r+   r,   Number | Literal['min'] | NonerQ   r+   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rI   r   rJ   r   rK   r   r>   r+   ) rN   r@   rO   r+   rP   r+   r,   r   rQ   r+   rR   r   rS   r   rT   r   rU   r   rV   r   rW   r   rI   r   rJ   r   rK   r   r`   zScriptRunContext | Noner>   r+   )r>   r%   )	rA   rB   rC   r   rX   r   ra   propertyr|   r1   r6   r4   rF   rF   S   s    
 !%,1 |@	 _c  v{  aj		 	 		
 *	 	 	 )3	 BL	 `u	 DU	 fy	 R\	 os	 O^	 
	 	  !%
 -2!Tdw{  X\  |@  \`  sx  ^g

 

 
 *
 
 
 )3
 BL
 `u
 DU
 fy
 OY
 lp
 L[
 

 
  !% $	
  !Tdw{  X\  |@  \`  sx  ^g

 
 	
 
 
 
 )3
 BL
 `u
 DU
 fy
 OY
 lp
 L[
 

 
   !% $,1
 "Tdw{  X\  |@  \`  sx  ^g

 
 	

 *
 
 
 )3
 BL
 `u
 DU
 fy
 OY
 lp
 L[
 

 
   #'"&.3! |@	 _c  v{  aj		  	  		
 ,	 	 	 )3	 BL	 `u	 DU	 fy	 R\	 os	 O^	 
	 	 N# $(#'05"!+/"&&*c
 #',5!c
c
 !c
 !	c

 .c
 c
 c
 c
 c
 )c
  c
 $c
  c
 c
  *!c
" 
#c
 $c
P $(#'05"!+/"&&*D" #',5'+#D"D" !D" !	D"
 .D" D" D" D" D" )D"  D" $D"  D" D"  *!D"" %#D"$ 
%D"L , ,r6   rF   )<
__future__r   rh   dataclassesr   textwrapr   typingr   r   r   r	   r
   r   typing_extensionsr   !streamlit.elements.lib.form_utilsr    streamlit.elements.lib.js_numberr   r   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   streamlit.errorsr   r   r   r   r   streamlit.proto.NumberInput_pb2r   r8   streamlit.runtime.metrics_utilr   streamlit.runtime.scriptrunnerr   r   streamlit.runtime.stater    r!   r"   r#   r$   streamlit.delta_generatorr%   r-   rp   r&   rD   r'   r(   r*   rF   r1   r6   r4   <module>r      s    #  !  I I ' = N   L 9 O  8 #u*%	 %Kd+	mUD1   $F, F,r6   