Full-stack demo that turns natural language questions into SQL and executes them against a local database. The backend is Django, the frontend is Vite + React, and the Hugging Face Space hosts the text-to-SQL model UI.
- Python 3.11+
- pipenv
- Node.js 18+ (or Bun)
- Git
cd backend
pipenv install
pipenv shell
python manage.py migrateCreate backend/.env:
DEBUG=True
DATABASE_URL=sqlite:///./text_to_sql_db.sqlite3
SECRET_KEY=your-secret-key
ALLOWED_HOSTS=127.0.0.1,localhost
CORS_ALLOW_ALL_ORIGINS=True
CORS_ALLOWED_ORIGINS=
HF_TOKEN=your-huggingface-token
HF_MODEL_ID=your-username/your-model-id
Initialize the database:
python manage.py migrateRun the backend:
python manage.py runserverOptional: seed mock data
python manage.py seed_mock_datacd frontend
npm installEnsure frontend/.env.development:
VITE_API_BASE_URL=http://127.0.0.1:8000/api
Run the frontend:
npm run devThis app ships a simple Gradio Space under hf_app/ with app.py and requirements.txt.
- Create a new Space
- Go to https://huggingface.co/spaces
- New Space → SDK: Gradio → Python
- Push the Space files
git clone https://huggingface.co/spaces/<your-username>/<your-space-name>
cd <your-space-name>
copy /Y ..\\path\\to\\text-to-sql-system\\hf_app\\app.py app.py
copy /Y ..\\path\\to\\text-to-sql-system\\hf_app\\requirements.txt requirements.txt
git add app.py requirements.txt
git commit -m "Add Gradio app"
git push- Verify the Space
- Wait for the build to complete
- Open the Space URL and try a sample prompt
