I have this data:
data = [
{"human1": "i am human", "human2": None},
{"human1": None, "human2": "i can help"},
{"human1": None, "human2": "i can do many things"},
{"human1": "give me an example", "human2": None}
]
with open('data.yaml', 'w') as file:
yaml.dump(data, file)
That stores the chat history using gradio.Chatbot. this is the code:
def send_message(msg, history):
time.sleep(1)
data.append({"human1": msg, "human2": None})
with open('data.yaml', 'w') as file:
yaml.dump(data, file)
return "", history + [[msg, None]]
with gr.Blocks() as demo:
with open('data.yaml', 'r') as file:
data = yaml.load(file, Loader=yaml.FullLoader)
history = gr.Chatbot([(item.get("human1"), item.get("human2")) for item in data])
msg = gr.Textbox()
msg.submit(send_message, [msg, history], [msg, history])
demo.launch()
The problem is that everytime I open a new browser tab, the history disappears, however the file data.yaml is storing the conversations correctly.
Any idea?