nl2sql-bench / server /app.py
ritvik360's picture
Upload folder using huggingface_hub
a069777 verified
"""
nl2sql-bench/server/app.py
============================
FastAPI application entry point for the NL2SQL-Bench OpenEnv server.
create_fastapi_app() auto-creates all required OpenEnv endpoints:
POST /reset β€” start a new episode
POST /step β€” submit an action
GET /state β€” retrieve episode state
GET /health β€” health check
GET /web β€” interactive web UI (if ENABLE_WEB_INTERFACE=true)
GET /docs β€” Swagger UI
"""
import sys
from pathlib import Path
from openenv.core.env_server import create_fastapi_app
from environment import NL2SQLEnvironment
import sqlite3 # <-- Add this import
# Ensure models can be imported from the parent directory
_HERE = Path(__file__).parent
sys.path.insert(0, str(_HERE.parent))
from models import NL2SQLAction, NL2SQLObservation
# Pass the explicitly required action and observation classes
app = create_fastapi_app(
NL2SQLEnvironment,
action_cls=NL2SQLAction,
observation_cls=NL2SQLObservation
)
@app.on_event("startup")
async def startup_event():
from db.seed import seed_database
conn = sqlite3.connect('ecommerce.db')
# NEW FIX: Read and execute the schema DDL first!
with open('db/schema.sql', 'r') as f:
schema_sql = f.read()
conn.executescript(schema_sql)
# Now that tables exist, insert the data
seed_database(conn)
conn.commit()
conn.close()
def main():
import uvicorn
uvicorn.run(app, host="0.0.0.0", port=7860)
if __name__ == '__main__':
main()