--- title: Text to SQL Demo emoji: 🗃️ colorFrom: blue colorTo: purple sdk: gradio sdk_version: 5.10.0 app_file: app.py pinned: false license: mit --- # Text-to-SQL Demo Ask a plain-English question about a sample e-commerce database (customers, products, orders, order_items) and get back real, generated SQL plus the actual query results — retrieval, generation, AST validation, safe execution, and self-healing retries, all live. This demo runs a fine-tuned Qwen2.5-3B model for SQL generation, paired with a full retrieval-and-validation pipeline: hybrid schema retrieval (dense + BM25) narrows down the relevant tables, an AST-level validator enforces read-only, schema-checked queries before anything executes, and a self-healing loop retries automatically if a query fails, feeding the database's own error back to the model. Nothing but a validated `SELECT` ever reaches the database, regardless of what the model generates. ## Required Space secrets Set these under Settings → Repository secrets before running: | Secret | Example | |---|---| | `DB_HOST` | `db.yourproject.supabase.co` | | `DB_PORT` | `5432` | | `DB_NAME` | `postgres` | | `DB_USER` | `postgres` | | `DB_PASSWORD` | *(your database password)* | Point these at a **read-only** role on a database you're comfortable exposing publicly — this demo is configured for a small sample dataset, not production data.