Wootang01 commited on
Commit
25e4ead
·
1 Parent(s): c0fdbe0

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -1
app.py CHANGED
@@ -20,10 +20,17 @@ if 'count' not in st.session_state or st.session_state.count == 6:
20
  st.session_state.old_response = ''
21
  else:
22
  st.session_state.count += 1
23
-
 
24
  new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
 
 
25
  bot_input_ids = torch.cat([st.session_state.chat_history_ids, new_user_input_ids], dim=-1) if st.session_state.count > 1 else new_user_input_ids
 
 
26
  st.session_state.chat_history_ids = model.generate(bot_input_ids, max_length=500, pad_token_id=tokenizer.eos_token_id)
 
 
27
  response = tokenizer.decode(st.session_state.chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
28
 
29
  if st.session_state.old_response == response:
 
20
  st.session_state.old_response = ''
21
  else:
22
  st.session_state.count += 1
23
+
24
+ # tokenize the new input sentence
25
  new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
26
+
27
+ # append the new user input tokens to the chat history
28
  bot_input_ids = torch.cat([st.session_state.chat_history_ids, new_user_input_ids], dim=-1) if st.session_state.count > 1 else new_user_input_ids
29
+
30
+ # generate a response
31
  st.session_state.chat_history_ids = model.generate(bot_input_ids, max_length=500, pad_token_id=tokenizer.eos_token_id)
32
+
33
+ # convert the tokens to text, and then split the responses into lines
34
  response = tokenizer.decode(st.session_state.chat_history_ids[:, bot_input_ids.shape[-1]:][0], skip_special_tokens=True)
35
 
36
  if st.session_state.old_response == response: