Spaces:
Running
Running
Binayak Panigrahi commited on
Commit ·
65a9ef2
1
Parent(s): 64f49b7
Add application file
Browse files
app.py
CHANGED
|
@@ -265,7 +265,7 @@ def execute_sql(sql: str) -> dict:
|
|
| 265 |
# Save results to file with timestamp
|
| 266 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 267 |
filename = OUTPUT_DIR / f"sql_result_{timestamp}.json"
|
| 268 |
-
|
| 269 |
output_data = {
|
| 270 |
"timestamp": datetime.now().isoformat(),
|
| 271 |
"sql_query": sql,
|
|
@@ -273,14 +273,14 @@ def execute_sql(sql: str) -> dict:
|
|
| 273 |
"row_count": result.get("row_count", 0),
|
| 274 |
"execution_status": "success" if result.get("success") else "failed"
|
| 275 |
}
|
| 276 |
-
|
| 277 |
try:
|
| 278 |
with open(filename, "w", encoding="utf-8") as f:
|
| 279 |
json.dump(output_data, f, ensure_ascii=False, indent=2)
|
| 280 |
print(f"✓ Results saved to: {filename}")
|
| 281 |
except Exception as e:
|
| 282 |
print(f"⚠️ Failed to save results to file: {str(e)}")
|
| 283 |
-
|
| 284 |
return result
|
| 285 |
|
| 286 |
|
|
@@ -291,10 +291,10 @@ def generate_reply(user_message: str, products: list, conversation_history: list
|
|
| 291 |
|
| 292 |
# Build messages: system + history + current turn
|
| 293 |
messages = [{"role": "system", "content": RESPONSE_SYSTEM_PROMPT}]
|
| 294 |
-
|
| 295 |
# Add conversation history
|
| 296 |
messages.extend(conversation_history)
|
| 297 |
-
|
| 298 |
# Add current user query
|
| 299 |
messages.append({
|
| 300 |
"role": "user",
|
|
@@ -391,7 +391,7 @@ async def get_result(filename: str):
|
|
| 391 |
filepath = OUTPUT_DIR / filename
|
| 392 |
if not filepath.exists() or not filepath.suffix == ".json":
|
| 393 |
raise HTTPException(status_code=404, detail="Result file not found")
|
| 394 |
-
|
| 395 |
try:
|
| 396 |
return FileResponse(filepath, media_type="application/json", filename=filename)
|
| 397 |
except Exception as e:
|
|
|
|
| 265 |
# Save results to file with timestamp
|
| 266 |
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
|
| 267 |
filename = OUTPUT_DIR / f"sql_result_{timestamp}.json"
|
| 268 |
+
|
| 269 |
output_data = {
|
| 270 |
"timestamp": datetime.now().isoformat(),
|
| 271 |
"sql_query": sql,
|
|
|
|
| 273 |
"row_count": result.get("row_count", 0),
|
| 274 |
"execution_status": "success" if result.get("success") else "failed"
|
| 275 |
}
|
| 276 |
+
|
| 277 |
try:
|
| 278 |
with open(filename, "w", encoding="utf-8") as f:
|
| 279 |
json.dump(output_data, f, ensure_ascii=False, indent=2)
|
| 280 |
print(f"✓ Results saved to: {filename}")
|
| 281 |
except Exception as e:
|
| 282 |
print(f"⚠️ Failed to save results to file: {str(e)}")
|
| 283 |
+
|
| 284 |
return result
|
| 285 |
|
| 286 |
|
|
|
|
| 291 |
|
| 292 |
# Build messages: system + history + current turn
|
| 293 |
messages = [{"role": "system", "content": RESPONSE_SYSTEM_PROMPT}]
|
| 294 |
+
|
| 295 |
# Add conversation history
|
| 296 |
messages.extend(conversation_history)
|
| 297 |
+
|
| 298 |
# Add current user query
|
| 299 |
messages.append({
|
| 300 |
"role": "user",
|
|
|
|
| 391 |
filepath = OUTPUT_DIR / filename
|
| 392 |
if not filepath.exists() or not filepath.suffix == ".json":
|
| 393 |
raise HTTPException(status_code=404, detail="Result file not found")
|
| 394 |
+
|
| 395 |
try:
|
| 396 |
return FileResponse(filepath, media_type="application/json", filename=filename)
|
| 397 |
except Exception as e:
|