PD03 commited on
Commit
1ea51fb
·
verified ·
1 Parent(s): 8d8bf58

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -42,7 +42,7 @@ class SALTAnalytics:
42
 
43
  # Get schema information
44
  schema_result = self.con.execute("DESCRIBE salt_data").fetchall()
45
- self.schema_info = "\n".join([f"{col[0]}: {col[1]}" for col in schema_result])
46
 
47
  self.data_loaded = True
48
  return f"✅ Successfully loaded {len(df)} records into DuckDB"
@@ -130,12 +130,12 @@ class SALTAnalytics:
130
  temperature=0.1
131
  )
132
 
133
- sql_query = response.choices[0].message.content.strip()
134
 
135
- # Clean SQL query
136
- if sql_query.startswith("```
137
  sql_query = sql_query[6:-3]
138
- elif sql_query.startswith("```"):
139
  sql_query = sql_query[3:-3]
140
 
141
  # Execute query
@@ -155,9 +155,9 @@ class SALTAnalytics:
155
  temperature=0.3
156
  )
157
 
158
- explanation = explanation_response.choices[0].message.content
159
 
160
- return f"**SQL Query:**\n``````\n\n**Results:**\n{result_df.to_string(index=False)}\n\n**Explanation:**\n{explanation}"
161
 
162
  except Exception as e:
163
  return f"Error: {str(e)}"
 
42
 
43
  # Get schema information
44
  schema_result = self.con.execute("DESCRIBE salt_data").fetchall()
45
+ self.schema_info = "\n".join([f"{col}: {col}" for col in schema_result])[1]
46
 
47
  self.data_loaded = True
48
  return f"✅ Successfully loaded {len(df)} records into DuckDB"
 
130
  temperature=0.1
131
  )
132
 
133
+ sql_query = response.choices.message.content.strip()
134
 
135
+ # Clean SQL query - FIXED: Use single quotes to avoid syntax error
136
+ if sql_query.startswith('```sql'):
137
  sql_query = sql_query[6:-3]
138
+ elif sql_query.startswith('```
139
  sql_query = sql_query[3:-3]
140
 
141
  # Execute query
 
155
  temperature=0.3
156
  )
157
 
158
+ explanation = explanation_response.choices.message.content
159
 
160
+ return f"**SQL Query:**\n```sql\n{sql_query}\n```
161
 
162
  except Exception as e:
163
  return f"Error: {str(e)}"