|
import ipywidgets as widgets |
|
from IPython.display import clear_output |
|
|
|
|
|
user_input = widgets.Textarea( |
|
value="", |
|
placeholder="Type your prompt here", |
|
disabled=False, |
|
style={"description_width": "initial"}, |
|
layout=widgets.Layout(width="100%", height="100%"), |
|
) |
|
|
|
|
|
submit_button = widgets.Button( |
|
description="Submit", button_style="success", layout=widgets.Layout(width="100%", height="80%") |
|
) |
|
|
|
|
|
def on_button_clicked(b): |
|
user_prompt = user_input.value |
|
user_input.value = "" |
|
print("\nUser:\n", user_prompt) |
|
conversational_agent.run(user_prompt) |
|
|
|
|
|
submit_button.on_click(on_button_clicked) |
|
|
|
|
|
memory_button = widgets.Button( |
|
description="Show Memory", button_style="info", layout=widgets.Layout(width="100%", height="100%") |
|
) |
|
|
|
|
|
def on_memory_button_clicked(b): |
|
memory = conversational_agent.memory.load() |
|
if len(memory): |
|
print("\nMemory:\n", memory) |
|
else: |
|
print("Memory is empty") |
|
|
|
|
|
memory_button.on_click(on_memory_button_clicked) |
|
|
|
|
|
clear_button = widgets.Button( |
|
description="Clear Memory", button_style="warning", layout=widgets.Layout(width="100%", height="100%") |
|
) |
|
|
|
|
|
def on_clear_button_button_clicked(b): |
|
conversational_agent.memory.clear() |
|
print("\nMemory is cleared\n") |
|
|
|
|
|
clear_button.on_click(on_clear_button_button_clicked) |
|
|
|
|
|
grid = widgets.GridspecLayout(3, 3, height="200px", width="800px", grid_gap="10px") |
|
grid[0, 2] = clear_button |
|
grid[0:2, 0:2] = user_input |
|
grid[2, 0:] = submit_button |
|
grid[1, 2] = memory_button |
|
display(grid) |