import asyncio import panel as pn from panel.widgets import ChatEntry pn.extension() ChatEntry(value="Hi and welcome!") import pandas as pd import matplotlib.pyplot as plt df = pd.DataFrame({"x": [1, 2, 3], "y": [4, 5, 6]}) fig, axes = plt.subplots() axes.plot(df["x"], df["y"]) plt.close(fig) pn.Column( ChatEntry(value=pn.widgets.Button(name="Click")), ChatEntry(value=df), ChatEntry(value=fig), ) ChatEntry(value="Want to hear some beat boxing?", user="Beat Boxer", avatar="🎶") ChatEntry(value="Want to hear some beat boxing?", user="Beat Boxer", avatar="\N{musical note}") pn.Column( ChatEntry( value="Yes. I want to hear some beat boxing", user="Music Lover", avatar="🎸" ), ChatEntry( value=pn.Column( "Here goes. Hope you like this one?", pn.pane.Audio( "https://upload.wikimedia.org/wikipedia/commons/d/d3/Beatboxset1_pepouni.ogg" ), ), user="Beat Boxer", avatar="🎶", ), ) chat_entry = pn.widgets.ChatEntry() chat_entry chat_entry.value = pn.pane.Markdown("## Cheers!") chat_entry.param.update(user="Jolly Guy", avatar="🎅") ChatEntry.default_avatars ChatEntry.default_avatars["Wolfram"] = "🐺" ChatEntry.default_avatars["#1 good-to-go guy"] = "👍" pn.Column( ChatEntry(value="Mathematics!", user="Wolfram"), ChatEntry(value="Good to go!", user="#1 Good-to-Go Guy"), ChatEntry(value="What's up?", user="Other Guy"), max_width=300, ) pn.widgets.ChatEntry(timestamp_format="%b %d, %Y %I:%M %p") ChatEntry( value="Plain and simple", show_avatar=False, show_user=False, show_timestamp=False, reaction_icons={}, ) ChatEntry( value="Want to hear some beat boxing?", user="Beat Boxer", avatar="🎶", height=250, sizing_mode="stretch_width", max_width=600, styles={"background": "#CBC3E3"}, ) pn.widgets.ChatEntry(value="Love this!", reactions=["favorite"]) entry = pn.widgets.ChatEntry( value="Looks good!", reactions=["like"], reaction_icons={"like": "thumb-up", "dislike": "thumb-down"}, ) entry def print_reactions(reactions): print(f"{reactions} selected.") pn.bind(print_reactions, entry.param.reactions, watch=True) async def replace_response(): for value in range(0, 28): await asyncio.sleep(0.2) yield value ChatEntry(value=replace_response) sentence = """ The greatest glory in living lies not in never falling, but in rising every time we fall. """ async def append_response(): value = "" for token in sentence.split(): value += f" {token}" await asyncio.sleep(0.2) yield value ChatEntry(value=append_response, user="Wise guy", avatar="🤓") async def respond_when_ready(): spinner = pn.indicators.LoadingSpinner(value=True, size=25, color="light") layout = pn.Column("Love your question. Let me think.", spinner) yield layout await asyncio.sleep(1) # Waiting for some external response... layout.insert(-1, "I can use Matplotlib to create the Figure") yield layout await asyncio.sleep(1) # Calculating ... layout.insert(-1, fig) layout[-1] = "I hope that answered your question?" yield layout ChatEntry( value=respond_when_ready, user="Assistant", avatar="https://upload.wikimedia.org/wikipedia/commons/6/63/Yumi_UBports.png", )