Spaces:
Sleeping
Sleeping
Update README.md
Browse files
README.md
CHANGED
|
@@ -1 +1,82 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: QueryMind β Natural Language to SQL
|
| 3 |
+
emoji: β‘
|
| 4 |
+
colorFrom: green
|
| 5 |
+
colorTo: teal
|
| 6 |
+
sdk: docker
|
| 7 |
+
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
+
app_port: 7860
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
# β‘ QueryMind β Natural Language to SQL
|
| 13 |
+
|
| 14 |
+
Upload any CSV file and ask questions about your data in plain English.
|
| 15 |
+
QueryMind converts your question into SQL, runs it on your data, and returns the results instantly.
|
| 16 |
+
|
| 17 |
+
## How it Works
|
| 18 |
+
|
| 19 |
+
1. **Upload** your CSV file using the sidebar
|
| 20 |
+
2. **Ask** a question in plain English (e.g. "Show top 5 rows by sales")
|
| 21 |
+
3. **See** the generated SQL and query results in the chat
|
| 22 |
+
|
| 23 |
+
## Models
|
| 24 |
+
|
| 25 |
+
This repo contains **two versions** of `app.py` to compare performance:
|
| 26 |
+
|
| 27 |
+
| File | Model | Size | Speed |
|
| 28 |
+
|------|-------|------|-------|
|
| 29 |
+
| `app_t5.py` | `cssupport/t5-small-awesome-text-to-sql` | ~250MB | Fast (CPU OK) |
|
| 30 |
+
| `app_sqlcoder.py` | `defog/sqlcoder-7b-2` | ~14GB | Slow on CPU, needs GPU |
|
| 31 |
+
|
| 32 |
+
**To switch models:** rename the desired file to `app.py` before deploying.
|
| 33 |
+
|
| 34 |
+
## Tech Stack
|
| 35 |
+
|
| 36 |
+
- **Backend:** FastAPI + Python
|
| 37 |
+
- **Model Inference:** HuggingFace Transformers (PyTorch)
|
| 38 |
+
- **Database:** SQLite (in-memory per session)
|
| 39 |
+
- **Frontend:** Vanilla HTML/CSS/JS (no framework)
|
| 40 |
+
- **Deployment:** Docker on HuggingFace Spaces
|
| 41 |
+
|
| 42 |
+
## Local Development
|
| 43 |
+
|
| 44 |
+
```bash
|
| 45 |
+
git clone https://huggingface.co/spaces/<your-username>/<your-space-name>
|
| 46 |
+
cd <your-space-name>
|
| 47 |
+
|
| 48 |
+
# Install dependencies
|
| 49 |
+
pip install -r requirements.txt
|
| 50 |
+
|
| 51 |
+
# Run locally
|
| 52 |
+
uvicorn app:app --host 0.0.0.0 --port 7860 --reload
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
Then open `http://localhost:7860` in your browser.
|
| 56 |
+
|
| 57 |
+
## Deploying to HuggingFace Spaces (via GitHub)
|
| 58 |
+
|
| 59 |
+
1. Create a new Space on [huggingface.co/spaces](https://huggingface.co/spaces)
|
| 60 |
+
- SDK: **Docker**
|
| 61 |
+
- Connect your GitHub repository in Space settings
|
| 62 |
+
|
| 63 |
+
2. Push this repo to GitHub β HuggingFace will auto-build & deploy.
|
| 64 |
+
|
| 65 |
+
## File Structure
|
| 66 |
+
|
| 67 |
+
```
|
| 68 |
+
βββ app.py β Active model (rename from app_t5.py or app_sqlcoder.py)
|
| 69 |
+
βββ app_t5.py β T5-small text-to-SQL (CPU friendly)
|
| 70 |
+
βββ app_sqlcoder.py β SQLCoder-7B (GPU recommended)
|
| 71 |
+
βββ static/
|
| 72 |
+
β βββ index.html β Frontend UI
|
| 73 |
+
βββ requirements.txt
|
| 74 |
+
βββ Dockerfile
|
| 75 |
+
βββ README.md
|
| 76 |
+
```
|
| 77 |
+
|
| 78 |
+
## Notes
|
| 79 |
+
|
| 80 |
+
- Sessions are in-memory β data is lost when the Space restarts.
|
| 81 |
+
- The T5 model is recommended for free CPU Spaces (fast, lightweight).
|
| 82 |
+
- SQLCoder-7B gives better SQL quality but needs a GPU Space (T4 small or better).
|