| --- |
| title: QueryMind |
| emoji: π€ |
| colorFrom: blue |
| colorTo: green |
| sdk: docker |
| pinned: false |
| --- |
| |
| # β‘ 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/<your-username>/<your-space-name> |
| cd <your-space-name> |
| |
| # 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). |
|
|