https://github.com/lexiestleszek/text2sql_csv
Simple script using local LLM to ask CSV/XLS files with natural language.
https://github.com/lexiestleszek/text2sql_csv
Last synced: 3 months ago
JSON representation
Simple script using local LLM to ask CSV/XLS files with natural language.
- Host: GitHub
- URL: https://github.com/lexiestleszek/text2sql_csv
- Owner: LexiestLeszek
- License: mit
- Created: 2024-03-10T10:12:03.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-03-12T19:33:25.000Z (about 1 year ago)
- Last Synced: 2025-01-13T21:44:11.531Z (5 months ago)
- Language: Python
- Size: 20.5 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Text2SQL_CSV
## Introduction
The Text2SQL CSV project is a Python-based application designed to facilitate the conversion of natural language queries into SQL queries and execute these queries on a SQLite database. This project leverages the power of Large Language Models (LLMs) to interpret user input and generate SQL queries, enabling users to interact with their data in a more natural and intuitive manner.
## Installation
Clone the repo:
```bash
git clone https://github.com/LexiestLeszek/text2sql_CSV.git
```Then install the necessary Python libraries, run the following command:
```bash
pip install pandas sqlite3 llmware
```## Usage
1. **Upload CSV to SQLite**: Use the `upload_csv_to_sqlite` function to upload a CSV file to a SQLite database. This function reads the CSV file, creates a table in the SQLite database with the same name as the CSV file, and inserts the data from the CSV file into the table.
```python
db_schema = upload_csv_to_sqlite('./StockRatings.csv', './StockRatings.db')
```2. **Text to SQL**: Use the `text2sql` function to convert a natural language query into an SQL query. This function uses the LLM to interpret the query and generate an SQL query.
```python
query_sql = text2sql('Who has the best overall rating?', db_schema)
```3. **Query Database**: Use the `query_db` function to execute the generated SQL query on the SQLite database and retrieve the results.
```python
answer = query_db(query_sql, './StockRatings.db')
print(answer)
```
Note: First run will download LLMWare models and it will take some time.## Contributing
Contributions are welcome! For major changes, please open an issue first to discuss what you would like to change. Please make sure to update tests as appropriate.
## License
This project is licensed under the MIT License. See the `LICENSE` file for details.