teaevo commited on
Commit
b948232
1 Parent(s): 875202b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -44,13 +44,18 @@ def predict(input, history=[]):
44
 
45
  if is_question:
46
  sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
47
- sql_outputs = sql_model.generate(**sql_encoding)
48
- sql_response = sql_tokenizer.batch_decode(sql_outputs, skip_special_tokens=True)
49
-
50
- # Append the SQL model's response to the history
51
- sql_response_ids = tokenizer.encode(sql_response + tokenizer.eos_token, return_tensors='pt')
52
- history.extend(sql_response_ids[0].tolist()) # Add SQL response token IDs to history
53
 
 
 
 
 
 
 
 
 
 
54
 
55
  '''
56
  bot_input_ids = torch.cat([torch.LongTensor(history), sql_encoding], dim=-1)
@@ -61,15 +66,6 @@ def predict(input, history=[]):
61
  else:
62
  # tokenize the new input sentence
63
  new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
64
-
65
- sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
66
- sql_outputs = sql_model.generate(**sql_encoding)
67
- sql_response = sql_tokenizer.batch_decode(sql_outputs, skip_special_tokens=True)
68
-
69
- # Append the SQL model's response to the history
70
- sql_response_ids = tokenizer.encode(sql_response + tokenizer.eos_token, return_tensors='pt')
71
- history.extend(sql_response_ids[0].tolist()) # Add SQL response token IDs to history
72
-
73
 
74
  # append the new user input tokens to the chat history
75
  bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)
 
44
 
45
  if is_question:
46
  sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
47
+ #sql_outputs = sql_model.generate(**sql_encoding)
48
+ #sql_response = sql_tokenizer.batch_decode(sql_outputs, skip_special_tokens=True)
 
 
 
 
49
 
50
+ # append the new user input tokens to the chat history
51
+ bot_input_ids = torch.cat([torch.LongTensor(history), sql_encoding], dim=-1)
52
+
53
+ # generate a response
54
+ history = sql_model.generate(bot_input_ids, max_length=1000, pad_token_id=sql_tokenizer.eos_token_id).tolist()
55
+
56
+ # convert the tokens to text, and then split the responses into the right format
57
+ response = sql_tokenizer.decode(history[0]).split("<|endoftext|>")
58
+ response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)] # convert to tuples of list
59
 
60
  '''
61
  bot_input_ids = torch.cat([torch.LongTensor(history), sql_encoding], dim=-1)
 
66
  else:
67
  # tokenize the new input sentence
68
  new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
 
 
 
 
 
 
 
 
 
69
 
70
  # append the new user input tokens to the chat history
71
  bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1)