
    g,)                    b   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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'm(Z( d dl)m*Z*m+Z+m,Z,m-Z- d dl.m/Z/m0Z0 erd dl1m2Z2 ee0e/df   Z3de4d<   e G d d             Z5 G d d      Z6y)    )annotations)	dataclass)dedent)TYPE_CHECKINGUnioncast)	TypeAlias)make_deprecated_name_warningshow_deprecation_warning)current_form_id)check_widget_policiesmaybe_raise_label_warnings)KeyLabelVisibilitycompute_and_register_element_id get_label_visibility_proto_valueto_key)_get_upload_files)
AudioInput)FileUploaderState)UploadedFileInfo)gather_metrics)ScriptRunContextget_script_run_ctx)
WidgetArgsWidgetCallbackWidgetKwargsregister_widget)DeletedFileUploadedFile)DeltaGeneratorNr	   SomeUploadedAudioFilec                  0    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       [/var/www/openai/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                J    t        |      }t        |      dk(  rd }|S |d   }|S )Nr   )r   len)r0   ui_value	widget_idupload_filesreturn_values        r4   deserializezAudioInputSerde.deserializeN   s9     )2|!L  (?Lr6   N)r1   r"   returnr&   )r9   zFileUploaderStateProto | Noner:   strr>   r"   )__name__
__module____qualname__r5   r=    r6   r4   r$   r$   ;   s6    ) 
 "5BE	r6   r$   c            	         e Zd Z ed      dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z ed      dddddddd	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Z	 	 	 	 	 ddddd		 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd
Zedd       Zy)AudioInputMixinaudio_inputNFvisible)keyhelp	on_changeargskwargsdisabledlabel_visibilityc               J    t               }	| j                  |||||||||		      S )aH  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. 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

        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 audio 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.

        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 alligned with other widgets.
            If this is ``"collapsed"``, Streamlit displays no label or spacer.

        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
        --------
        >>> 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

        	labelrH   rI   rJ   rK   rL   rM   rN   ctx)r   _audio_input
r0   rQ   rH   rI   rJ   rK   rL   rM   rN   rR   s
             r4   rF   zAudioInputMixin.audio_inputZ   s@    J !"  - ! 

 
	
r6   experimental_audio_inputc               v    t        t        ddd             t               }	| j                  |||||||||		      S )zYDeprecated alias for st.audio_input.
        See the docstring for the widget's new name.rU   rF   z
2025-01-01rP   )r   r
   r   rS   rT   s
             r4   rU   z(AudioInputMixin.experimental_audio_input   sZ      	!(*	
 !"  - ! 

 
	
r6   )rM   rN   rR   c          
     t   t        |      }t        | j                  ||d d       t        ||       t	        d|t        | j                        ||      }
t               }|
|_        ||_        t        | j                        |_	        ||_
        t        |      |j                  _        |r|t        |      |_        t!               }t#        |j                  ||||j$                  |j&                  |	d      }| j                  j)                  d|       t+        |j                  t,              ry |j                  S )NF)default_valuewrites_allowedrF   )user_keyform_idrQ   rI   file_uploader_state_value)on_change_handlerrK   rL   deserializer
serializerrR   
value_type)r   r   dgr   r   r   AudioInputProtoidrQ   r[   rM   r   rN   valuer   rI   r$   r   r=   r5   _enqueuer'   r   )r0   rQ   rH   rI   rJ   rK   rL   rM   rN   rR   
element_idaudio_input_protoserdeaudio_input_states                 r4   rS   zAudioInputMixin._audio_input   s/    SkGG 	
 	#5*:;4#DGG,

 ,-)"'$3DGG$<!%-"3S4
**0 T%%+D\"!+  '**2	
 	(9:'--{; &&&r6   c                    t        d|       S )zGet our DeltaGenerator.r!   )r   )r0   s    r4   ra   zAudioInputMixin.dg0  s     $d++r6   )rQ   r?   rH   
Key | NonerI   
str | NonerJ   WidgetCallback | NonerK   WidgetArgs | NonerL   WidgetKwargs | NonerM   boolrN   r   r>   UploadedFile | None)NNNNN)rQ   r?   rH   rk   rI   rl   rJ   rm   rK   rn   rL   ro   rM   rp   rN   r   rR   zScriptRunContext | Noner>   rq   )r>   r!   )	r@   rA   rB   r   rF   rU   rS   propertyra   rC   r6   r4   rE   rE   Y   s   M"
 +/"&&*,5o
o
 	o

 o
 )o
  o
 $o
 o
 *o
 
o
 #o
b ./
 +/"&&*,5"
"
 	"

 "
 )"
  "
 $"
 "
 *"
 
"
 0"
N +/"&&*=' ,5'+='=' =' 	='
 )='  =' $=' =' *=' %=' 
='~ , ,r6   rE   )7
__future__r   dataclassesr   textwrapr   typingr   r   r   typing_extensionsr	   streamlit.deprecation_utilr
   r   !streamlit.elements.lib.form_utilsr   streamlit.elements.lib.policiesr   r   streamlit.elements.lib.utilsr   r   r   r   r   (streamlit.elements.widgets.file_uploaderr   streamlit.proto.AudioInput_pb2r   rb   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"   __annotations__r$   rE   rC   r6   r4   <module>r      s    # !  - - ' >  G H R P 9 O  N8#({D)H#I y I   :Z, Z,r6   