text2sql-chatbot / README.md
nilotpaldhar2004's picture
Update README.md
66ed048 verified
metadata
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

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

    • 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).