
    ;3h                        d Z ddlmZ ddlZddlZddlZddl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mZ ddlmZ dd	lmZ dd
l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%m&Z&m'Z' ddl(m)Z) ddl*m+Z+ ddl,m-Z-  e        G d de             Z. e        G d de             Z/ G d de      Z0 G d de      Z1 G d de&      Z2 G d de&      Z3 G d de'      Z4 G d d e&      Z5 G d! d"e      Z6 e       e
 G d# d$                    Z7 G d% d&e'      Z8ee9ee:e9e:   df   ee:e9e:   df   f   e;ee:e9e:   df      z     Z<erdd'l m=Z= 	 	 	 	 d+d(Z> e        G d) d*e!             Z?y),zgr.Chatbot() component.    )annotationsN)CallableSequence)	dataclassfield)Path)TYPE_CHECKINGAnyLiteralOptionalUnioncast)utils)document)NotRequired	TypedDict)ComponentMeta)	Component)FileDataGradioModelGradioRootModel)Events)Error)I18nDatac                  N    e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   y)MetadataDictaP  
    A typed dictionary to represent metadata for a message in the Chatbot component. An
    instance of this dictionary is used for the `metadata` field in a ChatMessage when
    the chat message should be displayed as a thought.
    Parameters:
        title: The title of the "thought" message. Required if the message is to be displayed as a thought.
        id: The ID of the message. Only used for nested thoughts. Nested thoughts can be nested by setting the parent_id to the id of the parent thought.
        parent_id: The ID of the parent message. Only used for nested thoughts.
        log: A string message to display next to the thought title in a subdued font.
        duration: The duration of the message in seconds. Appears next to the thought title in a subdued font inside a parentheses.
        status: if set to `"pending"`, a spinner appears next to the thought title and the accordion is initialized open.  If `status` is `"done"`, the thought accordion is initialized closed. If `status` is not provided, the thought accordion is initialized open and no spinner is displayed.
    NotRequired[str]titlezNotRequired[int | str]id	parent_idlogzNotRequired[float]durationz'NotRequired[Literal['pending', 'done']]statusN__name__
__module____qualname____doc____annotations__     Y/var/www/html/audio-gradio/venv/lib/python3.12/site-packages/gradio/components/chatbot.pyr   r   $   s-     %%	  33r+   r   c                  &    e Zd ZU dZded<   ded<   y)
OptionDicta7  
    A typed dictionary to represent an option in a ChatMessage. A list of these
    dictionaries is used for the `options` field in a ChatMessage.
    Parameters:
        value: The value to return when the option is selected.
        label: The text to display in the option, if different from the value.
    strvaluer   labelNr$   r*   r+   r,   r.   r.   ;   s     Jr+   r.   c                  T    e Zd ZU ded<   ded<   ded<   ded<   ded<   d	ed
<   ded<   y)FileDataDictr/   pathzNotRequired[Optional[str]]urlzNotRequired[Optional[int]]size	orig_name	mime_typezNotRequired[bool]	is_streamz2dict[Literal['_type'], Literal['gradio.FileData']]metaNr%   r&   r'   r)   r*   r+   r,   r3   r3   I   s+    
I	##
$$))))  
<<r+   r3   c                  6    e Zd ZU ded<   ded<   ded<   ded<   y	)
MessageDictz&str | FileDataDict | tuple | Componentcontent&Literal['user', 'assistant', 'system']rolezNotRequired[MetadataDict]metadatazNotRequired[list[OptionDict]]optionsNr;   r*   r+   r,   r=   r=   S   s    33
00''**r+   r=   c                  &    e Zd ZU ded<   dZded<   y)FileMessager   fileNzOptional[str]alt_text)r%   r&   r'   r)   rF   r*   r+   r,   rD   rD   Z   s    
N"Hm"r+   rD   c                  6    e Zd ZU ded<   ded<   ded<   ded<   y)	ComponentMessager/   	componentr
   r0   zdict[str, Any]constructor_argspropsNr;   r*   r+   r,   rH   rH   _   s    NJ$$r+   rH   c                      e Zd ZU ded<   y)ChatbotDataTupleszmlist[tuple[Union[str, FileMessage, ComponentMessage, None], Union[str, FileMessage, ComponentMessage, None]]]rootNr;   r*   r+   r,   rM   rM   f   s     r+   rM   c                  >    e Zd ZU ded<   dZded<   ded<   dZded	<   y)
Messager/   r@   NzOptional[MetadataDict]rA   z)Union[str, FileMessage, ComponentMessage]r>   zOptional[list[OptionDict]]rB   )r%   r&   r'   r)   rA   rB   r*   r+   r,   rP   rP   o   s#    
I'+H$+66*.G'.r+   rP   c                  6    e Zd ZU ded<   ded<   ded<   ded<   y)	ExampleMessagezNotRequired[str | FileDataDict]iconr   display_texttextz)NotRequired[Sequence[str | FileDataDict]]filesNr;   r*   r+   r,   rR   rR   v   s(        r+   rR   c                  b    e Zd ZU dZded<   dZded<    ee      Zded	<    ee	      Z
d
ed<   y)ChatMessagea;  
    A dataclass that represents a message in the Chatbot component (with type="messages"). The only required field is `content`. The value of `gr.Chatbot` is a list of these dataclasses.
    Parameters:
        content: The content of the message. Can be a string or a Gradio component.
        role: The role of the message, which determines the alignment of the message in the chatbot. Can be "user", "assistant", or "system". Defaults to "assistant".
        metadata: The metadata of the message, which is used to display intermediate thoughts / tool usage. Should be a dictionary with the following keys: "title" (required to display the thought), and optionally: "id" and "parent_id" (to nest thoughts), "duration" (to display the duration of the thought), "status" (to display the status of the thought).
        options: The options of the message. A list of Option objects, which are dictionaries with the following keys: "label" (the text to display in the option), and optionally "value" (the value to return when the option is selected if different from the label).
    z8str | FileData | Component | FileDataDict | tuple | listr>   	assistantr?   r@   )default_factoryr   rA   zlist[OptionDict]rB   N)r%   r&   r'   r(   r)   r@   r   r   rA   listrB   r*   r+   r,   rX   rX      s:     FE3>D
0>"<@Hl@ %d ;G;r+   rX   c                      e Zd ZU ded<   y)ChatbotDataMessageszlist[Message]rN   Nr;   r*   r+   r,   r]   r]      s    
r+   r]   )Timerc                    	 t        j                         D ]&  }| |j                  k(  st        |t              s$|c S  y # t
        $ r}t        d|  d|       |d }~wt        $ r Y y w xY w)NzError importing z: )r   get_all_componentsr%   
isinstancer   ModuleNotFoundError
ValueErrorAttributeError)component_namerI   es      r,   import_component_and_datarg      s{    	113 	!I!3!33
=9 ! 		!
  J+N+;2aSABI s,   &A  A  A  A   	A*	AA*)A*c            *          e Zd ZdZej
                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  ej                  g
Z	 dddddddddddddddddddddddddddddddddddddddddd	(	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d fd
Zd Zd Zedd       Z	 	 	 	 ddZ	 	 	 	 ddZ	 	 	 	 ddZedd       Zed        Z	 	 	 	 d dZd!dZ	 	 	 	 d"dZ	 	 	 	 d#dZd$dZd$dZ xZ S )%Chatbota  
    Creates a chatbot that displays user-submitted messages and responses. Supports a subset of Markdown including bold, italics, code, tables.
    Also supports audio/video/image files, which are displayed in the Chatbot, and other kinds of files which are displayed as links. This
    component is usually used as an output component.

    Demos: chatbot_simple, chatbot_streaming, chatbot_with_tools, chatbot_core_components
    Guides: creating-a-chatbot-fast, creating-a-custom-chatbot-with-blocks, agents-and-tool-usage
    NT   r0   i  F)LikeDislike)(typer1   everyinputs
show_label	containerscale	min_widthvisibleelem_idelem_classes
autoscrollrenderkeypreserved_by_keyheight	resizable
resizeable
max_height
min_heighteditablelatex_delimitersrtlshow_share_buttonshow_copy_button	watermarkavatar_imagessanitize_htmlrender_markdownfeedback_optionsfeedback_valuebubble_full_widthline_breakslayoutplaceholderexamplesshow_copy_all_buttonallow_file_downloadsgroup_consecutive_messages
allow_tagsc       (           |t        j                  dt        d       d}n!|dk(  rt        j                  dt        d       |dvrt        d|       || _        | j                          || _        || _        |d	ur#t        j                  d
t        d       || _	        || _	        || _
        || _        || _        || _        |(| _        |ddddg}|| _        |t!        j"                         dun|| _        || _        || _        || _        || _        |!t        j                  dt        d       d| _        |"| _        |#| _        |&| _        |'| _        || _        | | _        |)r|)nd	| _        t>        *|   |||||||	|
||||||       ddg| _!        |n-| jE                  |d         | jE                  |d         g| _!        |$| _#        |%| _$        | jK                          | j                  dk(  rd| _&        yd| _&        y)a%  
        Parameters:
            value: Default list of messages to show in chatbot, where each message is of the format {"role": "user", "content": "Help me."}. Role can be one of "user", "assistant", or "system". Content should be either text, or media passed as a Gradio component, e.g. {"content": gr.Image("lion.jpg")}. If a function is provided, the function will be called each time the app loads to set the initial value of this component.
            type: The format of the messages passed into the chat history parameter of `fn`. If "messages", passes the value as a list of dictionaries with openai-style "role" and "content" keys. The "content" key's value should be one of the following - (1) strings in valid Markdown (2) a dictionary with a "path" key and value corresponding to the file to display or (3) an instance of a Gradio component. At the moment Image, Plot, Video, Gallery, Audio, and HTML are supported. The "role" key should be one of 'user' or 'assistant'. Any other roles will not be displayed in the output. If this parameter is 'tuples', expects a `list[list[str | None | tuple]]`, i.e. a list of lists. The inner list should have 2 elements: the user message and the response message, but this format is deprecated.
            label: the label for this component. Appears above the component and is also used as the header if there are a table of examples for this component. If None and used in a `gr.Interface`, the label will be the name of the parameter this component is assigned to.
            every: Continously calls `value` to recalculate it if `value` is a function (has no effect otherwise). Can provide a Timer whose tick resets `value`, or a float that provides the regular interval for the reset Timer.
            inputs: Components that are used as inputs to calculate `value` if `value` is a function (has no effect otherwise). `value` is recalculated any time the inputs change.
            show_label: if True, will display label.
            container: If True, will place the component in a container - providing some extra padding around the border.
            scale: relative size compared to adjacent Components. For example if Components A and B are in a Row, and A has scale=2, and B has scale=1, A will be twice as wide as B. Should be an integer. scale applies in Rows, and to top-level Components in Blocks where fill_height=True.
            min_width: minimum pixel width, will wrap if not sufficient screen space to satisfy this value. If a certain scale value results in this Component being narrower than min_width, the min_width parameter will be respected first.
            visible: If False, component will be hidden.
            elem_id: An optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.
            elem_classes: An optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.
            autoscroll: If True, will automatically scroll to the bottom of the textbox when the value changes, unless the user scrolls up. If False, will not scroll to the bottom of the textbox when the value changes.
            render: If False, component will not render be rendered in the Blocks context. Should be used if the intention is to assign event listeners now but render the component later.
            key: in a gr.render, Components with the same key across re-renders are treated as the same component, not a new component. Properties set in 'preserved_by_key' are not reset across a re-render.
            preserved_by_key: A list of parameters from this component's constructor. Inside a gr.render() function, if a component is re-rendered with the same key, these (and only these) parameters will be preserved in the UI (if they have been changed by the user or an event listener) instead of re-rendered based on the values provided during constructor.
            height: The height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If messages exceed the height, the component will scroll.
            resizable: If True, the user of the Gradio app can resize the chatbot by dragging the bottom right corner.
            max_height: The maximum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If messages exceed the height, the component will scroll. If messages are shorter than the height, the component will shrink to fit the content. Will not have any effect if `height` is set and is smaller than `max_height`.
            min_height: The minimum height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed. If messages exceed the height, the component will expand to fit the content. Will not have any effect if `height` is set and is larger than `min_height`.
            editable: Allows user to edit messages in the chatbot. If set to "user", allows editing of user messages. If set to "all", allows editing of assistant messages as well.
            latex_delimiters: A list of dicts of the form {"left": open delimiter (str), "right": close delimiter (str), "display": whether to display in newline (bool)} that will be used to render LaTeX expressions. If not provided, `latex_delimiters` is set to `[{ "left": "$$", "right": "$$", "display": True }]`, so only expressions enclosed in $$ delimiters will be rendered as LaTeX, and in a new line. Pass in an empty list to disable LaTeX rendering. For more information, see the [KaTeX documentation](https://katex.org/docs/autorender.html).
            rtl: If True, sets the direction of the rendered text to right-to-left. Default is False, which renders text left-to-right.
            show_share_button: If True, will show a share icon in the corner of the component that allows user to share outputs to Hugging Face Spaces Discussions. If False, icon does not appear. If set to None (default behavior), then the icon appears if this Gradio app is launched on Spaces, but not otherwise.
            show_copy_button: If True, will show a copy button for each chatbot message.
            watermark: If provided, this text will be appended to the end of messages copied from the chatbot, after a blank line. Useful for indicating that the message is generated by an AI model.
            avatar_images: Tuple of two avatar image paths or URLs for user and bot (in that order). Pass None for either the user or bot image to skip. Must be within the working directory of the Gradio app or an external URL.
            sanitize_html: If False, will disable HTML sanitization for chatbot messages. This is not recommended, as it can lead to security vulnerabilities.
            render_markdown: If False, will disable Markdown rendering for chatbot messages.
            feedback_options: A list of strings representing the feedback options that will be displayed to the user. The exact case-sensitive strings "Like" and "Dislike" will render as thumb icons, but any other choices will appear under a separate flag icon.
            feedback_value: A list of strings representing the feedback state for entire chat. Only works when type="messages". Each entry in the list corresponds to that assistant message, in order, and the value is the feedback given (e.g. "Like", "Dislike", or any custom feedback option) or None if no feedback was given for that message.
            bubble_full_width: Deprecated.
            line_breaks: If True (default), will enable Github-flavored Markdown line breaks in chatbot messages. If False, single new lines will be ignored. Only applies if `render_markdown` is True.
            layout: If "panel", will display the chatbot in a llm style layout. If "bubble", will display the chatbot with message bubbles, with the user and bot messages on alterating sides. Will default to "bubble".
            placeholder: a placeholder message to display in the chatbot when it is empty. Centered vertically and horizontally in the Chatbot. Supports Markdown and HTML. If None, no placeholder is displayed.
            examples: A list of example messages to display in the chatbot before any user/assistant messages are shown. Each example should be a dictionary with an optional "text" key representing the message that should be populated in the Chatbot when clicked, an optional "files" key, whose value should be a list of files to populate in the Chatbot, an optional "icon" key, whose value should be a filepath or URL to an image to display in the example box, and an optional "display_text" key, whose value should be the text to display in the example box. If "display_text" is not provided, the value of "text" will be displayed.
            show_copy_all_button: If True, will show a copy all button that copies all chatbot messages to the clipboard.
            allow_file_downloads: If True, will show a download button for chatbot messages that contain media. Defaults to True.
            group_consecutive_messages: If True, will display consecutive messages from the same role in the same bubble. If False, will display each message in a separate bubble. Defaults to True.
            allow_tags: If a list of tags is provided, these tags will be preserved in the output chatbot messages, even if `sanitize_html` is `True`. For example, if this list is ["thinking"], the tags `<thinking>` and `</thinking>` will not be removed. If True, all custom tags (non-standard HTML tags) will be preserved. If False, no tags will be preserved (default behavior).
        Na#  You have not specified a value for the `type` parameter. Defaulting to the 'tuples' format for chatbot messages, but this is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style dictionaries with 'role' and 'content' keys.   )
stackleveltupleszThe 'tuples' format for chatbot messages is deprecated and will be removed in a future version of Gradio. Please set type='messages' instead, which uses openai-style 'role' and 'content' keys.)messagesr   z?The `type` parameter must be 'messages' or 'tuples', received: FzThe 'resizeable' parameter is deprecated and will be removed in a future version. Please use the 'resizable' (note the corrected spelling) parameter instead.z$$T)leftrightdisplayzThe 'bubble_full_width' parameter is deprecated and will be removed in a future version. This parameter no longer has any effect.)r1   rn   ro   rp   rq   rr   rs   rt   ru   rv   rx   ry   rz   r0   r      r   z_a list of chat message dictionaries in openai format, e.g. {'role': 'user', 'content': 'Hello'}z`a list of 2-part tuples, where each tuple contains the user message and the bot response message)'warningswarnUserWarningrc   rm   _setup_data_modelrw   r{   DeprecationWarningr|   r~   r   r   r   r   r   r   	get_spacer   r   r   r   r   r   r   r   r   r   r   r   r   super__init__r   serve_static_filer   r   _setup_examples_value_description)+selfr0   rm   r1   rn   ro   rp   rq   rr   rs   rt   ru   rv   rw   rx   ry   rz   r{   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   	__class__s+                                             r,   r   zChatbot.__init__   sv   p <MM v
 DXMM S
 --QRVQWX  48	 $U"MM p"
 (DN"$$ *D'#)- NO 0 !( __d*" 	
  / 0"*(MM T"
 "&&$8!$8! 0,(2*!%- 	 	
  26t  &&}Q'78&&}Q'78"D '  yyJ& n 	 t 	r+   c                P    | j                   dk(  rt        | _        y t        | _        y )Nr   )rm   r]   
data_modelrM   r   s    r,   r   zChatbot._setup_data_model  s    99
"1DO/DOr+   c                
   | j                   t        | j                         D ]  \  }}d|v r*t        |d   t              r| j	                  |d         |d<   |j                  d      }|t        |t              st        d      |et        |      D ]l  \  }}t        |t              st        |      j                  }| j	                  |      }|@||d<   t        j                  |      |d<   t        di |}|||<   n  y y )NrS   rV   z_Data incompatible with files format. The 'files' passed should be a list of file paths or URLs.r7   r8   r*   )r   	enumeratera   r/   r   getr[   r   r   nameclient_utilsget_mimetyper3   )r   iexample	file_inforE   r7   	file_datas          r,   r   zChatbot._setup_examples  s   ==$'6 9
7W$GFOS)I&*&<&<WV_&MGFO#KK0	(It1Ly  (#,Y#7 
94%dC0(,T
I(,(>(>t(DI(49B	+ 69E9R9R$-:"	+ 6 -9,E9,E	/8	!
99 %r+   c                    |dk(  r t        d | D              }|st        d      y t        d | D              st        d      y )Nr   c              3     K   | ]9  }t        |t              xr
 d |v xr d|v xs t        |t        t        z         ; yw)r@   r>   N)ra   dictrX   rP   .0messages     r,   	<genexpr>z(Chatbot._check_format.<locals>.<genexpr>  sV      
 	 7D) )g%)(> g{W'<=>s   ?AzData incompatible with messages format. Each message should be a dictionary with 'role' and 'content' keys or a ChatMessage object.c              3  h   K   | ]*  }t        |t        t        f      xr t        |      d k(   , yw)   N)ra   tupler[   lenr   s     r,   r   z(Chatbot._check_format.<locals>.<genexpr>  s4      
 w.D3w<13DD
s   02zPData incompatible with tuples format. Each message should be a list of length 2.)allr   )r   rm   	all_valids      r,   _check_formatzChatbot._check_format  sn    : 
  ( I  Z    
#
 
 b 	
r+   c                `   |y t        |t              rE|j                  "|j                  j                  |j                  fS |j                  j                  fS t        |t
              r|S t        |t              r&|j                  dv r|j                  j                         n|j                  j                         }t        |      }| |       }|j                  s|j                  }nzt        |j                  t              r |j                  di |j                  }nCt        |j                  t              r|j                  |j                        }n|j                  }|j!                  |      } |dd|i|j"                  S t%        d|j                         t%        d|       )N)jsonhtmlrN   r0   z)Invalid component for Chatbot component: 'Invalid message for Chatbot component: r*   )ra   rD   rF   rE   r4   r/   rH   rI   upper
capitalizerg   r   r0   
issubclassr   r   
preprocessrJ   rc   )r   chat_messagecapitalized_componentrI   instancepayloadr0   s          r,   _preprocess_contentzChatbot._preprocess_content  s    k2$$0$))..0E0EFF$))..00c*&67  ))-== &&,,.!++668 "
 22GHI$$;***00G 3 3[A1h11GL4F4FGG 3 3_E&11|7I7I1JG*00G ++G4 NuN0M0MNN ?@V@V?WX  F|nUVVr+   c                   g }|j                   D ]y  }t        |t        t        f      st	        d|       t        |      dk7  rt	        d|       |j                  | j                  |d         | j                  |d         g       { |S )Nz6Expected a list of lists or list of tuples. Received: r   zNExpected a list of lists of length 2 or list of tuples of length 2. Received: r   r   )rN   ra   r   r[   	TypeErrorr   appendr   )r   r   processed_messagesmessage_pairs       r,   _preprocess_messages_tuplesz#Chatbot._preprocess_messages_tuples  s      #LL 	LlUDM:L\N[  < A%deqdrs  %%,,\!_=,,\!_=	 "!r+   c                   |g S | j                   dk(  r:t        |t              st        d      | j	                  t        t        |            S t        |t              st        d      g }|j                  D ]O  }t        t        |j                               }| j                  |j                        |d<   |j                  |       Q |S )a  
        Parameters:
            payload: data as a ChatbotData object
        Returns:
            If type is 'tuples', passes the messages in the chatbot as a `list[list[str | None | tuple]]`, i.e. a list of lists. The inner list has 2 elements: the user message and the response message. Each message can be (1) a string in valid Markdown, (2) a tuple if there are displayed files: (a filepath or URL to a file, [optional string alt text]), or (3) None, if there is no message displayed. If type is 'messages', passes the value as a list of dictionaries with 'role' and 'content' keys. The `content` key's value supports everything the `tuples` format supports.
        r   z(Data incompatible with the tuples formatz*Data incompatible with the messages formatr>   )rm   ra   rM   r   r   r   r]   rN   r=   
model_dumpr   r>   r   )r   r   message_dictsr   message_dicts        r,   r   zChatbot.preprocess  s     ?I99 g'89FGG33D9JG4TUU'#67DEE|| 	/GW-?-?-ABL&*&>&>w&OL#  .	/ r+   c                    t        | t              r| j                  d      S t        | t              st	        |       dkD  r| d   S y y )NrF   r   )ra   r   r   GradioComponentr   )r   s    r,   _get_alt_textzChatbot._get_alt_text  sH    lD)##J//L/:s<?PST?T?" @U:r+   c                    t        j                  |      }t        t        ||      t        j                  |             S )N)r4   r8   )rE   rF   )r   r   rD   r   ri   r   )r   filepathr8   s      r,   _create_file_messagezChatbot._create_file_message  s7     --h7	x9=**<8
 	
r+   c                   |y t        |t        t        t        f      r|S t        |t              rt        |      S t        |t
              r|j                          t        t        |      j                        }|rd|j                  d<    |j                  d	i |j                  }|j                  j                  dd        |j                         }t        t        |      j                  j                         |j                  dd       |j                  |      S y t        |t               rd|v r|d   }| j#                  ||      S t        |t$        t&        f      r t        |d         }| j#                  ||      S t)        d|       )
N)rE   Frx   r0   )rI   r0   rJ   rK   r4   r   r   r*   )ra   rD   rH   r/   r   r   unrenderrg   rm   r%   rJ   r   pop
get_configlowerr   r   r   r   r[   rc   )r   r   rI   configr   s        r,   _postprocess_contentzChatbot._postprocess_content  sl    l[2BC$HIh/L11o6!!#1$|2D2M2MNI:?--h72L22S\5R5RS	--11'4@"--/'"<099??A **Wd3%1%B%B 	   d+,0F#F+H,,\8DDudm4<?+H,,\8DDF|nUVVr+   c                    g }|D ]9  }|j                  | j                  |d         | j                  |d         g       ; t        |      S )Nr   r   r   )r   r   rM   )r   r0   r   r   s       r,   _postprocess_messages_tuplesz$Chatbot._postprocess_messages_tuples?  s\    ! 	L%%--l1o>--l1o>	 !&899r+   c                L   t        j                  |      }t        |t              r#| j	                  |d         |d<   t        di |}nt        |t              rX| j	                  |j                        |_        t        |j                  |j                  |j                  |j                        }n"t        |t
              r|S t        d| d      t        |j                  t              r&t        j                  |j                        |_        |S |j                  |_        |S )Nr>   )r@   r>   rA   rB   r   F)rt   r*   )copydeepcopyra   r   r   rP   rX   r>   r@   rA   rB   r   r/   inspectcleandoc)r   r   msgs      r,   _postprocess_message_messagesz%Chatbot._postprocess_message_messagesJ  s     --(gt$!%!:!:79;M!NGI$G$C-"77HGO\\ ))	C )N9'CU  #++s+ S[[) 	
 
  	
 
r+   c           	        t        t        t        t           t        t           f   | j
                        }|	 |g       S | j                  dk(  r1| j                  |d       | j                  t        t        |            S | j                  |d       |D cg c]!  }| j                  t        t        |            # }}t	        |      S c c}w )a  
        Parameters:
            value: If type is `tuples`, expects a `list[list[str | None | tuple]]`, i.e. a list of lists. The inner list should have 2 elements: the user message and the response message. The individual messages can be (1) strings in valid Markdown, (2) tuples if sending files: (a filepath or URL to a file, [optional string alt text]) -- if the file is image/video/audio, it is displayed in the Chatbot, or (3) None, in which case the message is not displayed. If type is 'messages', passes the value as a list of dictionaries with 'role' and 'content' keys. The `content` key's value supports everything the `tuples` format supports.
        Returns:
            an object of type ChatbotData
        r   r   r   )r   r   rm   rM   r]   r   r   r   TupleFormatr   r=   )r   r0   r   r   r   s        r,   postprocesszChatbot.postprocessg  s     $()40C+DDEt

 =2&&99 uh/44T+u5MNN5*- !
 ..tK/IJ
 
 #(:;;	
s   &Cc                    | j                   dk(  r6t        dd      j                         t        dd      j                         gS dd ggS Nr   userzHello!)r@   r>   rY   zHow can I help you?rm   rP   r   r   s    r,   example_payloadzChatbot.example_payload  O    99
"VX6AAC[2GHSSU  4 !!r+   c                    | j                   dk(  r6t        dd      j                         t        dd      j                         gS dd ggS r   r   r   s    r,   example_valuezChatbot.example_value  r   r+   )N)Lr0   z;list[MessageDict | Message] | TupleFormat | Callable | Nonerm   z$Literal['messages', 'tuples'] | Noner1   zstr | I18nData | Nonern   zTimer | float | Nonero   z7Component | Sequence[Component] | set[Component] | Nonerp   bool | Nonerq   boolrr   z
int | Noners   intrt   r   ru   
str | Nonerv   list[str] | str | Nonerw   r   rx   r   ry   z(int | str | tuple[int | str, ...] | Nonerz   r  r{   int | str | Noner|   r   r}   r   r~   r  r   r  r   zLiteral['user', 'all'] | Noner   z"list[dict[str, str | bool]] | Noner   r   r   r   r   r   r   r  r   z2tuple[str | Path | None, str | Path | None] | Noner   r   r   r   r   z"list[str] | tuple[str, ...] | Noner   zSequence[str | None] | Noner   r   r   z!Literal['panel', 'bubble'] | Noner   r  r   zlist[ExampleMessage] | Noner   r   r   zlist[str] | bool)r   r
   rm   zLiteral['messages', 'tuples'])r   +str | FileMessage | ComponentMessage | NonereturnzIstr | GradioComponent | tuple[str | None] | tuple[str | None, str] | None)r   rM   r  z5list[list[str | tuple[str] | tuple[str, str] | None]])r   z.ChatbotDataTuples | ChatbotDataMessages | Noner  zIlist[list[str | tuple[str] | tuple[str, str] | None]] | list[MessageDict])r   z%dict | list | tuple | GradioComponent)r   zXstr | tuple | list | FileDataDict | FileData | GradioComponent | ComponentMessage | Noner  r  )r0   r   r  rM   )r   zMessageDict | ChatMessager  rP   )r0   z0TupleFormat | list[MessageDict | Message] | Noner  z'ChatbotDataTuples | ChatbotDataMessages)r  r
   )!r%   r&   r'   r(   r   changeselectlikeretryundoexample_selectoption_selectclearr   editEVENTSr   r   r   staticmethodr   r   r   r   r   r   r   r   r   r   r   r   __classcell__)r   s   @r,   ri   ri      s    	F PTt
 6:'+&*JN"& "/38<3:#& '+'+26?C)-!& $LP" $?R6: 48"&04"!+/',Wt
Kt
 3	t

 %t
 $t
 Ht
  t
 t
 t
 t
 t
 t
 -t
 t
  !t
" 6#t
$ 1%t
& !'t
( )t
* +t
, %-t
. %/t
0 01t
2 =3t
4 5t
6 '7t
8 9t
: ;t
< J=t
> ?t
@ At
B =Ct
D 4Et
H It
J 2Kt
L  Mt
N .Ot
T %)Ut
V %Wt
l09.  *%WA%W 
S%WN"("	>"*? 
S2 # # 
 
&W&W 
5&WP	:0	:<?< 
1<2""r+   ri   )re   r/   r  z,GradioComponent | ComponentMeta | Any | None)@r(   
__future__r   r   r   r   collections.abcr   r   dataclassesr   r   pathlibr   typingr	   r
   r   r   r   r   gradio_clientr   r   gradio_client.documentationr   typing_extensionsr   r   gradiogradio.component_metar   gradio.componentsr   r   gradio.components.basegradio.data_classesr   r   r   gradio.eventsr   gradio.exceptionsr   gradio.i18nr   r   r.   r3   r=   rD   rH   rM   rP   rR   rX   r]   r   r/   r[   r   r^   rg   ri   r*   r+   r,   <module>r"     s    "    . (   0 0 4  / - F F   #   
49 4 4, 

 
 
=9 =+) +#+ #
{  /k /
Y 
 

< <  < /  	%U3Z%
&c5:t.C(D
DE
5eCj$&'()
 '1 
\"i \" \"r+   