Update app.py
Browse files
app.py
CHANGED
@@ -64,7 +64,7 @@ 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 chat(input, history=[]):
|
70 |
|
@@ -92,14 +92,14 @@ def chat(input, history=[]):
|
|
92 |
|
93 |
# convert the tokens to text, and then split the responses into the right format
|
94 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
95 |
-
|
96 |
|
97 |
return response, history
|
98 |
|
99 |
|
100 |
-
def sqlquery(input):
|
101 |
|
102 |
-
global conversation_history
|
103 |
|
104 |
#input_text = " ".join(conversation_history) + " " + input
|
105 |
sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
|
@@ -117,16 +117,16 @@ def sqlquery(input):
|
|
117 |
return output
|
118 |
'''
|
119 |
|
120 |
-
|
121 |
#conversation_history.append(("User", input))
|
122 |
#conversation_history.append(("Bot", sql_response))
|
123 |
|
124 |
# Build conversation string
|
125 |
-
conversation = "\n".join([f"User: {user_msg}\nBot: {resp_msg}" for user_msg, resp_msg in
|
126 |
-
#conversation = "\n".join([f"{sender}: {msg}" for sender, msg in
|
127 |
|
128 |
#return conversation
|
129 |
-
return
|
130 |
|
131 |
'''
|
132 |
html = "<div class='chatbot'>"
|
@@ -154,9 +154,10 @@ sql_interface = gr.Interface(
|
|
154 |
fn=sqlquery,
|
155 |
theme="default",
|
156 |
css=".footer {display:none !important}",
|
157 |
-
inputs=gr.Textbox(prompt="You:"),
|
158 |
#outputs=gr.Textbox(),
|
159 |
-
|
|
|
160 |
#live=True,
|
161 |
#capture_session=True,
|
162 |
title="ST SQL Chat",
|
|
|
64 |
sql_model = BartForConditionalGeneration.from_pretrained(sql_model_name)
|
65 |
|
66 |
#sql_response = None
|
67 |
+
#conversation_history = []
|
68 |
|
69 |
def chat(input, history=[]):
|
70 |
|
|
|
92 |
|
93 |
# convert the tokens to text, and then split the responses into the right format
|
94 |
response = tokenizer.decode(history[0]).split("<|endoftext|>")
|
95 |
+
response = [(response[i], response[i + 1]) for i in range(0, len(response) - 1, 2)] # convert to tuples of list
|
96 |
|
97 |
return response, history
|
98 |
|
99 |
|
100 |
+
def sqlquery(input, history[]):
|
101 |
|
102 |
+
#global conversation_history
|
103 |
|
104 |
#input_text = " ".join(conversation_history) + " " + input
|
105 |
sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
|
|
|
117 |
return output
|
118 |
'''
|
119 |
|
120 |
+
history.append((input, sql_response))
|
121 |
#conversation_history.append(("User", input))
|
122 |
#conversation_history.append(("Bot", sql_response))
|
123 |
|
124 |
# Build conversation string
|
125 |
+
#conversation = "\n".join([f"User: {user_msg}\nBot: {resp_msg}" for user_msg, resp_msg in history])
|
126 |
+
#conversation = "\n".join([f"{sender}: {msg}" for sender, msg in history])
|
127 |
|
128 |
#return conversation
|
129 |
+
return sql_response, history
|
130 |
|
131 |
'''
|
132 |
html = "<div class='chatbot'>"
|
|
|
154 |
fn=sqlquery,
|
155 |
theme="default",
|
156 |
css=".footer {display:none !important}",
|
157 |
+
#inputs=gr.Textbox(prompt="You:"),
|
158 |
#outputs=gr.Textbox(),
|
159 |
+
inputs=["text", "state"],
|
160 |
+
outputs=["chatbot", "state"],
|
161 |
#live=True,
|
162 |
#capture_session=True,
|
163 |
title="ST SQL Chat",
|