
    ch7X                       % S SK Jr  S SKrS SKrS SKrS SKJrJrJr  S SK	J
r
JrJrJrJrJr  S SKJr  S SKJrJrJrJrJr  S SKJrJr  S SKJr  S S	KJr  S S
KJ r   S SK!J"r"J#r#  \(       a  S SK$J%r%  \RL                  \RN                  \RP                  \RR                  \RT                  4r+S\,S'   \" \-5      r.S\,S'   Sr/S\,S'    " S S\0\   5      r1 " S S5      r2g)    )annotationsN)ChainMapUserDictUserList)AsyncGenerator	Generator	ItemsViewIterableKeysView
ValuesView)StringIO)TYPE_CHECKINGAnyCallableFinalcast)dataframe_util	type_util)StreamlitAPIException)
get_logger)gather_metrics)is_mem_address_strmax_char_sequence)DeltaGeneratorzFinal[tuple[type[Any], ...]]
HELP_TYPESr   _LOGGERu    ▏_TEXT_CURSORc                      \ rS rSrSrg)StreamingOutput@    N)__name__
__module____qualname____firstlineno____static_attributes__r!       kC:\Users\julio\OneDrive\Documentos\Trabajo\Ideas Frescas\venv\Lib\site-packages\streamlit/elements/write.pyr   r   @   s    r'   r   c                  x    \ rS rSr\" S5          SS j5       r\" S5      SS.SS jj5       r\SS j5       rS	r	g
)
WriteMixinD   write_streamc                  ^^^	 [        U[        5      (       d  [        R                  " U5      (       a  [	        S[        U5       S35      eSmSm[        5       m	SUUU	4S jjn[        R                  " U5      (       d  [        R                  " U5      (       a  U" 5       n[        R                  " U5      (       a  [        R                  " U5      n [        U5        U GHk  n[        R                  " U5      (       ad   [!        UR"                  5      S:X  d  UR"                  S   R$                  c  SnO-UR"                  S   R$                  R&                  =(       d    Sn [        R*                  " US
5      (       a   UR&                  =(       d    Sn[        U[        5      (       aW  U(       d  M  SnT(       d  U R,                  R/                  5       mSnTU-  mTR1                  TU(       a  SO[2        -   5        GM!  [5        U5      (       a  U" 5         U" 5         GMB  U" 5         U R7                  U5        T	R9                  U5        GMn     U" 5         T	(       d  g[!        T	5      S:X  a  [        T	S   [        5      (       a  T	S   $ T	$ ! [         a  n[	        S[        U5       S35      UeSnAff = f! [(         a  n[	        S	5      UeSnAff = f! [(         a  n[	        S5      UeSnAff = f)a  Stream a generator, iterable, or stream-like sequence to the app.

``st.write_stream`` iterates through the given sequences and writes all
chunks to the app. String chunks will be written using a typewriter effect.
Other data types will be written using ``st.write``.

Parameters
----------
stream : Callable, Generator, Iterable, OpenAI Stream, or LangChain Stream
    The generator or iterable to stream.

    If you pass an async generator, Streamlit will internally convert
    it to a sync generator. If the generator depends on a cached object
    with async references, this can raise an error.

    .. note::
        To use additional LLM libraries, you can create a wrapper to
        manually define a generator function and include custom output
        parsing.

Returns
-------
str or list
    The full response. If the streamed output only contains text, this
    is a string. Otherwise, this is a list of all the streamed objects.
    The return value is fully compatible as input for ``st.write``.

Example
-------
You can pass an OpenAI stream as shown in our tutorial, `Build a         basic LLM chat app <https://docs.streamlit.io/develop/tutorials/llms        /build-conversational-apps#build-a-chatgpt-like-app>`_. Alternatively,
you can pass a generic generator function as input:

>>> import time
>>> import numpy as np
>>> import pandas as pd
>>> import streamlit as st
>>>
>>> _LOREM_IPSUM = """
>>> Lorem ipsum dolor sit amet, **consectetur adipiscing** elit, sed do eiusmod tempor
>>> incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis
>>> nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
>>> """
>>>
>>>
>>> def stream_data():
>>>     for word in _LOREM_IPSUM.split(" "):
>>>         yield word + " "
>>>         time.sleep(0.02)
>>>
>>>     yield pd.DataFrame(
>>>         np.random.randn(5, 10),
>>>         columns=["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"],
>>>     )
>>>
>>>     for word in _LOREM_IPSUM.split(" "):
>>>         yield word + " "
>>>         time.sleep(0.02)
>>>
>>>
>>> if st.button("Stream data"):
>>>     st.write_stream(stream_data)

..  output::
    https://doc-write-stream-data.streamlit.app/
    height: 550px

zI`st.write_stream` expects a generator or stream-like object as input not z3. Please use `st.write` instead for this data type.N c                 r   > T(       a/  T (       a'  T R                  T5        TR                  T5        Sm Smggg)z#Write the full response to the app.Nr.   )markdownappend)stream_containerstreamed_responsewritten_contents   r(   flush_stream_response6WriteMixin.write_stream.<locals>.flush_stream_response   s=    
 !%5 ))*;<&&'89#' $&! &6 r'   zThe provided input (type: z^) cannot be iterated. Please make sure that it is a generator, generator function or iterable.r   a8  Failed to parse the OpenAI ChatCompletionChunk. The most likely cause is a change of the chunk object structure due to a recent OpenAI update. You might be able to fix this by downgrading the OpenAI library or upgrading Streamlit. Also, please report this issue to: https://github.com/streamlit/streamlit/issues.z)langchain_core.messages.ai.AIMessageChunka9  Failed to parse the LangChain AIMessageChunk. The most likely cause is a change of the chunk object structure due to a recent LangChain update. You might be able to fix this by downgrading the OpenAI library or upgrading Streamlit. Also, please report this issue to: https://github.com/streamlit/streamlit/issues.FT   returnNone)
isinstancestrr   is_dataframe_liker   typer   inspectisgeneratorfunctionisasyncgenfunction
isasyncgenr   async_generator_to_synciter	TypeErroris_openai_chunklenchoicesdeltacontentAttributeErroris_typedgemptyr0   r   callablewriter1   )
selfstreamr5   excchunkerr
first_textr2   r3   r4   s
          @@@r(   r,   WriteMixin.write_streamE   s   ` fc""n&F&Fv&N&N'F|n %""  37!#%4%6
	' 
	' &&v..'2L2LV2T2TXF f%%66v>F	L E((//5==)Q.%--2B2H2H2P !# %a 0 6 6 > > D"   (STT	!MM/RE %%%"
''+ww}}$!%J!U*! ))%z|L %%'%'

5!&&u-i l 	1$OA4F)L)L"1%% Q  	',T&\N ;[ [ 	$ & /f  & /f sN   J  5J86,J8 K
J5J00J58
KKK
K1 K,,K1rP   Funsafe_allow_htmlc                 ^ ^^ U(       a  [         R                  SU5        [        U5      S:X  a6  [        US   [        5      (       a  T R
                  R                  US   TS9  g/ mT R
                  R                  (       d  [        U5      S:  a  [        S5      eSU UU4S jjnU GHK  n[        U[        5      (       a  TR                  U5        M,  [        U[        5      (       aB  U" 5         U H3  n[        U5      (       a  U" 5         U" 5         M#  T R                  UTS9  M5     M  [        U[        5      (       a$  U" 5         T R
                  R                  U5        M  [        R                   " U5      (       a$  U" 5         T R
                  R#                  U5        M  [$        R&                  " U5      (       a%  U" 5         T R
                  R)                  U5        GM;  [        R*                  " U5      (       a%  U" 5         T R
                  R-                  U5        GM{  [        R.                  " US5      (       a%  U" 5         T R
                  R1                  U5        GM  [        R2                  " U5      (       a%  U" 5         T R
                  R5                  U5        GM  [        R.                  " US	5      (       a%  U" 5         T R
                  R7                  U5        GM=  [        R8                  " U5      (       a%  U" 5         T R
                  R;                  U5        GM}  [        R<                  " U5      (       a%  U" 5         T R
                  R?                  U5        GM  [        R@                  " U5      (       a%  U" 5         T R
                  RC                  U5        GM  [        RD                  " U5      (       aJ  SS
K#J$n  U" 5         URK                  U5      nT R
                  R;                  URM                  5       5        GMb  [        U[N        [P        [R        [T        [V        RX                  [Z        [\        [^        [`        [b        [d        45      (       dQ  [        Rf                  " U5      (       d6  [        Rh                  " U5      (       d  [        Rj                  " U5      (       a%  U" 5         T R
                  Rm                  U5        GM*  [        Rn                  " U5      (       a%  U" 5         T R
                  Rq                  U5        GMj  [        U[r        5      (       a3  U" 5         T R
                  R                  URu                  5       5        GM  [v        Rx                  " U5      (       dm  [v        Rz                  " U5      (       dR  [v        R|                  " U5      (       d7  [v        R~                  " U5      (       d  [        R.                  " US5      (       a  U" 5         T R                  U5        GMU  [        U[        5      (       d  [        R                  " U5      (       a%  U" 5         T R
                  R#                  U5        GM  [v        R                  " U5      (       a/  U" 5         T R
                  R#                  [        SU5      5        GM  T(       aH  [        R                  " US5      (       a,  T R
                  R                  UR                  5       5        GMC  [        R                  " US5      (       d  [        R                  " US5      (       a%  U" 5         T R
                  R)                  U5        GM  [	        U5      n	[        U	5      (       a%  U" 5         T R
                  R#                  U5        GM  SU	;   a:  [        S[        U	S5      S-   5      n
SU
-  nTR                  U SU	 SU 35        GM   [        U	S5      S-   n
SU
-  nTR                  U U	 U 35        GMN     U" 5         g)a  Displays arguments in the app.

This is the Swiss Army knife of Streamlit commands: it does different
things depending on what you throw at it. Unlike other Streamlit
commands, ``st.write()`` has some unique properties:

- You can pass in multiple arguments, all of which will be displayed.
- Its behavior depends on the input type(s).

Parameters
----------
*args : any
    One or many objects to display in the app.

    .. list-table:: Each type of argument is handled as follows:
        :header-rows: 1

        * - Type
          - Handling
        * - ``str``
          - Uses ``st.markdown()``.
        * - dataframe-like, ``dict``, or ``list``
          - Uses ``st.dataframe()``.
        * - ``Exception``
          - Uses ``st.exception()``.
        * - function, module, or class
          - Uses ``st.help()``.
        * - ``DeltaGenerator``
          - Uses ``st.help()``.
        * - Altair chart
          - Uses ``st.altair_chart()``.
        * - Bokeh figure
          - Uses ``st.bokeh_chart()``.
        * - Graphviz graph
          - Uses ``st.graphviz_chart()``.
        * - Keras model
          - Converts model and uses ``st.graphviz_chart()``.
        * - Matplotlib figure
          - Uses ``st.pyplot()``.
        * - Plotly figure
          - Uses ``st.plotly_chart()``.
        * - ``PIL.Image``
          - Uses ``st.image()``.
        * - generator or stream (like ``openai.Stream``)
          - Uses ``st.write_stream()``.
        * - SymPy expression
          - Uses ``st.latex()``.
        * - An object with ``._repr_html()``
          - Uses ``st.html()``.
        * - Database cursor
          - Displays DB API 2.0 cursor results in a table.
        * - Any
          - Displays ``str(arg)`` as inline code.

unsafe_allow_html : bool
    Whether to render HTML within ``*args``. This only applies to
    strings or objects falling back on ``_repr_html_()``. If this is
    ``False`` (default), any HTML tags found in ``body`` will be
    escaped and therefore treated as raw text. If this is ``True``, any
    HTML expressions within ``body`` will be rendered.

    Adding custom HTML to your app impacts safety, styling, and
    maintainability.

    .. note::
        If you only want to insert HTML or CSS without Markdown text,
        we recommend using ``st.html`` instead.

**kwargs : any
    Keyword arguments. Not used.

.. deprecated::
    ``**kwargs`` is deprecated and will be removed in a later version.
    Use other, more specific Streamlit commands to pass additional
    keyword arguments.

Returns
-------
None

Examples
--------
Its basic use case is to draw Markdown-formatted text, whenever the
input is a string:

>>> import streamlit as st
>>>
>>> st.write("Hello, *World!* :sunglasses:")

..  output::
    https://doc-write1.streamlit.app/
    height: 150px

As mentioned earlier, ``st.write()`` also accepts other data formats, such as
numbers, data frames, styled data frames, and assorted objects:

>>> import streamlit as st
>>> import pandas as pd
>>>
>>> st.write(1234)
>>> st.write(
...     pd.DataFrame(
...         {
...             "first column": [1, 2, 3, 4],
...             "second column": [10, 20, 30, 40],
...         }
...     )
... )

..  output::
    https://doc-write2.streamlit.app/
    height: 350px

Finally, you can pass in multiple arguments to do things like:

>>> import streamlit as st
>>>
>>> st.write("1 + 1 = ", 2)
>>> st.write("Below is a DataFrame:", data_frame, "Above is a dataframe.")

..  output::
    https://doc-write3.streamlit.app/
    height: 410px

Oh, one more thing: ``st.write`` accepts chart objects too! For example:

>>> import altair as alt
>>> import pandas as pd
>>> import streamlit as st
>>> from numpy.random import default_rng as rng
>>>
>>> df = pd.DataFrame(rng(0).standard_normal((200, 3)), columns=["a", "b", "c"])
>>> chart = (
...     alt.Chart(df)
...     .mark_circle()
...     .encode(x="a", y="b", size="c", color="c", tooltip=["a", "b", "c"])
... )
>>>
>>> st.write(chart)

..  output::
    https://doc-vega-lite-chart.streamlit.app/
    height: 300px

zInvalid arguments were passed to "st.write" function. Support for passing such unknown keywords arguments will be dropped in future. Invalid arguments were: %sr7   r   rX   NzCannot replace a single element with multiple elements.

The `write()` method only supports multiple elements when inserting elements rather than replacing. That is, only when called as `st.write()` or `st.sidebar.write()`.c                    > T(       aA  SR                  T5      n TR                  R                  5       nUR                  U TS9  / TS S & g g )N rX   )joinrM   rN   r0   )text_contenttext_containerrQ   string_bufferrY   s     r(   flush_buffer&WriteMixin.write.<locals>.flush_buffer  sO    "xx6 "&'' &7 (  $&a  r'   zmatplotlib.figure.Figurezbokeh.plotting.figure.Figure)	vis_utilszopenai.Streamr>   _repr_html_	to_pandas__dataframe__
   `r8   )Lr   warningrG   r;   r<   rM   r0   _is_top_levelr   r1   r   rO   rP   	Exception	exceptionr   is_delta_generatorhelpr   r=   	dataframeis_altair_chartaltair_chartrL   pyplotis_plotly_chartplotly_chartbokeh_chartis_graphviz_chartgraphviz_chartis_sympy_expressionlatexis_pillow_imageimageis_keras_modeltensorflow.python.keras.utilsrc   model_to_dot	to_stringdictlistmap	enumeratetypesMappingProxyTyper   r   r   r	   r   r   is_custom_dictis_namedtupleis_pydantic_modeljson	is_pydeckpydeck_chartr   getvaluer?   isgeneratorr@   rA   rB   r,   r   dataclassesis_dataclassisclassr   has_callable_attrhtmlrd   r   maxr   )rQ   rY   argskwargsra   argitemrc   dotstringified_argbacktick_countbacktick_wrapperr`   s   ``          @r(   rP   WriteMixin.write   s   f OO- 	 t9>ja#66
 GGT!W8IJ#%
 ww$$TQ'G 
	& 
	& C#s##$$S)C11D~~$

4;L
M   C++!!#&--c22S!11#66!!#&**3//$$S)""3(BCCs#**3//$$S)""3(FGG##C(,,S11&&s+..s33c"**3//c"))#.. ,,S1&&s}}7!..   ! "   ++C00**3//..s33S!$$S))$$S)C**  0##C((..s33--c22%%c**$$S/::!!#&C,,0H0H0M0MS!%% T&#./"y'B'B3'V'VS__./,,[ ,,S/BB !!#&"%c(%o66 NGGLL%_, &),=os,SVW,W%XN'*^';$!((+,B.?rBRAST &7%Lq%PN'*^';$!((+,_,=>N=OPA H 	r'   c                    [        SU 5      $ )zGet our DeltaGenerator.r   )r   )rQ   s    r(   rM   WriteMixin.dgB  s     $d++r'   r!   N)rR   zXCallable[..., Any] | Generator[Any, Any, Any] | Iterable[Any] | AsyncGenerator[Any, Any]r9   zlist[Any] | str)r   r   rY   boolr   r   r9   r:   )r9   r   )
r"   r#   r$   r%   r   r,   rP   propertyrM   r&   r!   r'   r(   r*   r*   D   se    N#x#x 
x $xt G:?  B
 , ,r'   r*   )3
__future__r   r   r?   r   collectionsr   r   r   collections.abcr   r   r	   r
   r   r   ior   typingr   r   r   r   r   	streamlitr   r   streamlit.errorsr   streamlit.loggerr   streamlit.runtime.metrics_utilr   streamlit.string_utilr   r   streamlit.delta_generatorr   BuiltinFunctionTypeBuiltinMethodTypeFunctionType
MethodType
ModuleTyper   __annotations__r"   r   r   r   r   r*   r!   r'   r(   <module>r      s    #    4 4    0 2 ' 9
 8 
				,
(  H% %e 	d3i 	A, A,r'   