ericzzz commited on
Commit
5a344af
1 Parent(s): e578fce

Update app.py

Browse files

Disable chat_input while generating

Files changed (1) hide show
  1. app.py +10 -1
app.py CHANGED
@@ -8,8 +8,10 @@ REPETITION_PENALTY = 1.05
8
  MAX_NEW_TOKENS = 500
9
  MODEL_NAME = "ericzzz/falcon-rw-1b-chat"
10
 
 
11
  st.write("**💬Tiny Chat with [Falcon-RW-1B-Chat](https://huggingface.co/ericzzz/falcon-rw-1b-chat)**" )
12
 
 
13
  if "chat_history" not in st.session_state:
14
  st.session_state.chat_history = []
15
 
@@ -103,6 +105,8 @@ class ResponseStreamer:
103
  # clean up states (actually not needed as the instance will get recreated)
104
  self.first_call_to_put = True
105
  self.current_response = ""
 
 
106
 
107
 
108
  tokenizer, model = load_model()
@@ -111,8 +115,13 @@ chat_messages_container = st.container()
111
  for msg in st.session_state.chat_history:
112
  show_chat_message(chat_messages_container, msg)
113
 
114
- user_input = st.chat_input()
 
 
115
  if user_input:
 
 
 
116
  new_user_message = {"role": "user", "content": user_input}
117
  st.session_state.chat_history.append(new_user_message)
118
  show_chat_message(chat_messages_container, new_user_message)
 
8
  MAX_NEW_TOKENS = 500
9
  MODEL_NAME = "ericzzz/falcon-rw-1b-chat"
10
 
11
+ # fmt: off
12
  st.write("**💬Tiny Chat with [Falcon-RW-1B-Chat](https://huggingface.co/ericzzz/falcon-rw-1b-chat)**" )
13
 
14
+ # fmt: on
15
  if "chat_history" not in st.session_state:
16
  st.session_state.chat_history = []
17
 
 
105
  # clean up states (actually not needed as the instance will get recreated)
106
  self.first_call_to_put = True
107
  self.current_response = ""
108
+ # rerun to unfreeze the chat_input
109
+ st.rerun()
110
 
111
 
112
  tokenizer, model = load_model()
 
115
  for msg in st.session_state.chat_history:
116
  show_chat_message(chat_messages_container, msg)
117
 
118
+ input_placeholder = st.empty() # use placeholder as a hack to disable input
119
+ user_input = input_placeholder.chat_input(key="user_input_original")
120
+
121
  if user_input:
122
+ # disable chat_input while generating
123
+ input_placeholder.chat_input(key="user_input_disabled", disabled=True)
124
+
125
  new_user_message = {"role": "user", "content": user_input}
126
  st.session_state.chat_history.append(new_user_message)
127
  show_chat_message(chat_messages_container, new_user_message)