Text2SQL is an interactive Streamlit application that allows users to query CSV data using natural language. The application converts user questions into SQL queries, executes them against a SQLite database, and displays the results.
- CSV file upload and automatic SQLite database creation
- Natural language to SQL query conversion using the Ollama LLM
- Question caching for improved performance on similar queries
- Automatic query execution and result display
- Support for various data types, including dates
- Interactive Streamlit interface
- Python 3.7+
- Streamlit
- Pandas
- SQLite3
- Langchain
- Ollama
- Scikit-learn
-
Clone the repository:
git clone https://github.com/devbm7/text2sql.git cd text2sql
-
Install the required Python packages:
pip install streamlit pandas langchain-community requests scikit-learn
-
Install Ollama following the instructions at Ollama's official website.
-
Ensure Ollama is installed and the llama3.1:8b model is available.
-
Start the Ollama server with the llama3.1:8b model:
ollama run llama3.1:8b
-
Run the Streamlit application:
streamlit run main.py
-
Open your web browser and navigate to the URL displayed in the terminal (usually
http://localhost:8501
). -
Use the application:
- Upload a CSV file using the file uploader.
- Enter your question about the data in natural language.
- View the generated SQL query and the query results.
- The user uploads a CSV file, which is converted into a SQLite database.
- The user enters a question in natural language.
- The application checks if a similar question has been asked before and uses the cached query if available.
- If no similar question is found, the application uses the Ollama LLM to generate a SQL query from the natural language question.
- The generated SQL query is executed against the SQLite database.
- The results are displayed in a tabular format.
- The accuracy of the SQL query generation depends on the capabilities of the Ollama LLM model.
- Large CSV files may take some time to process and load into the SQLite database.
- The application currently supports a single table per session.
Contributions to improve Text2SQL are welcome. Please feel free to submit pull requests or open issues to suggest improvements or report bugs.