A powerful natural language to SQL query tool with visualization capabilities and voice assistant features.
Talk2SQL lets you query databases using plain English. It translates natural language questions into SQL, executes the queries, and displays the results with visualizations. The app includes a voice assistant for hands-free operation and maintains a history of all queries for easy reference.
textsql.mp4
- Python 3.8+
- Node.js and npm
- SQLite database(s) to query
- Clone the repository
git clone https://github.com/KabeerThockchom/Talk2Sql
cd Talk2SQL- Create a virtual environment
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate- Install Python dependencies
pip install -r requirements.txtKey Python dependencies include:
- flask - Web framework
- pandas & numpy - Data processing
- plotly - Data visualization
- sounddevice & soundfile - Audio processing
- openai - Azure OpenAI integration
- groq - text to speech and speech to text capabilities
- python-dotenv - Environment variable management
- Create a .env file
Create a .env file in the root directory with the following variables:
# Azure OpenAI
AZURE_OPENAI_API_KEY=your_azure_openai_api_key
AZURE_ENDPOINT=your_azure_endpoint
AZURE_API_VERSION=2024-02-15-preview
AZURE_DEPLOYMENT=gpt-4o-mini
#Optional Anthropic Usage
ANTHROPIC_API_KEY=your_anthropic_api_key
# Optional: Qdrant vector database (for persistent storage)
QDRANT_URL=your_qdrant_url
QDRANT_API_KEY=your_qdrant_api_key
# Groq API (for voice features)
GROQ_API_KEY=your_groq_api_key
- Navigate to the frontend directory
cd frontend- Install npm dependencies
npm installKey frontend dependencies include:
- React & React DOM - Frontend framework
- Plotly.js - Interactive visualizations
- Axios - HTTP requests
- Tailwind CSS - Styling
- TypeScript - Type safety
- Build the frontend
npm run build- Move the build files to connect with Flask
The build process creates a dist directory. The Flask app is configured to serve these files automatically, so no manual copying is needed.
- Start the backend server
From the project root:
python app.py- Access the application
Open your browser and go to:
https://text2sql.fly.dev
- Type natural language questions in the main input
- The interface displays:
- Generated SQL query with syntax highlighting
- Data results in a tabular format
- Automatic visualizations based on the data
- Summary of the query results
- Thumbs up/down feedback buttons
- Upload or select SQLite databases from the available list
- View schema information automatically extracted from the database
- Upload training examples in JSON format to improve query accuracy
- Monitor vector database status (if using persistent storage)
- Click the microphone icon to activate voice input
- Choose from multiple voice options for responses
- View real-time transcription and results streaming
- Get spoken answers to your questions
- Browse all past queries with timestamps
- View the original questions, SQL queries, and results
- Re-run previous queries with a single click
- Export history in various formats (JSON, CSV, ZIP)
- Filter by success/failure status
- View performance dashboards with:
- Success rate charts and trend analysis
- Average query times and performance metrics
- Error type distribution and analysis
- Query complexity statistics
- Interactive time-series charts of usage patterns
- On the main dashboard, select a database from the list (to have them there put .sqlite files in databases folder) or upload a new SQLite file.
- The system will automatically extract schema information and prepare the database for queries.
- You can also upload training examples to improve query accuracy.
- Type your question in natural language (e.g., "How many teams are in the NBA?")
- View the generated SQL, data results, and visualizations
- Provide feedback (thumbs up/down) to improve future queries saving queries to qdrant
- Click the microphone icon to activate voice input
- Speak your question clearly
- The system will transcribe your question, execute the query, and provide a spoken response
- The voice streaming interface will show results in real-time
- Navigate to the History tab to see past queries
- Use the Metrics page to analyze performance and patterns
- Export query history for further analysis
- View detailed statistics about your query patterns
- Database connection issues: Ensure your SQLite file is valid and not corrupted
- API key errors: Verify all environment variables are correctly set in the .env file
- Voice features not working: Check your microphone permissions and Groq API key
- Frontend build errors: Make sure all npm dependencies are installed correctly
- Missing visualizations: Check that the data returned from queries is suitable for visualization
app.py: Main Flask application with all API endpointsfrontend/: React frontend codesrc/: Source filesApp.tsx: Main application componentcomponents/: UI components like History, Metrics pages
databases/: Directory for SQLite databasestraining_data/: Example queries and responsesaudio_cache/: Temporary storage for voice recordings
- Backend changes go in
app.py - Frontend changes should be made in the
frontend/srcdirectory - After frontend changes, run
npm run buildagain
To use your own SQLite database:
- Place your .sqlite or .db file in the
databases/directory - Connect to it through the UI
- You can create training examples specific to your database by creating a JSON file with examples