A conversational interface for interacting with databases using LangChain and Google Generative AI. This project enables users to query databases in natural language through a Streamlit web application.
- Natural Language Processing: Convert user queries to SQL using Google Generative AI
- Multi-Application Support: Multiple implementations including basic and advanced Langchain versions
- Database Integration: Support for PostgreSQL and other SQL databases via SQLAlchemy
- Web Interface: User-friendly Streamlit application
- Environment Configuration: Secure handling of credentials via .env files
- app.py - Basic Streamlit application for database interaction
- app_langC.py - Advanced Langchain implementation with enhanced capabilities
- deploy.py - Deployment utilities and configuration
- test.py - Testing module for functionality validation
- requirements.txt - Python dependencies
- Schema.jpg - Database schema diagram
The project uses the following Python packages:
streamlit- Web application frameworkpandas- Data manipulation and analysissqlalchemy- SQL toolkit and ORMpython-dotenv- Environment variable managementlangchain-google-genai- LangChain integration with Google Generative AIpsycopg2- PostgreSQL database adapter
Install dependencies using:
pip install -r requirements.txt- Clone the repository:
git clone https://github.com/Mo7amed676/-Chat-with-database-using-Langchain.git
cd -Chat-with-database-using-Langchain- Install dependencies:
pip install -r requirements.txt-
Configure environment variables:
- Create a
.envfile in the project root - Add your database connection string
- Add your Google Generative AI API key
- Create a
-
Run the application:
streamlit run app.pyOr for the advanced Langchain version:
streamlit run app_langC.py- Start the Streamlit application
- Enter your natural language query about the database
- The system converts your query to SQL using Google Generative AI
- Results are displayed in the web interface
The system uses a schema-aware approach where:
- Database schema is analyzed and provided to the AI model
- User queries are converted to appropriate SQL statements
- Results are fetched and displayed in an interactive format
See Schema.jpg for the database structure.
Run tests using:
python test.pyUse deploy.py for deployment configuration and utilities.
- LangChain - Framework for building applications with language models
- Google Generative AI - AI-powered query generation
- Streamlit - Web application framework
- SQLAlchemy - Database abstraction layer
- PostgreSQL - Database system
This project is available on GitHub at: https://github.com/Mo7amed676/-Chat-with-database-using-Langchain