Skip to content

hmyunis/text-to-sql-system

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Text-to-SQL System

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.

UI Screenshot

Prerequisites

  • Python 3.11+
  • pipenv
  • Node.js 18+ (or Bun)
  • Git

Backend setup

cd backend
pipenv install
pipenv shell
python manage.py migrate

Create 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 migrate

Run the backend:

python manage.py runserver

Optional: seed mock data

python manage.py seed_mock_data

Frontend setup

cd frontend
npm install

Ensure frontend/.env.development:

VITE_API_BASE_URL=http://127.0.0.1:8000/api

Run the frontend:

npm run dev

Hugging Face Space setup (Gradio)

This app ships a simple Gradio Space under hf_app/ with app.py and requirements.txt.

  1. Create a new Space
  1. 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
  1. Verify the Space
  • Wait for the build to complete
  • Open the Space URL and try a sample prompt

About

Full-stack app that turns natural language questions into SQL using a T5 model and executes them against a local database.

Topics

Resources

Stars

Watchers

Forks

Contributors