Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- 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
|
| 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
|