A professional AI-powered application that converts natural language questions into SQL queries and executes them against your database. Built with LangGraph, Streamlit, and OpenAI's GPT models.
π Try the Live Demo - Transform your questions into SQL queries instantly!
Note: You'll need your own OpenAI API key to use the application. This ensures data privacy and cost control.
- Natural Language to SQL: Convert questions into optimized SQL queries
- Multi-Database Support: SQLite, PostgreSQL, MySQL with schema selection
- AI-Powered Analysis: GPT-4o and GPT-4o-mini model selection
- Memory & Context: Conversational interface with chat history
- Real-time Execution: Execute queries and display results instantly
- Clean UI: Professional Streamlit interface with sidebar controls
- API Key Required: Users provide their own OpenAI key for privacy and cost control
- Database Upload: Upload SQLite files or connect via connection strings
- SQL Display: View generated SQL queries alongside natural language responses
- Chat History: Persistent conversation with visual icons
- LangGraph Workflow: Structured agent with tool integration
- Database Agnostic Tools: SQLAlchemy-based tools work across all databases
- Memory Management: Built-in conversation memory with checkpointing
- Error Handling: Comprehensive error management and user feedback
- Python 3.8 or higher
- OpenAI API key (optional - app provides fallback)
-
Clone the repository
git clone https://github.com/Joe-ElM/Project-Text2SQL-.git cd Project-Text2SQL- -
Install dependencies
pip install -r requirements.txt
-
Configure environment
cp .env.example .env # Edit .env with your API keys (optional) -
Run the application
streamlit run app/app.py
OPENAI_API_KEY=your_openai_api_key_here
DB_TYPE=sqlite
DB_DSN=sqlite:///data/sakila_master.db- GPT-4o: Best performance, higher cost
- GPT-4o-mini: Balanced performance and cost
- SQLite: File upload or local files
- PostgreSQL: Connection string with optional schema selection
- MySQL: Connection string support
- Open the application in your browser
- Select your preferred AI model in the sidebar
- Choose database type and upload/connect your database
- Ask natural language questions about your data
"Show me all customers from California"
"What are the top 5 best-selling products?"
"Find customers who haven't made a purchase in the last 30 days"
"Show revenue by month for the last year"
SQLite (File Upload)
- Use the file uploader in the sidebar
- Supports .db and .sqlite files
PostgreSQL
postgresql://username:password@localhost:5432/database_name
PostgreSQL with Schema
Connection: postgresql://username:password@localhost:5432/database_name
Schema: public
MySQL
mysql://username:password@localhost:3306/database_name
βββ app/
β βββ app.py # Streamlit UI application
βββ src/
β βββ text2sql/
β βββ agents/
β β βββ text2sql_agent.py # LangGraph agent implementation
β βββ database/
β β βββ factory.py # Database engine factory
β β βββ tools.py # Database interaction tools
β βββ core/
β β βββ query_engine.py # Core query processing (placeholder)
β βββ utils/
β β βββ helpers.py # Utility functions
β βββ config.py # Configuration management
βββ data/
β βββ sakila_master.db # Sample SQLite database
βββ tests/
β βββ test_smoke.py # Basic tests
βββ requirements.txt # Python dependencies
βββ .env.example # Environment template
βββ .gitignore # Git ignore rules
βββ README.md # This file
βββ CLAUDE.md # Development notes
LangGraph Agent (src/text2sql/agents/text2sql_agent.py)
- Workflow-based SQL generation
- Tool integration for database operations
- Memory management with checkpointing
Database Tools (src/text2sql/database/tools.py)
list_tables_tool: Discover available tablesget_table_schema_tool: Inspect table structuresexecute_sql_tool: Execute generated queries
Streamlit UI (app/app.py)
- Clean, professional interface
- Sidebar controls for configuration
- Chat-style conversation history
- Push to GitHub repository
- Connect repository to Streamlit Cloud
- Set environment variables in Streamlit Cloud dashboard
- Deploy automatically
- Connect GitHub repository
- Configure build command:
pip install -r requirements.txt - Configure start command:
streamlit run app/app.py --server.port=$PORT - Set environment variables
- Deploy
FROM python:3.9-slim
WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt
COPY . .
EXPOSE 8501
CMD ["streamlit", "run", "app/app.py", "--server.port=8501"]- Data Privacy: No data stored permanently, only session-based memory
- API Key Security: Users can provide their own OpenAI keys
- Database Security: Supports read-only operations by default
- Local Deployment: Can be deployed on-premises for sensitive data
- Consider self-hosted LLM models for complete data privacy
- Implement user authentication for multi-user environments
- Add audit logging for compliance requirements
- Use Azure OpenAI for enterprise-grade security
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
- LangChain/LangGraph: For the agent framework
- OpenAI: For GPT models
- Streamlit: For the web interface
- SQLAlchemy: For database abstraction