File size: 2,349 Bytes
70293d1
66ed048
c4e54e9
 
 
66ed048
70293d1
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
---
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).