Ë
    Eêñi3  ã                  ó~  — U d dl mZ d dl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 d dl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 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& d dl'm(Z(m)Z) d dl*m+Z+m,Z,m-Z-m.Z. d dl/m0Z0m1Z1 erd dl2m3Z3 d dlm4Z4 e1e0z  dz  Z5de6d<   h d£Z7e G d„ d«      «       Z8 G d„ d«      Z9y)é    )Úannotations)Ú	dataclass)Údedent)ÚTYPE_CHECKINGÚ	TypeAliasÚcast)Úenforce_filename_restriction)Úcurrent_form_id)Úcreate_layout_config)Úcheck_widget_policiesÚmaybe_raise_label_warnings)ÚKeyÚLabelVisibilityÚcompute_and_register_element_idÚ get_label_visibility_proto_valueÚto_key)Ú_get_upload_files)ÚStreamlitAPIException)Ú
AudioInput)ÚFileUploaderState)ÚUploadedFileInfo)Úgather_metrics)ÚScriptRunContextÚget_script_run_ctx)Ú
WidgetArgsÚWidgetCallbackÚWidgetKwargsÚregister_widget)ÚDeletedFileÚUploadedFile)ÚDeltaGenerator)ÚWidthWithoutContentNr   ÚSomeUploadedAudioFile>   é }  é+  é"V  é@  éD¬  é€»  éÀ]  é€>  c                  ó,   — e Zd Z	 	 	 	 dd„Z	 	 	 	 dd„Zy)ÚAudioInputSerdec                ó&  — t        «       }|�t        |t        «      r|S |j                  j	                  «       }|j
                  |_        |j                  |_        |j                  |_        |j                  j                  |j                  «       |S )N)ÚFileUploaderStateProtoÚ
isinstancer   Úuploaded_file_infoÚaddÚfile_idÚnameÚsizeÚ	file_urlsÚCopyFromÚ
_file_urls)ÚselfÚ
audio_fileÚstate_protoÚ	file_infos       úh/var/www/pod-logistic/pod-ai/venv/lib/python3.12/site-packages/streamlit/elements/widgets/audio_input.pyÚ	serializezAudioInputSerde.serialize>   sy   € ô -Ó.ˆàÐ¤¨J¼Ô!DØÐà+6×+IÑ+I×+MÑ+MÓ+Oˆ	Ø&×.Ñ.ˆ	ÔØ#Ÿ™ˆ	ŒØ#Ÿ™ˆ	ŒØ×Ñ×$Ñ$ Z×%:Ñ%:Ô;àÐó    c                ó˜   — t        |«      }t        |«      dk(  rd n|d   }|�'t        |t        «      st	        |j
                  dg«       |S )Nr   z.wav)r   Úlenr0   r   r	   r4   )r9   Úui_valueÚupload_filesÚreturn_values       r=   ÚdeserializezAudioInputSerde.deserializeO   sL   € ô )¨Ó2ˆÜ" <Ó0°AÒ5‘t¸<È¹?ˆØÐ#¬J°|Ä[Ô,QÜ(¨×):Ñ):¸V¸HÔEØÐr?   N)r:   r#   Úreturnr/   )rB   zFileUploaderStateProto | NonerF   r#   )Ú__name__Ú
__module__Ú__qualname__r>   rE   © r?   r=   r-   r-   <   s.   „ ðà)ðð 
 óð"Ø5ðà	ôr?   r-   c                  óÌ   — e Zd Z ed«      ddddddddddœ		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd„«       Z	 	 	 	 	 	 dddddd	œ	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
„Zedd„«       Zy)ÚAudioInputMixinÚaudio_inputr+   NFÚvisibleÚstretch)	Úsample_rateÚkeyÚhelpÚ	on_changeÚargsÚkwargsÚdisabledÚlabel_visibilityÚwidthc       	        ó    — |�'|t         vrt        d|› dt        t         «      › d�«      ‚t        «       }| j	                  |||||||||	|
|¬«      S )am  Display a widget that returns an audio recording from the user's microphone.

        Parameters
        ----------
        label : str
            A short label explaining to the user what this widget is used 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. Common block-level Markdown (headings,
            lists, blockquotes) is automatically escaped and displays as
            literal text in labels.

            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

        sample_rate : int or None
            The target sample rate for the audio recording in Hz. 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).

        key : str, int, or None
            An optional string or integer to use as the unique key for
            the widget. If this is ``None`` (default), a key will be
            generated for the widget based on the values of the other
            parameters. No two widgets may have the same key. Assigning
            a key stabilizes the widget's identity and preserves its
            state across reruns even when other parameters change.

            A key lets you access the widget's value via
            ``st.session_state[key]`` (read-only). For more details, see
            `Widget behavior
            <https://docs.streamlit.io/develop/concepts/architecture/widget-behavior>`_.

            Additionally, if ``key`` is provided, it will be used as a
            CSS class name prefixed with ``st-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 audio input's value
            changes.

        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.

        disabled : bool
            An optional boolean that disables the audio input if set to
            ``True``. 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 aligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        width : "stretch" or int
            The width of the audio 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 or UploadedFile
            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. The MIME type for the audio data is
            ``audio/wav``.

            .. Note::
                The resulting ``UploadedFile`` is subject to the size
                limitation configured in ``server.maxUploadSize``. If you
                expect large sound files, update the configuration option
                appropriately.

        Examples
        --------
        *Example 1:* Record a voice message and play it back.*

        The default sample rate of 16000 Hz is optimal for speech recognition.

        >>> import streamlit as st
        >>>
        >>> audio_value = st.audio_input("Record a voice message")
        >>>
        >>> if audio_value:
        ...     st.audio(audio_value)

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

        *Example 2:* Record high-fidelity audio and play it back.*

        Higher sample rates can create higher-quality, larger audio files. This
        might require a nicer microphone to fully appreciate the difference.

        >>> import streamlit as st
        >>>
        >>> audio_value = st.audio_input("Record high quality audio", sample_rate=48000)
        >>>
        >>> if audio_value:
        ...     st.audio(audio_value)

        .. output::
           https://doc-audio-input-high-rate.streamlit.app/
           height: 260px

        zInvalid sample_rate: z. Must be one of z! Hz, or None for browser default.)ÚlabelrP   rQ   rR   rS   rT   rU   rV   rW   rX   Úctx)ÚALLOWED_SAMPLE_RATESr   Úsortedr   Ú_audio_input)r9   rZ   rP   rQ   rR   rS   rT   rU   rV   rW   rX   r[   s               r=   rM   zAudioInputMixin.audio_inputZ   s„   € ðv Ð" {Ô:NÑ'NÜ'Ø'¨ }ð 5"Ü"(Ô)=Ó">Ð!?Ð?`ðbóð ô
 !Ó"ˆØ× Ñ ØØ#ØØØØØØØ-ØØð !ó 
ð 	
r?   )rV   rW   rX   r[   c          
     ó–  — t        |«      }t        | j                  ||d d¬«       t        ||	«       t	        d|d| j                  |||
|¬«      }t        «       }||_        ||_        t        | j                  «      |_	        ||_
        t        |	«      |j                  _        |�||_        |r|�t        |«      |_        t#        |
¬«      }t%        «       }t'        |j                  ||||j(                  |j*                  |d¬«      }| j                  j-                  d||¬	«       t/        |j                  t0        «      ry |j                  S )
NF)Údefault_valueÚwrites_allowedrM   T)Úuser_keyÚkey_as_main_identityÚdgrZ   rR   rX   rP   )rX   Úfile_uploader_state_value)Úon_change_handlerrT   rU   ÚdeserializerÚ
serializerr[   Ú
value_type)Úlayout_config)r   r   rd   r   r   ÚAudioInputProtoÚidrZ   r
   Úform_idrV   r   rW   ÚvaluerP   r   rR   r   r-   r   rE   r>   Ú_enqueuer0   r   )r9   rZ   rP   rQ   rR   rS   rT   rU   rV   rW   rX   r[   Ú
element_idÚaudio_input_protorj   ÚserdeÚaudio_input_states                    r=   r^   zAudioInputMixin._audio_input
  sQ  € ô �S‹kˆäØ�G‰GØØØØ õ	
ô 	# 5Ð*:Ô;ä4ØØà!%Ø�w‰wØØØØ#ô

ˆ
ô ,Ó-ÐØ)ÐÔØ"'ÐÔÜ$3°D·G±GÓ$<ÐÔ!Ø%-ÐÔ"Ü3SØó4
Ð×*Ñ*Ô0ð
 Ð"Ø,7ÐÔ)á�TÐ%Ü%+¨D£\ÐÔ"ä,°5Ô9ˆäÓ!ˆä+Ø× Ñ Ø'ØØØ×*Ñ*Ø—‘ØØ2ô	
Ðð 	�‰×Ñ˜Ð(9ÈÐÔWäÐ'×-Ñ-¬{Ô;ØØ ×&Ñ&Ð&r?   c                ó   — t        d| «      S )zGet our DeltaGenerator.r!   )r   )r9   s    r=   rd   zAudioInputMixin.dgU  s   € ô Ð$ dÓ+Ð+r?   )rZ   ÚstrrP   ú
int | NonerQ   ú
Key | NonerR   ú
str | NonerS   úWidgetCallback | NonerT   úWidgetArgs | NonerU   úWidgetKwargs | NonerV   ÚboolrW   r   rX   r"   rF   úUploadedFile | None)r+   NNNNN)rZ   ru   rP   rv   rQ   rw   rR   rx   rS   ry   rT   rz   rU   r{   rV   r|   rW   r   rX   r"   r[   zScriptRunContext | NonerF   r}   )rF   r!   )rG   rH   rI   r   rM   r^   Úpropertyrd   rJ   r?   r=   rL   rL   Y   su  „ Ù�MÓ"ð
 #(ØØØ+/Ø"&Ø&*ØØ,5Ø%.ñm
àðm
ð  ð	m
ð
 ðm
ð ðm
ð )ðm
ð  ðm
ð $ðm
ð ðm
ð *ðm
ð #ðm
ð 
òm
ó #ðm
ðd #(ØØØ+/Ø"&Ø&*ðI'ð Ø,5Ø%.Ø'+ñI'àðI'ð  ðI'ð ð	I'ð
 ðI'ð )ðI'ð  ðI'ð $ðI'ð ðI'ð *ðI'ð #ðI'ð %ðI'ð 
óI'ðV ò,ó ñ,r?   rL   ):Ú
__future__r   Údataclassesr   Útextwrapr   Útypingr   r   r   Ú*streamlit.elements.lib.file_uploader_utilsr	   Ú!streamlit.elements.lib.form_utilsr
   Ú#streamlit.elements.lib.layout_utilsr   Ústreamlit.elements.lib.policiesr   r   Ústreamlit.elements.lib.utilsr   r   r   r   r   Ú(streamlit.elements.widgets.file_uploaderr   Ústreamlit.errorsr   Ústreamlit.proto.AudioInput_pb2r   rk   Ústreamlit.proto.Common_pb2r   r/   r   ÚUploadedFileInfoProtoÚstreamlit.runtime.metrics_utilr   Ústreamlit.runtime.scriptrunnerr   r   Ústreamlit.runtime.stater   r   r   r   Ú'streamlit.runtime.uploaded_file_managerr   r    Ústreamlit.delta_generatorr!   r"   r#   Ú__annotations__r\   r-   rL   rJ   r?   r=   ú<module>r“      s¢   ðö #å !Ý ß 1Ñ 1å SÝ =Ý D÷÷õ õ GÝ 2Ý HÝ RÝ PÝ 9ß O÷ó ÷ NáÝ8ÝGà#/°+Ñ#=ÀÑ#DÐ �yÓ Dò OÐ ð ÷ð ó ð÷8,ò ,r?   