CoolFace
Apppublic

deepakvish001/sql-repair-env-new

sourceHugging Faceupdated 5mo agoView on Hugging Face
0likes
App README

SQL Query Repair Lab ๐Ÿ”ง

An OpenEnv-compliant reinforcement learning environment where AI agents learn to identify and fix broken SQL queries โ€” with a full interactive dashboard for human users too.


๐Ÿš€ Features (8 Advanced)

1. ๐ŸŽจ Interactive SQL Editor

  • โ€”macOS-style code editor with syntax-aware textarea
  • โ€”Load original broken query, clear, character/line count
  • โ€”Keyboard shortcut: Ctrl+Enter to submit

2. ๐Ÿ“‹ Task Dashboard & Sidebar

  • โ€”3 tasks (Easy/Medium/Hard) with color-coded difficulty badges
  • โ€”Real-time progress bars showing best scores per task
  • โ€”One-click task switching with visual active state

3. ๐Ÿš€ Real-time Query Grading

  • โ€”Submit fixes and get instant scoring with partial credit
  • โ€”Success / Partial / Fail states with animated result panels
  • โ€”Progressive hints revealed after failed attempts

4. ๐Ÿ“Š Score Breakdown Visualization

  • โ€”Per-criterion partial scores (syntax, columns, row count, ordering, etc.)
  • โ€”Color-coded +/- indicators for each grading criterion
  • โ€”Clear feedback on exactly what's right and what needs fixing

5. ๐Ÿ“‹ Step History Timeline

  • โ€”Visual timeline with green/yellow/red dot indicators
  • โ€”Score, feedback message, and submitted query for each step
  • โ€”SVG score progression chart across attempts

6. ๐Ÿ—ƒ๏ธ Database Schema Explorer

  • โ€”Interactive table view with columns, types, constraints, notes
  • โ€”Sample data preview for each table
  • โ€”Parsed directly from DDL schema definitions

7. ๐Ÿ” Diff Viewer

  • โ€”Side-by-side comparison: broken query vs. your fix
  • โ€”Unified diff view with color-coded additions/removals
  • โ€”Toggleable live diff in workspace

8. โ–ถ๏ธ Query Runner & Analytics

  • โ€”Execute any SELECT query against the database (no scoring)
  • โ€”Validate SQL syntax without submitting
  • โ€”Performance analytics: average score, tasks completed, best score
  • โ€”Session timeline tracking all attempts

HTTP API

MethodEndpointDescription
GET/Frontend dashboard
POST/resetStart episode: {"task_id": "..."}
POST/stepSubmit fix: {"fixed_query": "..."}
GET/stateFull internal state
GET/tasksList all tasks
GET/healthLiveness probe
GET/schema/{id}Parsed schema for a task
POST/validateValidate SQL syntax: {"query": "..."}
POST/executeExecute query (read-only): {"query": "..."}
POST/hintGet hint: {"task_id": "...", "step": 0}
GET/analyticsSession analytics summary
POST/analytics/resetReset analytics data

Setup & Usage

Local (Python)

bash
pip install -r requirements.txt

# Start the server
uvicorn main:app --host 0.0.0.0 --port 7860

# Open browser to http://localhost:7860

Docker

bash
docker build -t sql-repair-lab .
docker run -p 7860:7860 sql-repair-lab

# Open browser to http://localhost:7860

Run Baseline Agent

bash
export HF_TOKEN=your_hf_token
export MODEL_NAME=meta-llama/Llama-3.3-70B-Instruct
export API_BASE_URL=https://router.huggingface.co/v1
python inference.py

Project Structure

sql-repair-lab/
โ”œโ”€โ”€ Dockerfile
โ”œโ”€โ”€ README.md
โ”œโ”€โ”€ openenv.yaml
โ”œโ”€โ”€ requirements.txt
โ”œโ”€โ”€ pyproject.toml
โ”œโ”€โ”€ app.py               โ† HF Spaces entry point
โ”œโ”€โ”€ main.py              โ† FastAPI server (enhanced with 6 new endpoints)
โ”œโ”€โ”€ inference.py          โ† Baseline RL agent
โ”œโ”€โ”€ static/
โ”‚   โ””โ”€โ”€ index.html        โ† Full frontend dashboard (single-file, no build step)
โ”œโ”€โ”€ server/
โ”‚   โ”œโ”€โ”€ __init__.py
โ”‚   โ””โ”€โ”€ app.py
โ””โ”€โ”€ env/
    โ”œโ”€โ”€ __init__.py
    โ”œโ”€โ”€ models.py          โ† Pydantic models
    โ”œโ”€โ”€ database.py        โ† SQLite setup + seed data
    โ”œโ”€โ”€ tasks.py           โ† Task definitions + graders
    โ””โ”€โ”€ environment.py     โ† Core environment (reset/step/state)

Tasks

#TaskDifficultyBugsExpected Baseline
1Fix Syntax ErrorsEasy1~0.85
2Fix Logic ErrorsMedium2~0.55
3Fix Complex QueryHard3~0.40

License

MIT