Spaces:
Runtime error
Runtime error
Commit ·
e332bb9
1
Parent(s): 26221aa
Upload app.py
Browse files
app.py
CHANGED
|
@@ -40,17 +40,17 @@ metadataLayout.setSelection(DEFAULT_TABLES_COLS)
|
|
| 40 |
selectedTablesAndCols = metadataLayout.getSelectedTablesAndCols()
|
| 41 |
|
| 42 |
|
| 43 |
-
openAIClient = OpenAI(api_key=OPENAI_API_KEY)
|
| 44 |
-
gptInstanceForTableCols = ChatgptManager(openAIClient, model=GPT_MODEL)
|
| 45 |
-
gptInstanceForQuery = ChatgptManager(openAIClient, model=GPT_MODEL)
|
| 46 |
-
queryHelper = QueryHelper(gptInstanceForTableCols=gptInstanceForTableCols,
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
|
| 55 |
|
| 56 |
openAIClient2 = OpenAI(api_key=OPENAI_API_KEY)
|
|
@@ -71,21 +71,21 @@ def checkAuth(username, password):
|
|
| 71 |
|
| 72 |
|
| 73 |
|
| 74 |
-
# Function to save history of chat
|
| 75 |
-
def respond(message, chatHistory):
|
| 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,14 +241,6 @@ def onSyncLogsWithDataDir():
|
|
| 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,7 +250,7 @@ with gr.Blocks() as demo:
|
|
| 258 |
|
| 259 |
# screen 2 : To run sql query against database
|
| 260 |
with gr.Tab("Run Query"):
|
| 261 |
-
gr.Markdown("""<h1><center>
|
| 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,7 +260,7 @@ with gr.Blocks() as demo:
|
|
| 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("
|
| 272 |
downloadCsv.click(onGetResultCsvFile, inputs=text_input, outputs=csvFileComponent)
|
| 273 |
|
| 274 |
# screen 3 : To set creds, schema, tables and columns
|
|
@@ -321,4 +313,5 @@ with gr.Blocks() as demo:
|
|
| 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)
|
|
|
|
|
|
| 40 |
selectedTablesAndCols = metadataLayout.getSelectedTablesAndCols()
|
| 41 |
|
| 42 |
|
| 43 |
+
# openAIClient = OpenAI(api_key=OPENAI_API_KEY)
|
| 44 |
+
# gptInstanceForTableCols = ChatgptManager(openAIClient, model=GPT_MODEL)
|
| 45 |
+
# gptInstanceForQuery = ChatgptManager(openAIClient, model=GPT_MODEL)
|
| 46 |
+
# queryHelper = QueryHelper(gptInstanceForTableCols=gptInstanceForTableCols,
|
| 47 |
+
# gptInstanceForQuery=gptInstanceForQuery,
|
| 48 |
+
# schemaName=SCHEMA_NAME,platform=PLATFORM,
|
| 49 |
+
# metadataLayout=metadataLayout,
|
| 50 |
+
# sampleDataRows=SAMPLE_ROW_MAX,
|
| 51 |
+
# gptSampleRows=GPT_SAMPLE_ROWS,
|
| 52 |
+
# dbEngine=dbEngine,
|
| 53 |
+
# getSampleDataForTablesAndCols=getSampleDataForTablesAndCols)
|
| 54 |
|
| 55 |
|
| 56 |
openAIClient2 = OpenAI(api_key=OPENAI_API_KEY)
|
|
|
|
| 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 |
with gr.Tab("Query Helper CoT"):
|
| 245 |
gr.Markdown("""<h1><center> Query Helper CoT</center></h1>""")
|
| 246 |
chatbot = gr.Chatbot()
|
|
|
|
| 250 |
|
| 251 |
# screen 2 : To run sql query against database
|
| 252 |
with gr.Tab("Run Query"):
|
| 253 |
+
gr.Markdown("""<h1><center> Setup Tab </center></h1>""")
|
| 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 |
text_button.click(testSQL, inputs=text_input, outputs=[text_output, table_output])
|
| 261 |
|
| 262 |
csvFileComponent = gr.File([], file_count='multiple')
|
| 263 |
+
downloadCsv = gr.Button("Generate csv result file")
|
| 264 |
downloadCsv.click(onGetResultCsvFile, inputs=text_input, outputs=csvFileComponent)
|
| 265 |
|
| 266 |
# screen 3 : To set creds, schema, tables and columns
|
|
|
|
| 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, port=8080)
|
| 317 |
+
demo.close()
|