
    ȯeiǖ                       U d dl mZ d dlmZmZmZ d dlmZmZ d dl	m
Z
 d dlmZmZmZ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mZ d dlmZm Z m!Z!m"Z" d dl#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/m0Z1 d dl2m3Z4 d dl5m6Z7 d dl5m8Z9 d dl5m:Z; d dl<m=Z= d dl>m?Z? d dl@mAZA d dlBmCZC d dlDmEZE d dlFmGZGmHZHmIZImJZJ d dlKmLZL d dlMmNZNmOZO d dlPmQZQmRZR erd dlSmTZT dZUd eVd!<    eWh d"      ZXd#eVd$<   e G d% d&eeYef                Z6 G d' d(eYe
      ZZ	 	 	 	 	 	 d1d)Z[	 	 	 	 d2d*Z\	 	 	 	 d3d+Z]e G d, d-             Z^ G d. d/      Z_y0)4    )annotations)IteratorMutableMappingSequence)	dataclassfield)Enum)TYPE_CHECKINGAnyLiteralcastoverload)configruntime)get_dg_singleton_instance)enforce_filename_restrictionnormalize_upload_file_type)
is_in_form)AtomicImageimage_to_url)LayoutConfigWidthWidthWithoutContentvalidate_width)check_widget_policies)Keycompute_and_register_element_id&get_chat_input_accept_file_proto_valuesave_for_app_testingto_key)ALLOWED_SAMPLE_RATES)StreamlitAPIException)Block)	ChatInput)ChatInputValue)FileUploaderState)UploadedFileInfo)RootContainer)WidthConfig)MemoryUploadedFileManager)gather_metrics)get_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)get_session_state)DeletedFileUploadedFile)is_emojivalidate_material_icon)DeltaGeneratorz.wavstr_ACCEPTED_AUDIO_EXTENSION>   	audio/wav
audio/waveaudio/x-wavzfrozenset[str]_ACCEPTED_AUDIO_MIME_TYPESc                      e Zd ZU dZded<    ee      Zded<   dZded	<    ed
d
d
      Z	ded<    ed
d
d
      Z
ded<    ed
d
d
      Zded<   ddZddZddZddZd dZd!dZd"dZd#dZd$dZd%dZy)&r%   a  Represents the value returned by `st.chat_input` after user interaction.

    This dataclass contains the user's input text, any files uploaded, and optionally
    an audio recording. It provides a dict-like interface for accessing and modifying
    its attributes.

    Attributes
    ----------
    text : str
        The text input provided by the user.
    files : list[UploadedFile]
        A list of files uploaded by the user. Only present when accept_file=True.
    audio : UploadedFile or None, optional
        An audio recording uploaded by the user, if any. Only present when accept_audio=True.

    Notes
    -----
    - Supports dict-like access via `__getitem__`, `__setitem__`, and `__delitem__`.
    - Use `to_dict()` to convert the value to a standard dictionary.
    - The 'files' key is only present when accept_file=True.
    - The 'audio' key is only present when accept_audio=True.
    r7   text)default_factorylist[UploadedFile]filesNUploadedFile | NoneaudioF)defaultreprcomparebool_include_files_include_audio)initrE   rF   tuple[str, ...]_included_keysc                    dg}| j                   r|j                  d       | j                  r|j                  d       t        j	                  | dt        |             y)z9Compute and cache the included keys after initialization.r>   rA   rC   rL   N)rH   appendrI   object__setattr__tuple)selfkeyss     a/var/www/html/glpi_dashboard/venv/lib/python3.12/site-packages/streamlit/elements/widgets/chat.py__post_init__zChatInputValue.__post_init__y   sJ    !(KK KK 4!15;?    c                    | j                   S )zEReturn tuple of keys that should be exposed based on inclusion flags.)rL   rR   s    rT   _get_included_keysz!ChatInputValue._get_included_keys   s    """rV   c                4    t        | j                               S N)lenrY   rX   s    rT   __len__zChatInputValue.__len__   s    4**,--rV   c                4    t        | j                               S r[   )iterrY   rX   s    rT   __iter__zChatInputValue.__iter__   s    D++-..rV   c                H    t        |t              sy|| j                         v S )NF)
isinstancer7   rY   rR   keys     rT   __contains__zChatInputValue.__contains__   s#    #s#d--///rV   c                    || j                         vrt        d|       	 t        | |      S # t        $ r t        d|       d w xY wNzInvalid key: )rY   KeyErrorgetattrAttributeError)rR   items     rT   __getitem__zChatInputValue.__getitem__   sZ    t..00]4&122	=4&& 	=]4&12<	=s	   . Ac                    |dk(  r!t         j                  | d      st        d      |dk(  r!t         j                  | d      st        d      t         j                  | |      S )NrA   rH   zD'ChatInputValue' object has no attribute 'files' (accept_file=False)rC   rI   zE'ChatInputValue' object has no attribute 'audio' (accept_audio=False))rO   __getattribute__rj   )rR   names     rT   rn   zChatInputValue.__getattribute__   si     7?6#:#:4AQ#R V  7?6#:#:4AQ#R W  &&tT22rV   c                ^    || j                         vrt        d|       t        | ||       y rg   )rY   rh   setattr)rR   rd   values      rT   __setitem__zChatInputValue.__setitem__   s1    d--//]3%011c5!rV   c                    || j                         vrt        d|       	 t        | |       y # t        $ r t        d|       d w xY wrg   )rY   rh   delattrrj   rc   s     rT   __delitem__zChatInputValue.__delitem__   sW    d--//]3%011	<D# 	<]3%01t;	<s	   / Ac                    d| j                   i}| j                  r| j                  |d<   | j                  r| j                  |d<   |S )Nr>   rA   rC   )r>   rH   rA   rI   rC   )rR   results     rT   to_dictzChatInputValue.to_dict   sF    DIIM
 "jjF7O"jjF7OrV   )returnNone)rz   rK   )rz   int)rz   zIterator[str])rd   rO   rz   rG   )rk   r7   rz   z.str | list[UploadedFile] | UploadedFile | None)ro   r7   rz   r   )rd   r7   rr   r   rz   r{   )rd   r7   rz   r{   )rz   z9dict[str, str | list[UploadedFile] | UploadedFile | None])__name__
__module____qualname____doc____annotations__r   listrA   rC   rH   rI   rL   rU   rY   r]   r`   re   rl   rn   rs   rv   ry    rV   rT   r%   r%   Y   s    . I %d ;E;!%E% UEJNDJ UEJNDJ&+UE&RNOR@#./0
=3"
<rV   r%   c                      e Zd ZdZdZdZdZy)PresetNamesuser	assistantaihumanN)r}   r~   r   USER	ASSISTANTAIHUMANr   rV   rT   r   r      s    DI	BErV   r   c           	     r   t         j                  j                  }| |j                  dfS t	        | t
              rS| t        D ch c]  }|j                   c}v r3|j                  | t        j                  t        j                  fv rdfS dfS t	        | t
              rt        |       r|j                  | fS t	        | t
              r(| j                  d      r|j                  t        |       fS 	 |j                  t        | t!        d      dd	d
|      fS c c}w # t"        $ r}t%        d      |d}~ww xY w)a  Detects the avatar type and prepares the avatar data for the frontend.

    Parameters
    ----------
    avatar :
        The avatar that was provided by the user.
    delta_path : str
        The delta path is used as media ID when a local image is served via the media
        file manager.

    Returns
    -------
    Tuple[AvatarType, str]
        The detected avatar type and the prepared avatar data.
    N r   r   z	:materialcontentwidthFRGBauto)layout_configclampchannelsoutput_formatimage_idz5Failed to load the provided avatar value as an image.)
BlockProtoChatMessage
AvatarTypeICONrb   r7   r   rr   r   r   r4   EMOJI
startswithr5   IMAGEr   r   	Exceptionr"   )avatar
delta_pathr   rk   exs        rT   _process_avatar_inputr      s:   $ ''22J~""&#6[-QTdjj-Q#Q OO knnk.C.CDD 
 	

 
 	
 &#8F#3''&#6#4#4[#A 6v >>>&Y7 "
 
 	
! .R0  #C
	s   D0&D 	D6%D11D6c                \   | g S t               }|g S | j                  }t        |      dk(  rg S |j                  j	                  |j
                  |D cg c]  }|j                   c}      }|D ci c]  }|j                  | }}g }|D ]  }|j                  |j                        }|!t        ||j                        }|j                  |       t        |j                  t              sc|j                  j                  |j
                  |j                          |S c c}w c c}w )Nr   
session_idfile_idsr   file_id)r,   uploaded_file_infor\   uploaded_file_mgr	get_filesr   r   getr3   	file_urlsrN   rb   r*   remove_file)	files_valuectxr   ffile_recs_list	file_recscollected_filesmaybe_file_recuploaded_files	            rT   _pop_upload_filesr      s'    	

C
{	$77
!#	**44>>%78!))8 5 N
 (66!A6I6*,O "qyy1%(EM""=1 #//1JK%%11"~~II 2   / 9 7s   D$
2D)c                v   | yt               }|y|j                  j                  |j                  | j                  g      }t        |      dk(  ry|d   }t        || j                        }|j                  j                         j                  t              s t        d|j                   dt         d      |j                  t        vr t        d|j                   dt         d	      | rKt        |j                  t               r1|j                  j#                  |j                  | j                  
       |S )a  Extract and return a single audio file from the protobuf message.

    Similar to _pop_upload_files but handles a single audio file instead of a list.
    Validates that the uploaded file is a WAV file.

    Parameters
    ----------
    audio_file_info : UploadedFileInfoProto or None
        The protobuf message containing information about the uploaded audio file.

    Returns
    -------
    UploadedFile or None
        The extracted audio file if available, None otherwise.

    Raises
    ------
    StreamlitAPIException
        If the uploaded audio file does not have a `.wav` extension or its MIME type is not
        one of the accepted WAV types (`audio/wav`, `audio/wave`, `audio/x-wav`).
    Nr   r   z)Invalid file extension for audio input: `z`. Only WAV files (z) are accepted.z$Invalid MIME type for audio input: `z`. Expected one of .r   )r,   r   r   r   r   r\   r3   r   ro   lowerendswithr8   r"   typer<   rb   r*   r   )audio_file_infor   r   file_recr   s        rT   _pop_audio_filer   $  sM   0 

C
{**44>>!))* 5 N
 >aa H ?+D+DEM ##%../HI#78J8J7K L89J
 	
 !;;#2=3E3E2F G9:!=
 	
 :c&;&;=VW))~~#++ 	* 	

 rV   c                  P    e Zd ZU dZded<   dZded<   dZded<   	 	 	 	 d
dZdd	Zy)ChatInputSerdeFrG   accept_filesaccept_audioNzSequence[str] | Noneallowed_typesc                   ||j                  d      sy | j                  s| j                  s|j                  S t	        |j
                        }|D ]@  }| j                  st        |t              r!t        |j                  | j                         B t        |j                  d      r|j                  nd       }t        |j                  ||| j                  | j                        S )Ndatar   )r>   rA   rC   rH   rI   )HasFieldr   r   r   r   file_uploader_stater   rb   r2   r   ro   r   r   r%   )rR   ui_valueuploaded_filesfile
audio_files        rT   deserializezChatInputSerde.deserializeo  s     8#4#4V#<  ):):== *8+G+GH" 	LD!!*T;*G,TYY8J8JK	L
 %(0(9(9:K(LH$$RV

  ,,,,
 	
rV   c                    t        |      S )N)r   )ChatInputValueProto)rR   vs     rT   	serializezChatInputSerde.serialize  s    "**rV   )r   zChatInputValueProto | Nonerz   str | ChatInputValue | None)r   
str | Nonerz   r   )	r}   r~   r   r   r   r   r   r   r   r   rV   rT   r   r   i  s;    L$L$*.M'.
2
	$
2+rV   r   c                     e Zd Z e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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d	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zedd       Zy)	ChatMixinchat_messageNstretch)r   r   c                  |t        d      |I|j                         t        D ch c]  }|j                   c}v st	        |      r|j                         }t        || j                  j                               \  }}t        |d       t        j                         }||_        ||_        ||_        t               }t        |t               r||_        n|dk(  rd|_        nd|_        t               }	d|	_        |	j*                  j-                  |       |	j.                  j-                  |       | j                  j1                  |	      S c c}w )u  Insert a chat message container.

        To add elements to the returned container, you can use ``with`` notation
        (preferred) or just call methods directly on the returned object. See the
        examples below.

        .. note::
            To follow best design practices and maintain a good appearance on
            all screen sizes, don't nest chat message containers.

        Parameters
        ----------
        name : "user", "assistant", "ai", "human", or str
            The name of the message author. Can be "human"/"user" or
            "ai"/"assistant" to enable preset styling and avatars.

            Currently, the name is not shown in the UI but is only set as an
            accessibility label. For accessibility reasons, you should not use
            an empty string.

        avatar : Anything supported by st.image (except list), str, or None
            The avatar shown next to the message.

            If ``avatar`` is ``None`` (default), the icon will be determined
            from ``name`` as follows:

            - If ``name`` is ``"user"`` or ``"human"``, the message will have a
              default user icon.

            - If ``name`` is ``"ai"`` or ``"assistant"``, the message will have
              a default bot icon.

            - For all other values of ``name``, the message will show the first
              letter of the name.

            In addition to the types supported by |st.image|_ (except list),
            the following strings are valid:

            - A single-character emoji. For example, you can set ``avatar="🧑‍💻"``
              or ``avatar="🦖"``. Emoji short codes are not supported.

            - An icon from the Material Symbols library (rounded style) in the
              format ``":material/icon_name:"`` where "icon_name" is the name
              of the icon in snake case.

              For example, ``icon=":material/thumb_up:"`` will display the
              Thumb Up icon. Find additional icons in the `Material Symbols               <https://fonts.google.com/icons?icon.set=Material+Symbols&icon.style=Rounded>`_
              font library.

            - ``"spinner"``: Displays a spinner as an icon.

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

        width : "stretch", "content", or int
            The width of the chat message container. This can be one of the following:

            - ``"stretch"`` (default): The width of the container matches the
              width of the parent container.
            - ``"content"``: The width of the container matches the width of its
              content, but doesn't exceed the width of the parent container.
            - An integer specifying the width in pixels: The container has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the container matches the width
              of the parent container.

        Returns
        -------
        Container
            A single container that can hold multiple elements.

        Examples
        --------
        You can use ``with`` notation to insert any element into an expander

        >>> import streamlit as st
        >>> import numpy as np
        >>>
        >>> with st.chat_message("user"):
        ...     st.write("Hello 👋")
        ...     st.line_chart(np.random.randn(30, 3))

        .. output::
            https://doc-chat-message-user.streamlit.app/
            height: 450px

        Or you can just call methods directly in the returned objects:

        >>> import streamlit as st
        >>> import numpy as np
        >>>
        >>> message = st.chat_message("assistant")
        >>> message.write("Hello human")
        >>> message.bar_chart(np.random.randn(30, 3))

        .. output::
            https://doc-chat-message-user1.streamlit.app/
            height: 450px

        zWThe author name is required for a chat message, please set it via the parameter `name`.T)allow_contentr   )block_proto)r"   r   r   rr   r4   r   dg_get_delta_path_strr   r   r   ro   r   avatar_typer)   rb   r|   pixel_widthuse_contentuse_stretchallow_emptyr   CopyFromwidth_config_block)
rR   ro   r   r   rk   r   converted_avatarmessage_container_protor   r   s
             rT   r   zChatMixin.chat_message  s/   Z <'i  >JJLK@DTZZ@@HTN ZZ\F(=DGG//1)
%% 	uD1","8"8":'+$)9&.9+ #}eS!',L$i'+L$'+L$ l"&  ))*AB  )),7ww~~+~66; As   EF)
rd   	max_charsaccept_file	file_typer   disabled	on_submitargskwargsr   c       
             y r[   r   )rR   placeholderrd   r   r   r   r   r   r   r   r   r   s               rT   
chat_inputzChatMixin.chat_input  s     rV   i>  )
rd   r   r   r   audio_sample_rater   r   r   r   r   c                    y r[   r   rR   r   rd   r   r   r   r   r   r   r   r   r   r   s                rT   r   zChatMixin.chat_input0        !$rV   )
rd   r   r   r   r   r   r   r   r   r   c                    y r[   r   r   s                rT   r   zChatMixin.chat_inputB  r   rV   r   )rd   r   r   r   r   r   r   r   r   r   r   c                  t        |      }t        | j                  ||	dd       |dvrt        d      t	               }t        d|h d| j                  |||||||      }|rt        |      }|'|t        vrt        d	| d
t        t               d      t        j                         r t        | j                        rt        d      t        | j                  j                  j                        }| j                  j                  j                  t         j"                  k(  r|sd}nd}t%               }||_        t)        |      |_        |||_        d|_        t1        |      |_        ||ng |j4                  dd t7        j8                  d      |_        ||_        |||_        tA        |dv ||      }tC        |j&                  |	|
||jD                  |jF                  |d      }tI        |       tK        |      }||_&        |jN                  rF|jP                  :|jP                  |_(        d|_)        tU               }|||v r|jW                  |d       |rtY        |||jP                         |dk(  r't[               j\                  j_                  d||       n| j                  j_                  d||       |jN                  s|jP                  S dS )a(  Display a chat input widget.

        Parameters
        ----------
        placeholder : str
            A placeholder text shown when the chat input is empty. This
            defaults to ``"Your message"``. For accessibility reasons, you
            should not use an empty string.

        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.

        max_chars : int or None
            The maximum number of characters that can be entered. If this is
            ``None`` (default), there will be no maximum.

        accept_file : bool, "multiple", or "directory"
            Whether the chat input should accept files. This can be one of the
            following values:

            - ``False`` (default): No files are accepted and the user can only
              submit a message.
            - ``True``: The user can add a single file to their submission.
            - ``"multiple"``: The user can add multiple files to their
              submission.
            - ``"directory"``: The user can add multiple files to their
              submission by selecting a directory. If ``file_type`` is set,
              only files matching those type(s) will be uploaded.

            By default, uploaded files are limited to 200 MB each. You can
            configure this using the ``server.maxUploadSize`` config option.
            For more information on how to set config options, see
            |config.toml|_.

            .. |config.toml| replace:: ``config.toml``
            .. _config.toml: https://docs.streamlit.io/develop/api-reference/configuration/config.toml

        file_type : str, Sequence[str], or None
            The allowed file extension(s) for uploaded files. This can be one
            of the following types:

            - ``None`` (default): All file extensions are allowed.
            - A string: A single file extension is allowed. For example, to
              only accept CSV files, use ``"csv"``.
            - A sequence of strings: Multiple file extensions are allowed. For
              example, to only accept JPG/JPEG and PNG files, use
              ``["jpg", "jpeg", "png"]``.

            .. note::
                This is a best-effort check, but doesn't provide a
                security guarantee against users uploading files of other types
                or type extensions. The correct handling of uploaded files is
                part of the app developer's responsibility.

        accept_audio : bool
            Whether to show an audio recording button in the chat input. This
            defaults to ``False``. If this is ``True``, users can record and
            submit audio messages. Recorded audio is available as an
            ``UploadedFile`` object with MIME type ``audio/wav``.

        audio_sample_rate : int or None
            The target sample rate for audio recording in Hz when
            ``accept_audio`` is ``True``. This defaults to ``16000``, which is
            optimal for speech recognition.

            The following values are supported: ``8000`` (telephone quality),
            ``11025``, ``16000`` (speech-recognition quality), ``22050``,
            ``24000``, ``32000``, ``44100``, ``48000`` (high-quality), or
            ``None``. If this is ``None``, the widget uses the browser's
            default sample rate (typically 44100 or 48000 Hz).

        disabled : bool
            Whether the chat input should be disabled. This defaults to
            ``False``.

        on_submit : callable
            An optional callback invoked when the chat input's value is submitted.

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

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

        width : "stretch" or int
            The width of the chat input widget. This can be one of the
            following:

            - ``"stretch"`` (default): The width of the widget matches the
              width of the parent container.
            - An integer specifying the width in pixels: The widget has a
              fixed width. If the specified width is greater than the width of
              the parent container, the width of the widget matches the width
              of the parent container.

        Returns
        -------
        None, str, or dict-like
            The user's submission. This is one of the following types:

            - ``None``: If the user didn't submit a message, file, or audio
              recording in the last rerun, the widget returns ``None``.
            - A string: When the widget isn't configured to accept files or
              audio recordings, and the user submitted a message in the last
              rerun, the widget returns the user's message as a string.
            - A dict-like object: When the widget is configured to accept files
              or audio recordings, and the user submitted any content in the
              last rerun, the widget returns a dict-like object.
              The object always includes the ``text`` attribute, and
              optionally includes ``files`` and/or ``audio`` attributes depending
              on the ``accept_file`` and ``accept_audio`` parameters.

            When the widget is configured to accept files or audio recordings,
            and the user submitted content in the last rerun, you can access
            the user's submission with key or attribute notation from the
            dict-like object. This is shown in Example 3 below.

            - The ``text`` attribute holds a string that is the user's message.
              This is an empty string if the user only submitted one or more
              files or audio recordings.
            - The ``files`` attribute is only present when ``accept_file``
              isn't ``False``. When present, it holds a list of
              ``UploadedFile`` objects. The list is empty if the user only
              submitted a message or audio recording. Unlike
              ``st.file_uploader``, this attribute always returns a list, even
              when the widget is configured to accept only one file at a time.
            - The ``audio`` attribute is only present when ``accept_audio`` is
              ``True``. When present, it holds an ``UploadedFile`` object if
              audio was recorded or ``None`` if no audio was recorded.

            The ``UploadedFile`` class is a subclass of ``BytesIO`` and
            therefore is "file-like". This means you can pass an instance of it
            anywhere a file is expected.

        Examples
        --------
        **Example 1: Pin the chat input widget to the bottom of your app**

        When ``st.chat_input`` is used in the main body of an app, it will be
        pinned to the bottom of the page.

        >>> import streamlit as st
        >>>
        >>> prompt = st.chat_input("Say something")
        >>> if prompt:
        ...     st.write(f"User has sent the following prompt: {prompt}")

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

        **Example 2: Use the chat input widget inline**

        The chat input can also be used inline by nesting it inside any layout
        container (container, columns, tabs, sidebar, etc) or fragment. Create
        chat interfaces embedded next to other content, or have multiple
        chatbots!

        >>> import streamlit as st
        >>>
        >>> with st.sidebar:
        >>>     messages = st.container(height=200)
        >>>     if prompt := st.chat_input("Say something"):
        >>>         messages.chat_message("user").write(prompt)
        >>>         messages.chat_message("assistant").write(f"Echo: {prompt}")

        .. output::
            https://doc-chat-input-inline.streamlit.app/
            height: 350px

        **Example 3: Let users upload files**

        When you configure your chat input widget to allow file attachments, it
        will return a dict-like object when the user sends a submission. You
        can access the user's message through the ``text`` attribute of this
        dictionary. You can access a list of the user's submitted file(s)
        through the ``files`` attribute. Similar to ``st.session_state``, you
        can use key or attribute notation.

        >>> import streamlit as st
        >>>
        >>> prompt = st.chat_input(
        >>>     "Say something and/or attach an image",
        >>>     accept_file=True,
        >>>     file_type=["jpg", "jpeg", "png"],
        >>> )
        >>> if prompt and prompt.text:
        >>>     st.markdown(prompt.text)
        >>> if prompt and prompt["files"]:
        >>>     st.image(prompt["files"][0])

        .. output::
            https://doc-chat-input-file-uploader.streamlit.app/
            height: 350px

        **Example 4: Programmatically set the text via session state**

        You can use ``st.session_state`` to set the text of the chat input widget.

        >>> import streamlit as st
        >>>
        >>> if st.button("Set Value"):
        >>>     st.session_state.chat_input = "Hello, world!"
        >>> st.chat_input(key="chat_input")
        >>> st.write("Chat input value:", st.session_state.chat_input)

        .. output::
            https://doc-chat-input-session-state.streamlit.app/
            height: 350px

        **Example 5: Enable audio recording**

        You can enable audio recording by setting ``accept_audio=True``.
        The ``accept_audio`` parameter works independently of ``accept_file``,
        allowing you to enable audio recording with or without file uploads.

        >>> import streamlit as st
        >>>
        >>> prompt = st.chat_input(
        >>>     "Say or record something",
        >>>     accept_audio=True,
        >>> )
        >>> if prompt and prompt.text:
        >>>     st.write("Text:", prompt.text)
        >>> if prompt and prompt.audio:
        >>>     st.audio(prompt.audio)
        >>>     st.write("Audio file:", prompt.audio.name)

        .. output::
            https://doc-chat-input-audio.streamlit.app/
            height: 350px

        NT)default_valuewrites_allowed>   FTmultiple	directoryzKThe `accept_file` parameter must be a boolean or 'multiple' or 'directory'.r   >   r   r   r   )
user_keykey_as_main_identityr   r   r   r   r   r   r   r   zInvalid audio_sample_rate: z. Must be one of z! Hz, or None for browser default.z1`st.chat_input()` can't be used in a `st.form()`.bottominliner   zserver.maxUploadSize>   Tr   r   )r   r   r   chat_input_value)on_change_handlerr   r   deserializer
serializerr   
value_typer   )r   )0r    r   r   r"   r,   r   r   r!   sortedr   existsr   set
_active_dg_ancestor_block_types_root_containerr(   MAINChatInputProtoidr7   r   r   rD   r   r   r   r   
get_optionmax_upload_size_mbr   r   r   r0   r   r   r   r   r   value_changedrr   	set_valuer1   reset_state_valuer   r   	bottom_dg_enqueue)rR   r   rd   r   r   r   r   r   r   r   r   r   r   r   
element_idancestor_block_typespositionchat_input_protoserdewidget_stater   session_states                         rT   r   zChatMixin.chat_inputT  s   x SkGG	
 DD']  !"4 "Kww##%/#

( 29=I )!)=='-.?-@ A""()=">!??`b  >>
477 3'C   #477#5#5#K#KLGG..-2D2DD(HH)+('*;'7$ )2& $& 'M(
$ 6?5J	PR""1%.4.?.?@V.W+(4%(1B.$(GG%#

 ''**)	
 	u$51$,!%%,*<*<*H &2%7%7")-&-/M3-#7 //T: j,2D2DEx &'11::.m ;  GG.m   *6)C)C|!!MMrV   c                    t        d|       S )zGet our DeltaGenerator.r6   )r   rX   s    rT   r   zChatMixin.dg  s     $d++rV   )ro   z1Literal['user', 'assistant', 'ai', 'human'] | strr   z7Literal['user', 'assistant'] | str | AtomicImage | Noner   r   rz   r6   )zYour message)r   r7   rd   
Key | Noner   
int | Noner   Literal[False]r   str | Sequence[str] | Noner   r!  r   rG   r   WidgetCallback | Noner   WidgetArgs | Noner   WidgetKwargs | Noner   r   rz   r   )r   r7   rd   r  r   r   r   r!  r   r"  r   zLiteral[True]r   r   r   rG   r   r#  r   r$  r   r%  r   r   rz   ChatInputValue | None)r   r7   rd   r  r   r   r   z&Literal[True, 'multiple', 'directory']r   r"  r   rG   r   r   r   rG   r   r#  r   r$  r   r%  r   r   rz   r&  )r   r7   rd   r  r   r   r   z'bool | Literal['multiple', 'directory']r   r"  r   rG   r   r   r   rG   r   r#  r   r$  r   r%  r   r   rz   r   )rz   r6   )	r}   r~   r   r+   r   r   r   propertyr   r   rV   rT   r   r     s|   N#
 KO O7?O7 H	O7
 O7 
O7 $O7b  *  $&+04',+/"&&*%. 	
  $ . %  )   $ # 
    *$  $&+04(-+/"&&*%.$$ 	$
 $ $$ .$ $$ &$ $ )$  $ $$ #$ 
$ $"  *$  $04"(-+/"&&*%.$$ 	$
 $ <$ .$ $ &$ $ )$  $ $$ #$ 
$ $" L! *IN  $?D04"(-+/"&&*%.ININ 	IN
 IN =IN .IN IN &IN IN )IN  IN $IN #IN 
%IN "INV , ,rV   r   N)r   zstr | AtomicImage | Noner   r7   rz   z7tuple[BlockProto.ChatMessage.AvatarType.ValueType, str])r   zFileUploaderStateProto | Nonerz   r@   )r   zUploadedFileInfoProto | Nonerz   rB   )`
__future__r   collections.abcr   r   r   dataclassesr   r   enumr	   typingr
   r   r   r   r   	streamlitr   r   $streamlit.delta_generator_singletonsr   *streamlit.elements.lib.file_uploader_utilsr   r   !streamlit.elements.lib.form_utilsr   "streamlit.elements.lib.image_utilsr   r   #streamlit.elements.lib.layout_utilsr   r   r   r   streamlit.elements.lib.policiesr   streamlit.elements.lib.utilsr   r   r   r   r    &streamlit.elements.widgets.audio_inputr!   streamlit.errorsr"   streamlit.proto.Block_pb2r#   r   streamlit.proto.ChatInput_pb2r$   r  streamlit.proto.Common_pb2r%   r   r&   FileUploaderStateProtor'   UploadedFileInfoProto!streamlit.proto.RootContainer_pb2r(   streamlit.proto.WidthConfig_pb2r)   .streamlit.runtime.memory_uploaded_file_managerr*   streamlit.runtime.metrics_utilr+   7streamlit.runtime.scriptrunner_utils.script_run_contextr,   streamlit.runtime.stater-   r.   r/   r0   +streamlit.runtime.state.session_state_proxyr1   'streamlit.runtime.uploaded_file_managerr2   r3   streamlit.string_utilr4   r5   streamlit.delta_generatorr6   r8   r   	frozensetr<   r7   r   r   r   r   r   r   r   rV   rT   <module>rG     sc   # > > (   & J 9 H  B  H 2 9 E L R P ; 7 : V  J M B8 "( 3 '-6. N  b^CH- b bJ#t 1$1251<1h'.''TB1BBJ + + +DW	, W	,rV   