kingabzpro commited on
Commit
97ab70f
β€’
1 Parent(s): 2afefe2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -3
app.py CHANGED
@@ -20,17 +20,17 @@ model = BlenderbotForConditionalGeneration.from_pretrained("facebook/blenderbot-
20
 
21
  def predict(input, history=[]):
22
  # tokenize the new input sentence
23
- new_user_input_ids = tokenizer.encode(input, return_tensors='pt')
24
 
25
  # append the new user input tokens to the chat history
26
  bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
27
 
28
  # generate a response
29
- history = model.generate(**new_user_input_ids)
30
 
31
  # convert the tokens to text, and then split the responses into the right format
32
  response = tokenizer.decode(history[0]).split("<|endoftext|>")
33
- response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 2)] # convert to tuples of list
34
  return response, history
35
 
36
  gr.Interface(
 
20
 
21
  def predict(input, history=[]):
22
  # tokenize the new input sentence
23
+ new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
24
 
25
  # append the new user input tokens to the chat history
26
  bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
27
 
28
  # generate a response
29
+ history = model.generate(bot_input_ids, max_length=1000, pad_token_id=tokenizer.eos_token_id).tolist()
30
 
31
  # convert the tokens to text, and then split the responses into the right format
32
  response = tokenizer.decode(history[0]).split("<|endoftext|>")
33
+ response = [(response[i], response[i+1]) for i in range(0, len(response)-1, 1)] # convert to tuples of list
34
  return response, history
35
 
36
  gr.Interface(