AliInamdar commited on
Commit
d43f197
Β·
verified Β·
1 Parent(s): 44c466e

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. streamlit_app.py +10 -1
streamlit_app.py CHANGED
@@ -5,7 +5,7 @@ from pandasql import sqldf
5
 
6
  # πŸ›  Page setup
7
  st.set_page_config(page_title="🧠 Excel SQL Assistant", layout="centered")
8
- st.title("SQL CHATBOT - POC")
9
 
10
  # πŸ” Load API Key securely
11
  TOGETHER_API_KEY = st.secrets.get("TOGETHER_API_KEY", None)
@@ -52,6 +52,7 @@ IMPORTANT:
52
  - Use SQL compatible with SQLite.
53
  - Table name is 'df'.
54
  - If column names contain spaces or special characters, wrap them in double quotes.
 
55
  """
56
 
57
  # πŸ”— Together API request
@@ -82,6 +83,14 @@ IMPORTANT:
82
  # 🧼 Clean the response
83
  sql_query = response.json()['choices'][0]['message']['content'].strip()
84
  sql_query = sql_query.replace("```sql", "").replace("```", "").strip()
 
 
 
 
 
 
 
 
85
  st.code(sql_query, language='sql')
86
 
87
  # πŸ§ͺ Execute SQL
 
5
 
6
  # πŸ›  Page setup
7
  st.set_page_config(page_title="🧠 Excel SQL Assistant", layout="centered")
8
+ st.title("πŸ“Š Excel to SQL with Together AI")
9
 
10
  # πŸ” Load API Key securely
11
  TOGETHER_API_KEY = st.secrets.get("TOGETHER_API_KEY", None)
 
52
  - Use SQL compatible with SQLite.
53
  - Table name is 'df'.
54
  - If column names contain spaces or special characters, wrap them in double quotes.
55
+ - DO NOT return unmatched quotes or symbols like *, ', ", ; β€” unless used correctly in SQL syntax.
56
  """
57
 
58
  # πŸ”— Together API request
 
83
  # 🧼 Clean the response
84
  sql_query = response.json()['choices'][0]['message']['content'].strip()
85
  sql_query = sql_query.replace("```sql", "").replace("```", "").strip()
86
+
87
+ # Auto-correct common malformed syntax
88
+ sql_query = sql_query.replace("*\"", "*").replace("\" FROM", " FROM").replace(";*", ";")
89
+ if sql_query.startswith('"SELECT'):
90
+ sql_query = sql_query.replace('"SELECT', 'SELECT')
91
+ if sql_query.startswith('SELECT "'):
92
+ sql_query = sql_query.replace('SELECT "', 'SELECT ')
93
+
94
  st.code(sql_query, language='sql')
95
 
96
  # πŸ§ͺ Execute SQL