anumaurya114exp commited on
Commit
8d62920
·
1 Parent(s): 11a349e

added table output

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -153,14 +153,16 @@ def testSQL(sql):
153
  conn = dbEngine2.getConnection()
154
  df = pd.read_sql_query(sql, con=conn)
155
  dbEngine2.disconnect()
156
- return disclaimerOutputStripping + str(pd.DataFrame(df))
 
157
  except Exception as e:
158
  errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
159
  saveLog(errorMessage, 'error')
160
  dbEngine2.disconnect()
161
 
162
  print(f"Error occured during running the query {sql}.\n and the error is {str(e)}")
163
- return f"The query you entered throws some error. Here is the error.\n {str(e)}"
 
164
 
165
 
166
  def onSelectedTablesChange(tablesSelected):
@@ -259,9 +261,10 @@ with gr.Blocks() as demo:
259
  gr.Markdown("""<h1><center> Run Query </center></h1>""")
260
  text_input = gr.Textbox(label = 'Input SQL Query', placeholder="Write your SQL query here ...")
261
  text_output = gr.Textbox(label = 'Result')
 
262
  text_button = gr.Button("RUN QUERY")
263
  clear = gr.ClearButton([text_input, text_output])
264
- text_button.click(testSQL, inputs=text_input, outputs=text_output)
265
 
266
  csvFileComponent = gr.File([], file_count='multiple')
267
  downloadCsv = gr.Button("Get result as csv")
 
153
  conn = dbEngine2.getConnection()
154
  df = pd.read_sql_query(sql, con=conn)
155
  dbEngine2.disconnect()
156
+ table_output = gr.DataFrame(df)
157
+ return disclaimerOutputStripping, table_output
158
  except Exception as e:
159
  errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
160
  saveLog(errorMessage, 'error')
161
  dbEngine2.disconnect()
162
 
163
  print(f"Error occured during running the query {sql}.\n and the error is {str(e)}")
164
+ table_output = gr.DataFrame(pd.DataFrame())
165
+ return f"The query you entered throws some error. Here is the error.\n {str(e)}", table_output
166
 
167
 
168
  def onSelectedTablesChange(tablesSelected):
 
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_output = gr.Textbox(label = 'Result')
264
+ table_output = gr.DataFrame(pd.Dataframe())
265
  text_button = gr.Button("RUN QUERY")
266
  clear = gr.ClearButton([text_input, text_output])
267
+ text_button.click(testSQL, inputs=text_input, outputs=[text_output, table_output])
268
 
269
  csvFileComponent = gr.File([], file_count='multiple')
270
  downloadCsv = gr.Button("Get result as csv")