Spaces:
Runtime error
Runtime error
Commit ·
ff48602
1
Parent(s): 4d39548
Update app.py
Browse files
app.py
CHANGED
|
@@ -71,21 +71,21 @@ def checkAuth(username, password):
|
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
-
#
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
|
| 90 |
# Function to save history of chat
|
| 91 |
def respondCoT(message, chatHistory):
|
|
@@ -241,6 +241,14 @@ def onSyncLogsWithDataDir():
|
|
| 241 |
|
| 242 |
|
| 243 |
with gr.Blocks() as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
with gr.Tab("Query Helper CoT"):
|
| 245 |
gr.Markdown("""<h1><center> Query Helper CoT</center></h1>""")
|
| 246 |
chatbot = gr.Chatbot()
|
|
@@ -250,7 +258,7 @@ with gr.Blocks() as demo:
|
|
| 250 |
|
| 251 |
# screen 2 : To run sql query against database
|
| 252 |
with gr.Tab("Run Query"):
|
| 253 |
-
gr.Markdown("""<h1><center>
|
| 254 |
text_input = gr.Textbox(label = 'Input SQL Query', placeholder="Write your SQL query here ...")
|
| 255 |
text_button = gr.Button("RUN QUERY")
|
| 256 |
text_output = gr.Textbox(label = 'Result')
|
|
@@ -260,7 +268,7 @@ with gr.Blocks() as demo:
|
|
| 260 |
text_button.click(testSQL, inputs=text_input, outputs=[text_output, table_output])
|
| 261 |
|
| 262 |
csvFileComponent = gr.File([], file_count='multiple')
|
| 263 |
-
downloadCsv = gr.Button("
|
| 264 |
downloadCsv.click(onGetResultCsvFile, inputs=text_input, outputs=csvFileComponent)
|
| 265 |
|
| 266 |
# screen 3 : To set creds, schema, tables and columns
|
|
@@ -313,5 +321,4 @@ with gr.Blocks() as demo:
|
|
| 313 |
refreshLogs = gr.Button("Sync Log files from /data")
|
| 314 |
refreshLogs.click(onSyncLogsWithDataDir, inputs=None, outputs=fileComponent)
|
| 315 |
|
| 316 |
-
demo.launch(share=True, debug=True, ssl_verify=False, auth=checkAuth
|
| 317 |
-
demo.close()
|
|
|
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
+
# Function to save history of chat
|
| 75 |
+
def respond(message, chatHistory):
|
| 76 |
+
"""gpt response handler for gradio ui"""
|
| 77 |
+
global queryHelper
|
| 78 |
+
try:
|
| 79 |
+
botMessage = queryHelper.getQueryForUserInput(message)
|
| 80 |
+
except Exception as e:
|
| 81 |
+
errorMessage = {"function":"queryHelper.getQueryForUserInput","error":str(e), "userInput":message}
|
| 82 |
+
saveLog(errorMessage, 'error')
|
| 83 |
+
raise ValueError(str(e))
|
| 84 |
+
queryGenerated = extractSqlFromGptResponse(botMessage)
|
| 85 |
+
logMessage = {"userInput":message, "queryGenerated":queryGenerated, "completeGptResponse":botMessage, "function":"queryHelper.getQueryForUserInput"}
|
| 86 |
+
saveLog(logMessage)
|
| 87 |
+
chatHistory.append((message, botMessage))
|
| 88 |
+
return "", chatHistory
|
| 89 |
|
| 90 |
# Function to save history of chat
|
| 91 |
def respondCoT(message, chatHistory):
|
|
|
|
| 241 |
|
| 242 |
|
| 243 |
with gr.Blocks() as demo:
|
| 244 |
+
# screen 1 : Chatbot for question answering to generate sql query from user input in english
|
| 245 |
+
with gr.Tab("Query Helper"):
|
| 246 |
+
gr.Markdown("""<h1><center> Query Helper</center></h1>""")
|
| 247 |
+
chatbot = gr.Chatbot()
|
| 248 |
+
msg = gr.Textbox()
|
| 249 |
+
clear = gr.ClearButton([msg, chatbot])
|
| 250 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
| 251 |
+
|
| 252 |
with gr.Tab("Query Helper CoT"):
|
| 253 |
gr.Markdown("""<h1><center> Query Helper CoT</center></h1>""")
|
| 254 |
chatbot = gr.Chatbot()
|
|
|
|
| 258 |
|
| 259 |
# screen 2 : To run sql query against database
|
| 260 |
with gr.Tab("Run Query"):
|
| 261 |
+
gr.Markdown("""<h1><center> Run Query </center></h1>""")
|
| 262 |
text_input = gr.Textbox(label = 'Input SQL Query', placeholder="Write your SQL query here ...")
|
| 263 |
text_button = gr.Button("RUN QUERY")
|
| 264 |
text_output = gr.Textbox(label = 'Result')
|
|
|
|
| 268 |
text_button.click(testSQL, inputs=text_input, outputs=[text_output, table_output])
|
| 269 |
|
| 270 |
csvFileComponent = gr.File([], file_count='multiple')
|
| 271 |
+
downloadCsv = gr.Button("Get result as csv")
|
| 272 |
downloadCsv.click(onGetResultCsvFile, inputs=text_input, outputs=csvFileComponent)
|
| 273 |
|
| 274 |
# screen 3 : To set creds, schema, tables and columns
|
|
|
|
| 321 |
refreshLogs = gr.Button("Sync Log files from /data")
|
| 322 |
refreshLogs.click(onSyncLogsWithDataDir, inputs=None, outputs=fileComponent)
|
| 323 |
|
| 324 |
+
demo.launch(share=True, debug=True, ssl_verify=False, auth=checkAuth)
|
|
|