Package: gradio-multichat
gradio_multichatA variant of Gradio's Chatbot component that can handle multiple entities, which can be useful for role-playing and/or multi-agent tasks.Installationpipinstallgradio_multichatUsageimportgradioasgrfromgradio_multichatimportMultiChatAVATARS=["https://thumbs.dreamstime.com/b/smiling-old-man-having-coffee-portrait-looking-happy-33471677.jpg","https://th.bing.com/th/id/OIP.sU-uj10S6p05niuTGnpkUgAAAA?rs=1&pid=ImgDetMain","https://images.pexels.com/photos/350784/pexels-photo-350784.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1","https://images.pexels.com/photos/2085831/pexels-photo-2085831.jpeg?auto=compress&cs=tinysrgb&w=1260&h=750&dpr=1"]defexample(value):samples=[["user",value],["bot",f"World!"],["john","Hello, Get Up!"],["carl","..."],]return("",samples,samples,)entities={"user":{"role":"user","avatar":AVATARS[0],},"bot":{"role":"bot","avatar":AVATARS[1],},"john":{"role":"user","avatar":AVATARS[2],},"carl":{"role":"bot","avatar":AVATARS[3],},}withgr.Blocks()asdemo:withgr.Tab("boobles"):chatbot_a=MultiChat(value=[],label="CustomChat",characters=entities,layout="bubble")withgr.Tab("panels"):chatbot_b=MultiChat(value=[],label="CustomChat",characters=entities,layout="panel")withgr.Row():withgr.Column(scale=999):text_input=gr.Textbox(interactive=True,placeholder="Add you prompt here",container=False,lines=4,max_lines=4,)withgr.Column(min_width=98):withgr.Group():send_button=gr.Button("Send",variant="primary")clear_button=gr.Button("Clear")gr.on([send_button.click,text_input.submit],example,text_input,[text_input,chatbot_a,chatbot_b],)if__name__=="__main__":demo.launch()MultiChatInitializationnametypedefaultdescriptionvaluelist[list[str|tuple[str]|tuple[str|pathlib.Path,str]|None]]|Callable|NoneNoneDefault value to show in chatbot. If callable, the function will be called whenever the app loads to set the initial value of the component.labelstr|NoneNoneThe 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.everyfloat|NoneNoneIf `value` is a callable, run the function 'every' number of seconds while the client connection is open. Has no effect otherwise. The event can be accessed (e.g. to cancel it) via this component's .load_event attribute.show_labelbool|NoneNoneif True, will display label.containerboolTrueIf True, will place the component in a container - providing some extra padding around the border.scaleint|NoneNonerelative 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_widthint160minimum 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.visibleboolTrueIf False, component will be hidden.elem_idstr|NoneNoneAn optional string that is assigned as the id of this component in the HTML DOM. Can be used for targeting CSS styles.elem_classeslist[str]|str|NoneNoneAn optional list of strings that are assigned as the classes of this component in the HTML DOM. Can be used for targeting CSS styles.renderboolTrueIf 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.heightint|str|NoneNoneThe height of the component, specified in pixels if a number is passed, or in CSS units if a string is passed.latex_delimiterslist[dict[str,str|bool]]|NoneNoneA 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).rtlboolFalseIf True, sets the direction of the rendered text to right-to-left. Default is False, which renders text left-to-right.show_share_buttonbool|NoneNoneIf 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_buttonboolFalseIf True, will show a copy button for each chatbot message.charactersdict|NoneNoneNonesanitize_htmlboolTrueIf False, will disable HTML sanitization for chatbot messages. This is not recommended, as it can lead to security vulnerabilities.render_markdownboolTrueIf False, will disable Markdown rendering for chatbot messages.bubble_full_widthboolTrueIf False, the chat bubble will fit to the content of the message. If True (default), the chat bubble will be the full width of the component.line_breaksboolTrueIf 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.likeableboolFalseWhether the chat messages display a like or dislike button. Set automatically by the .like method but has to be present in the signature for it to show up in the config.layout"panel"|"bubble"|NoneNoneIf "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".EventsnamedescriptionchangeTriggered when the value of the MultiChat changes either because of user input (e.g. a user types in a textbox) OR because of a function update (e.g. an image receives a value from the output of an event trigger). See.input()for a listener that is only triggered by user input.selectEvent listener for when the user selects or deselects the MultiChat. Uses event data gradio.SelectData to carryvaluereferring to the label of the MultiChat, andselectedto refer to state of the MultiChat. See EventData documentation on how to use this event datalikeThis listener is triggered when the user likes/dislikes from within the MultiChat. This event has EventData of type gradio.LikeData that carries information, accessible through LikeData.index and LikeData.value. See EventData documentation on how to use this event data.User functionThe impact on the users predict function varies depending on whether the component is used as an input or output for an event (or both).When used as an Input, the component only impacts the input signature of the user function.When used as an output, the component only impacts the return signature of the user function.The code snippet below is accurate in cases where the component is used as both an input and an output.As output:Is passed, passes the messages in the chatbot as alist[list[str, str | None]]. The inner list has 2 elements:.As input:Should return, receives a list of either list or turple of a pair of a strings. The first string represents the entity, while the second string represents the content.defpredict(value:list[tuple[str,str|None]]|None)->list[tuple[str,typing.Any]]|list[list[typing.Any]]|None:returnvalue