Spaces:
Sleeping
Sleeping
Remove orphaned except block - revert to working state
Browse files
main.py
CHANGED
|
@@ -166,42 +166,36 @@ async def process_query(request: QueryRequest):
|
|
| 166 |
error="GROQ_API_KEY not configured. Please add it in HF Spaces Settings > Variables.",
|
| 167 |
session_id=session_id
|
| 168 |
)
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
if error:
|
| 174 |
-
return QueryResponse(
|
| 175 |
-
success=False,
|
| 176 |
-
error=f"Failed to generate SQL: {error}",
|
| 177 |
-
session_id=session_id
|
| 178 |
-
)
|
| 179 |
-
|
| 180 |
-
# Generate explanation
|
| 181 |
-
explanation = explain_sql_with_groq(sql, request.question)
|
| 182 |
-
|
| 183 |
-
# For demo: return mock results
|
| 184 |
-
# In production, you'd execute the SQL against a real database
|
| 185 |
-
results = [
|
| 186 |
-
{"info": "SQL generated successfully! In production, this would execute against your database."},
|
| 187 |
-
{"note": "Connect your database to see real query results."}
|
| 188 |
-
]
|
| 189 |
-
|
| 190 |
return QueryResponse(
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
results_explanation=f"Generated SQL query for: '{request.question}'. Ready to execute against your database.",
|
| 196 |
-
session_id=session_id
|
| 197 |
-
)
|
| 198 |
|
| 199 |
-
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
import uvicorn
|
| 207 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 166 |
error="GROQ_API_KEY not configured. Please add it in HF Spaces Settings > Variables.",
|
| 167 |
session_id=session_id
|
| 168 |
)
|
| 169 |
+
|
| 170 |
+
sql, error = generate_sql_with_groq(request.question)
|
| 171 |
+
|
| 172 |
+
if error:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 173 |
return QueryResponse(
|
| 174 |
+
success=False,
|
| 175 |
+
error=f"Failed to generate SQL: {error}",
|
| 176 |
+
session_id=session_id
|
| 177 |
+
)
|
|
|
|
|
|
|
|
|
|
| 178 |
|
| 179 |
+
# Generate explanation
|
| 180 |
+
explanation = explain_sql_with_groq(sql, request.question)
|
| 181 |
+
|
| 182 |
+
# For demo: return mock results
|
| 183 |
+
# In production, you'd execute the SQL against a real database
|
| 184 |
+
results = [
|
| 185 |
+
{"info": "SQL generated successfully! In production, this would execute against your database."},
|
| 186 |
+
{"note": "Connect your database to see real query results."}
|
| 187 |
+
]
|
| 188 |
+
|
| 189 |
+
return QueryResponse(
|
| 190 |
+
success=True,
|
| 191 |
+
sql=sql,
|
| 192 |
+
results=results,
|
| 193 |
+
sql_explanation=explanation,
|
| 194 |
+
results_explanation=f"Generated SQL query for: '{request.question}'. Ready to execute against your database.",
|
| 195 |
+
session_id=session_id
|
| 196 |
+
)
|
| 197 |
+
|
| 198 |
+
|
| 199 |
+
if __name__ == "__main__":
|
| 200 |
import uvicorn
|
| 201 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|