minimew commited on
Commit
5d574b8
·
verified ·
1 Parent(s): 1525874

Upload src/app/api.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. src/app/api.py +20 -9
src/app/api.py CHANGED
@@ -53,16 +53,14 @@ DEFAULT_DB_PATH = str(
53
  )
54
 
55
  EXAMPLE_QUESTIONS = [
56
- "How many orders were placed in 2024?",
57
- "What is the total revenue from completed orders?",
58
- "List the top 5 best-selling products by total quantity sold.",
59
  "Which city has the most customers?",
60
- "Show the number of orders per store, ordered from highest to lowest.",
61
- "What is the average order value (sum of quantity times unit_price) for completed orders?",
62
- "Which product category generates the highest total revenue?",
63
- "List all customers from Hanoi who placed at least one order.",
64
- "Show monthly order counts for 2024.",
65
- "What products have stock below 10 units at any store?",
66
  ]
67
 
68
  def _default_active():
@@ -214,6 +212,19 @@ def upload(file: UploadFile):
214
  )
215
 
216
 
 
 
 
 
 
 
 
 
 
 
 
 
 
217
  @app.post("/api/reset")
218
  def reset():
219
  """Quay lai database mac dinh (retail_store). Giu nguyen model_id nguoi
 
53
  )
54
 
55
  EXAMPLE_QUESTIONS = [
56
+ "How many orders are there in total?",
57
+ "Show the number of orders by status.",
 
58
  "Which city has the most customers?",
59
+ "What are the 5 most expensive products?",
60
+ "How many customers are from hanoi?",
61
+ "How many completed orders are there?",
62
+ "What is the average product price?",
63
+ "List all stores in the north region.",
 
64
  ]
65
 
66
  def _default_active():
 
212
  )
213
 
214
 
215
+ @app.get("/api/preview")
216
+ def preview_table(table: str = ""):
217
+ """Return rows from a specific table (or first available) for the active database."""
218
+ db_path = _active["db_path"]
219
+ table_names = csv_loader.get_table_names(db_path)
220
+ if not table_names:
221
+ return {"table_names": [], "active_table": "", "columns": [], "rows": [], "row_count": 0, "truncated": False}
222
+ if table not in table_names:
223
+ table = table_names[0]
224
+ preview = csv_loader.get_preview_for_table(db_path, table)
225
+ return {"table_names": table_names, "active_table": table, **preview}
226
+
227
+
228
  @app.post("/api/reset")
229
  def reset():
230
  """Quay lai database mac dinh (retail_store). Giu nguyen model_id nguoi