linden-li commited on
Commit
a355fc1
1 Parent(s): 01bb522

Fix button

Browse files
Files changed (1) hide show
  1. app.py +5 -9
app.py CHANGED
@@ -99,6 +99,11 @@ with open("style.css") as css:
99
  if "messages" not in st.session_state:
100
  st.session_state["messages"] = []
101
 
 
 
 
 
 
102
  def last_role_is_user():
103
  return len(st.session_state["messages"]) > 0 and st.session_state["messages"][-1]["role"] == "user"
104
 
@@ -248,22 +253,13 @@ def handle_user_input(user_input):
248
  st.session_state["messages"].append({"role": "assistant", "content": response, "warning": stream_warning,"error": stream_error})
249
  print(st.session_state["messages"])
250
 
251
- def clear_chat_history():
252
- st.session_state["messages"] = []
253
 
254
  if prompt := st.chat_input("Type a message!", max_chars=1000):
255
  handle_user_input(prompt)
256
 
257
-
258
-
259
  with st.sidebar:
260
  with st.container():
261
  st.title("Examples")
262
  for prompt in EXAMPLE_PROMPTS:
263
  st.button(prompt, args=(prompt,), on_click=handle_user_input)
264
- for _ in range(5):
265
- st.write("")
266
- col1, col2, col3 = st.columns([1, 2, 1])
267
- with col2:
268
- st.button('Clear Chat History', on_click=clear_chat_history)
269
 
 
99
  if "messages" not in st.session_state:
100
  st.session_state["messages"] = []
101
 
102
+ def clear_chat_history():
103
+ st.session_state["messages"] = []
104
+
105
+ st.button('Clear Chat', on_click=clear_chat_history)
106
+
107
  def last_role_is_user():
108
  return len(st.session_state["messages"]) > 0 and st.session_state["messages"][-1]["role"] == "user"
109
 
 
253
  st.session_state["messages"].append({"role": "assistant", "content": response, "warning": stream_warning,"error": stream_error})
254
  print(st.session_state["messages"])
255
 
 
 
256
 
257
  if prompt := st.chat_input("Type a message!", max_chars=1000):
258
  handle_user_input(prompt)
259
 
 
 
260
  with st.sidebar:
261
  with st.container():
262
  st.title("Examples")
263
  for prompt in EXAMPLE_PROMPTS:
264
  st.button(prompt, args=(prompt,), on_click=handle_user_input)
 
 
 
 
 
265