Update app.py
Browse files
app.py
CHANGED
@@ -98,23 +98,35 @@ def chat(input, history=[]):
|
|
98 |
|
99 |
|
100 |
def sqlquery(input):
|
|
|
|
|
101 |
|
102 |
#input_text = " ".join(conversation_history) + " " + input
|
103 |
sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
|
104 |
sql_outputs = sql_model.generate(**sql_encoding)
|
105 |
sql_response = sql_tokenizer.batch_decode(sql_outputs, skip_special_tokens=True)
|
106 |
|
107 |
-
'''
|
108 |
-
global conversation_history
|
109 |
|
|
|
|
|
110 |
# Maintain the conversation history
|
111 |
conversation_history.append("User: " + input + "\n")
|
112 |
conversation_history.append("Bot: " + " ".join(sql_response) + "\n" )
|
113 |
|
114 |
output = " ".join(conversation_history)
|
115 |
return output
|
116 |
-
'''
|
117 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
118 |
|
119 |
|
120 |
chat_interface = gr.Interface(
|
@@ -127,6 +139,7 @@ chat_interface = gr.Interface(
|
|
127 |
description="Type your message in the box above, and the chatbot will respond.",
|
128 |
)
|
129 |
|
|
|
130 |
sql_interface = gr.Interface(
|
131 |
fn=sqlquery,
|
132 |
theme="default",
|
@@ -137,6 +150,14 @@ sql_interface = gr.Interface(
|
|
137 |
title="ST SQL Chat",
|
138 |
description="Type your message in the box above, and the chatbot will respond.",
|
139 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
140 |
|
141 |
combine_interface = gr.TabbedInterface(
|
142 |
interface_list=[
|
@@ -147,4 +168,5 @@ combine_interface = gr.TabbedInterface(
|
|
147 |
)
|
148 |
|
149 |
if __name__ == '__main__':
|
150 |
-
combine_interface.launch()
|
|
|
|
98 |
|
99 |
|
100 |
def sqlquery(input):
|
101 |
+
|
102 |
+
history = gr.get_state() or []
|
103 |
|
104 |
#input_text = " ".join(conversation_history) + " " + input
|
105 |
sql_encoding = sql_tokenizer(table=table, query=input + sql_tokenizer.eos_token, return_tensors="pt")
|
106 |
sql_outputs = sql_model.generate(**sql_encoding)
|
107 |
sql_response = sql_tokenizer.batch_decode(sql_outputs, skip_special_tokens=True)
|
108 |
|
|
|
|
|
109 |
|
110 |
+
#global conversation_history
|
111 |
+
'''
|
112 |
# Maintain the conversation history
|
113 |
conversation_history.append("User: " + input + "\n")
|
114 |
conversation_history.append("Bot: " + " ".join(sql_response) + "\n" )
|
115 |
|
116 |
output = " ".join(conversation_history)
|
117 |
return output
|
118 |
+
'''
|
119 |
+
|
120 |
+
history.append((input, sql_response))
|
121 |
+
gr.set_state(history)
|
122 |
+
html = "<div class='chatbot'>"
|
123 |
+
for user_msg, resp_msg in history:
|
124 |
+
html += f"<div class='user_msg'>{user_msg}</div>"
|
125 |
+
html += f"<div class='resp_msg'>{resp_msg}</div>"
|
126 |
+
html += "</div>"
|
127 |
+
return html
|
128 |
+
|
129 |
+
#return sql_response
|
130 |
|
131 |
|
132 |
chat_interface = gr.Interface(
|
|
|
139 |
description="Type your message in the box above, and the chatbot will respond.",
|
140 |
)
|
141 |
|
142 |
+
"""
|
143 |
sql_interface = gr.Interface(
|
144 |
fn=sqlquery,
|
145 |
theme="default",
|
|
|
150 |
title="ST SQL Chat",
|
151 |
description="Type your message in the box above, and the chatbot will respond.",
|
152 |
)
|
153 |
+
"""
|
154 |
+
|
155 |
+
iface = gr.Interface(chat, "text", "html", css="""
|
156 |
+
.chatbox {display:flex;flex-direction:column}
|
157 |
+
.user_msg, .resp_msg {padding:4px;margin-bottom:4px;border-radius:4px;width:80%}
|
158 |
+
.user_msg {background-color:cornflowerblue;color:white;align-self:start}
|
159 |
+
.resp_msg {background-color:lightgray;align-self:self-end}
|
160 |
+
""", allow_screenshot=False, allow_flagging=False)
|
161 |
|
162 |
combine_interface = gr.TabbedInterface(
|
163 |
interface_list=[
|
|
|
168 |
)
|
169 |
|
170 |
if __name__ == '__main__':
|
171 |
+
#combine_interface.launch()
|
172 |
+
iface.launch(debug=True)
|