Update app.py
Browse files
app.py
CHANGED
@@ -64,9 +64,8 @@ sql_tokenizer = TapexTokenizer.from_pretrained(sql_model_name)
|
|
64 |
sql_model = BartForConditionalGeneration.from_pretrained(sql_model_name)
|
65 |
|
66 |
#sql_response = None
|
67 |
-
conversation_history = []
|
68 |
|
69 |
-
def predict(input
|
70 |
|
71 |
#global sql_response
|
72 |
# Check if the user input is a question
|
@@ -80,13 +79,7 @@ def predict(input): #history=[]):
|
|
80 |
|
81 |
else:
|
82 |
'''
|
83 |
-
|
84 |
-
bot_input = tokenizer.encode(input + tokenizer.eos_token, return_tensors="pt")
|
85 |
-
chat_history_ids = model.generate(bot_input, max_length=1000, pad_token_id=tokenizer.eos_token_id)
|
86 |
-
response = tokenizer.decode(chat_history_ids[:, bot_input.shape[-1]:][0], skip_special_tokens=True)
|
87 |
-
#return response
|
88 |
-
|
89 |
-
'''
|
90 |
# tokenize the new input sentence
|
91 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
92 |
|
@@ -99,20 +92,10 @@ def predict(input): #history=[]):
|
|
99 |
# convert the tokens to text, and then split the responses into the right format
|
100 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
101 |
response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)] # convert to tuples of list
|
102 |
-
'''
|
103 |
|
104 |
-
return response
|
105 |
|
106 |
-
def chatbot_interface(user_input):
|
107 |
-
global conversation_history
|
108 |
-
|
109 |
-
conversation_history.append(user_input)
|
110 |
|
111 |
-
dialog_prompt = "User: " + " ".join(conversation_history) + "\nBot:"
|
112 |
-
response = predict(dialog_prompt)
|
113 |
-
conversation_history.append(response)
|
114 |
-
return response
|
115 |
-
|
116 |
def sqlquery(input):
|
117 |
|
118 |
sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
|
@@ -123,11 +106,13 @@ def sqlquery(input):
|
|
123 |
|
124 |
|
125 |
chat_interface = gr.Interface(
|
126 |
-
fn=
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
|
|
|
|
131 |
)
|
132 |
|
133 |
sql_interface = gr.Interface(
|
|
|
64 |
sql_model = BartForConditionalGeneration.from_pretrained(sql_model_name)
|
65 |
|
66 |
#sql_response = None
|
|
|
67 |
|
68 |
+
def predict(input, history=[]):
|
69 |
|
70 |
#global sql_response
|
71 |
# Check if the user input is a question
|
|
|
79 |
|
80 |
else:
|
81 |
'''
|
82 |
+
|
|
|
|
|
|
|
|
|
|
|
|
|
83 |
# tokenize the new input sentence
|
84 |
new_user_input_ids = tokenizer.encode(input + tokenizer.eos_token, return_tensors='pt')
|
85 |
|
|
|
92 |
# convert the tokens to text, and then split the responses into the right format
|
93 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
94 |
response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)] # convert to tuples of list
|
|
|
95 |
|
96 |
+
return response, history
|
97 |
|
|
|
|
|
|
|
|
|
98 |
|
|
|
|
|
|
|
|
|
|
|
99 |
def sqlquery(input):
|
100 |
|
101 |
sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
|
|
|
106 |
|
107 |
|
108 |
chat_interface = gr.Interface(
|
109 |
+
fn=predict,
|
110 |
+
theme="default",
|
111 |
+
css=".footer {display:none !important}",
|
112 |
+
inputs=["text", "state"],
|
113 |
+
outputs=["chatbot", "state"],
|
114 |
+
title="ST Chatbot",
|
115 |
+
description="Type your message in the box above, and the chatbot will respond.",
|
116 |
)
|
117 |
|
118 |
sql_interface = gr.Interface(
|