Spaces:
Runtime error
Runtime error
Commit ·
86504e3
1
Parent(s): 454d802
updating with local dev
Browse files- app.py +12 -13
- config.py +2 -2
- configProd.py +6 -1
- persistStorage.py +1 -6
app.py
CHANGED
|
@@ -83,33 +83,32 @@ def preProcessSQL(sql):
|
|
| 83 |
disclaimerOutputStripping = """Results are stripped to show only top 5 rows.
|
| 84 |
Please add your custom limit to get extend result.
|
| 85 |
eg\n select * from schema.table limit 20\n\n"""
|
| 86 |
-
|
| 87 |
-
|
| 88 |
return sql, disclaimerOutputStripping
|
| 89 |
|
| 90 |
def testSQL(sql):
|
| 91 |
-
global
|
| 92 |
-
dbEngine2 = DbEngine(dbCreds)
|
| 93 |
|
| 94 |
sql, disclaimerOutputStripping = preProcessSQL(sql=sql)
|
| 95 |
if not isDataQuery(sql):
|
| 96 |
return "Sorry not allowed to run. As the query modifies the data."
|
| 97 |
try:
|
| 98 |
-
|
| 99 |
-
conn =
|
| 100 |
df = pd.read_sql_query(sql, con=conn)
|
| 101 |
-
dbEngine2.disconnect()
|
| 102 |
return disclaimerOutputStripping + str(pd.DataFrame(df))
|
| 103 |
except Exception as e:
|
| 104 |
errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
|
| 105 |
saveLog(errorMessage, 'error')
|
|
|
|
| 106 |
print(f"Error occured during running the query {sql}.\n and the error is {str(e)}")
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
return f"The query you entered throws some error. Here is
|
| 113 |
|
| 114 |
|
| 115 |
def onSelectedTablesChange(tablesSelected):
|
|
|
|
| 83 |
disclaimerOutputStripping = """Results are stripped to show only top 5 rows.
|
| 84 |
Please add your custom limit to get extend result.
|
| 85 |
eg\n select * from schema.table limit 20\n\n"""
|
| 86 |
+
sql = str(sql)
|
| 87 |
+
sql = sqlparse.format(sql, reindent=True, keyword_case='upper')
|
| 88 |
return sql, disclaimerOutputStripping
|
| 89 |
|
| 90 |
def testSQL(sql):
|
| 91 |
+
global dbEngine, queryHelper
|
|
|
|
| 92 |
|
| 93 |
sql, disclaimerOutputStripping = preProcessSQL(sql=sql)
|
| 94 |
if not isDataQuery(sql):
|
| 95 |
return "Sorry not allowed to run. As the query modifies the data."
|
| 96 |
try:
|
| 97 |
+
dbEngine.connect()
|
| 98 |
+
conn = dbEngine.getConnection()
|
| 99 |
df = pd.read_sql_query(sql, con=conn)
|
|
|
|
| 100 |
return disclaimerOutputStripping + str(pd.DataFrame(df))
|
| 101 |
except Exception as e:
|
| 102 |
errorMessage = {"function":"testSQL","error":str(e), "userInput":sql}
|
| 103 |
saveLog(errorMessage, 'error')
|
| 104 |
+
|
| 105 |
print(f"Error occured during running the query {sql}.\n and the error is {str(e)}")
|
| 106 |
+
|
| 107 |
+
prompt = f"Please correct the following sql query, also it has to be run on {PLATFORM}. sql query is \n {sql}. the error occured is {str(e)}."
|
| 108 |
+
modifiedSql = queryHelper.modifySqlQueryEnteredByUser(prompt)
|
| 109 |
+
logMessage = {"function":"queryHelper.modifySqlQueryEnteredByUser", "sqlQuery":sql, "modifiedSQLQuery":modifiedSql}
|
| 110 |
+
saveLog(logMessage, 'info')
|
| 111 |
+
return f"The query you entered throws some error. Here is modified version. Please try this.\n {modifiedSql}"
|
| 112 |
|
| 113 |
|
| 114 |
def onSelectedTablesChange(tablesSelected):
|
config.py
CHANGED
|
@@ -1,2 +1,2 @@
|
|
| 1 |
-
|
| 2 |
-
from configProd import *
|
|
|
|
| 1 |
+
from configLocal import *
|
| 2 |
+
# from configProd import *
|
configProd.py
CHANGED
|
@@ -18,4 +18,9 @@ HUGGING_FACE_TOKEN = os.getenv("HUGGING_FACE_TOKEN")
|
|
| 18 |
ADMIN = os.getenv("admin")
|
| 19 |
PASSWD = os.getenv("passwd")
|
| 20 |
|
| 21 |
-
DB_CREDS_DATA = ({"database":dbName, "user":userDB, "password":pwdDB, "host":host, "port":port})
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
ADMIN = os.getenv("admin")
|
| 19 |
PASSWD = os.getenv("passwd")
|
| 20 |
|
| 21 |
+
DB_CREDS_DATA = ({"database":dbName, "user":userDB, "password":pwdDB, "host":host, "port":port})
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
logsDir = os.getenv("HF_HOME", "/data")
|
| 25 |
+
|
| 26 |
+
TABLES_DATA_DIR = os.path.join(os.getenv("HF_HOME", "/data"), "tablesData")
|
persistStorage.py
CHANGED
|
@@ -3,15 +3,10 @@ import sqlite3
|
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
import pytz
|
| 5 |
import os
|
| 6 |
-
from config import HUGGING_FACE_TOKEN
|
| 7 |
import pandas as pd
|
| 8 |
import csv
|
| 9 |
|
| 10 |
-
|
| 11 |
-
logsDir = os.getenv("HF_HOME", "/data")
|
| 12 |
-
|
| 13 |
-
TABLES_DATA_DIR = os.path.join(os.getenv("HF_HOME", "/data"), "tablesData")
|
| 14 |
-
|
| 15 |
try:
|
| 16 |
os.makedirs(TABLES_DATA_DIR, exist_ok=True)
|
| 17 |
except:
|
|
|
|
| 3 |
from datetime import datetime, timedelta
|
| 4 |
import pytz
|
| 5 |
import os
|
| 6 |
+
from config import HUGGING_FACE_TOKEN, TABLES_DATA_DIR, logsDir
|
| 7 |
import pandas as pd
|
| 8 |
import csv
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
try:
|
| 11 |
os.makedirs(TABLES_DATA_DIR, exist_ok=True)
|
| 12 |
except:
|