--- title: QueryMind — Natural Language to SQL emoji: ⚡ colorFrom: green colorTo: blue sdk: docker pinned: false license: mit app_port: 7860 --- # ⚡ QueryMind — Natural Language to SQL Upload any CSV file and ask questions about your data in plain English. QueryMind converts your question into SQL, runs it on your data, and returns the results instantly. ## How it Works 1. **Upload** your CSV file using the sidebar 2. **Ask** a question in plain English (e.g. "Show top 5 rows by sales") 3. **See** the generated SQL and query results in the chat ## Models This repo contains **two versions** of `app.py` to compare performance: | File | Model | Size | Speed | |------|-------|------|-------| | `app_t5.py` | `cssupport/t5-small-awesome-text-to-sql` | ~250MB | Fast (CPU OK) | | `app_sqlcoder.py` | `defog/sqlcoder-7b-2` | ~14GB | Slow on CPU, needs GPU | **To switch models:** rename the desired file to `app.py` before deploying. ## Tech Stack - **Backend:** FastAPI + Python - **Model Inference:** HuggingFace Transformers (PyTorch) - **Database:** SQLite (in-memory per session) - **Frontend:** Vanilla HTML/CSS/JS (no framework) - **Deployment:** Docker on HuggingFace Spaces ## Local Development ```bash git clone https://huggingface.co/spaces// cd # Install dependencies pip install -r requirements.txt # Run locally uvicorn app:app --host 0.0.0.0 --port 7860 --reload ``` Then open `http://localhost:7860` in your browser. ## Deploying to HuggingFace Spaces (via GitHub) 1. Create a new Space on [huggingface.co/spaces](https://huggingface.co/spaces) - SDK: **Docker** - Connect your GitHub repository in Space settings 2. Push this repo to GitHub — HuggingFace will auto-build & deploy. ## File Structure ``` ├── app.py ← Active model (rename from app_t5.py or app_sqlcoder.py) ├── app_t5.py ← T5-small text-to-SQL (CPU friendly) ├── app_sqlcoder.py ← SQLCoder-7B (GPU recommended) ├── static/ │ └── index.html ← Frontend UI ├── requirements.txt ├── Dockerfile └── README.md ``` ## Notes - Sessions are in-memory — data is lost when the Space restarts. - The T5 model is recommended for free CPU Spaces (fast, lightweight). - SQLCoder-7B gives better SQL quality but needs a GPU Space (T4 small or better).