Spaces:
Running
Running
added reset functionality
Browse files
app.py
CHANGED
@@ -14,6 +14,9 @@ def launch_bot():
|
|
14 |
response = vq.submit_query(question, cfg.bot_role, cfg.topic, cfg.style)
|
15 |
return response
|
16 |
|
|
|
|
|
|
|
17 |
if 'cfg' not in st.session_state:
|
18 |
cfg = OmegaConf.create({
|
19 |
'customer_id': str(os.environ['VECTARA_CUSTOMER_ID']),
|
@@ -24,6 +27,10 @@ def launch_bot():
|
|
24 |
st.session_state.cfg = cfg
|
25 |
st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_id, cfg.prompt_name)
|
26 |
|
|
|
|
|
|
|
|
|
27 |
cfg = st.session_state.cfg
|
28 |
vq = st.session_state.vq
|
29 |
st.set_page_config(page_title="Debate Bot", layout="wide")
|
@@ -36,14 +43,27 @@ def launch_bot():
|
|
36 |
role_options = ['in opposition to', 'in support of']
|
37 |
cfg.human_role = st.selectbox('Your are:', role_options)
|
38 |
cfg.bot_role = role_options[1] if cfg.human_role == role_options[0] else role_options[0]
|
|
|
|
|
|
|
39 |
|
40 |
topic_options = list(topics.keys())
|
41 |
cfg.topic = st.selectbox('The topic:', topic_options)
|
42 |
vq.corpus_id = topics[cfg.topic]
|
|
|
|
|
|
|
43 |
|
44 |
st.markdown("\n")
|
45 |
debate_styles = ['Lincoln-Douglas', 'Spontaneous Argumentation', 'Parliamentary debates']
|
46 |
cfg.style = st.selectbox('Debate Style:', debate_styles)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
47 |
|
48 |
st.markdown("---")
|
49 |
st.markdown(
|
@@ -53,8 +73,9 @@ def launch_bot():
|
|
53 |
)
|
54 |
st.markdown("---")
|
55 |
|
|
|
56 |
if "messages" not in st.session_state.keys():
|
57 |
-
|
58 |
|
59 |
# Display chat messages
|
60 |
for message in st.session_state.messages:
|
@@ -66,7 +87,7 @@ def launch_bot():
|
|
66 |
st.session_state.messages.append({"role": "user", "content": prompt, "avatar": 'π§βπ»'})
|
67 |
with st.chat_message("user", avatar='π§βπ»'):
|
68 |
st.write(prompt)
|
69 |
-
|
70 |
# Generate a new response if last message is not from assistant
|
71 |
if st.session_state.messages[-1]["role"] != "assistant":
|
72 |
with st.chat_message("assistant", avatar='π€'):
|
|
|
14 |
response = vq.submit_query(question, cfg.bot_role, cfg.topic, cfg.style)
|
15 |
return response
|
16 |
|
17 |
+
def reset():
|
18 |
+
st.session_state.messages = [{"role": "assistant", "content": "Please make your opening statement.", "avatar": 'π¦'}]
|
19 |
+
|
20 |
if 'cfg' not in st.session_state:
|
21 |
cfg = OmegaConf.create({
|
22 |
'customer_id': str(os.environ['VECTARA_CUSTOMER_ID']),
|
|
|
27 |
st.session_state.cfg = cfg
|
28 |
st.session_state.vq = VectaraQuery(cfg.api_key, cfg.customer_id, cfg.corpus_id, cfg.prompt_name)
|
29 |
|
30 |
+
st.session_state.current_human_role = None
|
31 |
+
st.session_state.current_topic = None
|
32 |
+
st.session_state.style = None
|
33 |
+
|
34 |
cfg = st.session_state.cfg
|
35 |
vq = st.session_state.vq
|
36 |
st.set_page_config(page_title="Debate Bot", layout="wide")
|
|
|
43 |
role_options = ['in opposition to', 'in support of']
|
44 |
cfg.human_role = st.selectbox('Your are:', role_options)
|
45 |
cfg.bot_role = role_options[1] if cfg.human_role == role_options[0] else role_options[0]
|
46 |
+
if st.session_state.current_human_role != cfg.human_role:
|
47 |
+
st.session_state.current_human_role = cfg.human_role
|
48 |
+
reset()
|
49 |
|
50 |
topic_options = list(topics.keys())
|
51 |
cfg.topic = st.selectbox('The topic:', topic_options)
|
52 |
vq.corpus_id = topics[cfg.topic]
|
53 |
+
if st.session_state.current_topic != cfg.topic:
|
54 |
+
st.session_state.current_topic = cfg.topic
|
55 |
+
reset()
|
56 |
|
57 |
st.markdown("\n")
|
58 |
debate_styles = ['Lincoln-Douglas', 'Spontaneous Argumentation', 'Parliamentary debates']
|
59 |
cfg.style = st.selectbox('Debate Style:', debate_styles)
|
60 |
+
if st.session_state.style != cfg.style:
|
61 |
+
st.session_state.style = cfg.style
|
62 |
+
reset()
|
63 |
+
|
64 |
+
st.markdown("\n\n")
|
65 |
+
if st.button('Start Over'):
|
66 |
+
reset()
|
67 |
|
68 |
st.markdown("---")
|
69 |
st.markdown(
|
|
|
73 |
)
|
74 |
st.markdown("---")
|
75 |
|
76 |
+
|
77 |
if "messages" not in st.session_state.keys():
|
78 |
+
reset()
|
79 |
|
80 |
# Display chat messages
|
81 |
for message in st.session_state.messages:
|
|
|
87 |
st.session_state.messages.append({"role": "user", "content": prompt, "avatar": 'π§βπ»'})
|
88 |
with st.chat_message("user", avatar='π§βπ»'):
|
89 |
st.write(prompt)
|
90 |
+
|
91 |
# Generate a new response if last message is not from assistant
|
92 |
if st.session_state.messages[-1]["role"] != "assistant":
|
93 |
with st.chat_message("assistant", avatar='π€'):
|