-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchatbot_app.py
More file actions
33 lines (22 loc) 路 931 Bytes
/
Copy pathchatbot_app.py
File metadata and controls
33 lines (22 loc) 路 931 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import streamlit as st
import chatbot_lib as glib
st.set_page_config(page_title="Chatbot", page_icon="馃")
st.title("Chatbot")
if 'memory' not in st.session_state:
st.session_state.memory = glib.get_memory()
if 'chat_history' not in st.session_state:
st.session_state.chat_history = []
for message in st.session_state.chat_history:
with st.chat_message(message["role"]):
st.markdown(message["text"])
input_text = st.chat_input("Chat with your assistant here")
if input_text:
with st.chat_message("human"):
st.markdown(input_text)
st.session_state.chat_history.append({"role": "user", "text": input_text})
chat_response = glib.get_chat_response(
input_text=input_text, memory=st.session_state.memory)
with st.chat_message("assistant"):
st.markdown(chat_response)
st.session_state.chat_history.append(
{"role": "assistant", "text": chat_response})