-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
33 lines (22 loc) · 689 Bytes
/
Copy pathapp.py
File metadata and controls
33 lines (22 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
from fastapi import FastAPI
from pydantic import BaseModel
import time
from src.text_to_sql import ask_question
app = FastAPI()
class Query(BaseModel):
question: str
@app.get("/")
def home():
return {"message": "Text-to-SQL API running"}
@app.post("/ask")
def ask(query: Query):
start = time.time() # start timer
sql_query, answer = ask_question(query.question)
execution_time = round(time.time() - start, 3) # stop timer
return {
"question": query.question,
"generated_sql": sql_query,
"result": answer,
"rows_returned": len(answer) if isinstance(answer, list) else 1,
"execution_time_sec": execution_time
}