Skip to content

hamza-amin-4365/Chat-with-sql

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CHAT with SQLite Streamlit App with Foreign Keys

Table of Content

Overview

This project is a Streamlit application that allows users to upload multiple CSV files and create a SQLite database with tables corresponding to each CSV file. The application also handles foreign key relationships between the tables based on common integer columns found in the CSV files and it allows you to query your database in natural language.

Motivation

The motivation behind this project was to provide a user-friendly way to convert CSV data into a SQLite database, while also automatically handling foreign key relationships between the tables. This can be useful for data analysis, querying, and integration with other applications that work with SQLite databases.

Technical Aspect

The application uses the following technologies and libraries:

  • Streamlit: A Python library for building interactive web applications.
  • Pandas: A popular data manipulation and analysis library for Python.
  • SQLite3: A Python library for working with SQLite databases.
  • LangChain: A framework for building applications with large language models (LLMs).
  • HuggingFace Endpoint: An LLM provided by HuggingFace for natural language processing tasks.

The application follows these steps:

  1. Allow the user to upload multiple CSV files through the Streamlit interface.
  2. Read the CSV files into Pandas DataFrames.
  3. Analyze the DataFrames to find potential foreign key relationships based on common integer columns.
  4. Create a SQLite database and tables corresponding to each CSV file, with foreign key constraints based on the detected relationships.
  5. Provide an interface for the user to ask questions about the data.
  6. Use the LangChain framework and the HuggingFace LLM to generate SQL queries based on the user's questions.
  7. Execute the generated SQL queries on the SQLite database and display the results to the user.

Installation And Run

  1. Clone the repository or download the source code.
  2. Install the required packages by running the following command:
pip install -r requirements.txt
  1. Set up your HuggingFace API token by creating a .env file in the project directory and adding the following line:
huggingfacehub_api_token=YOUR_API_TOKEN
  1. Run the Streamlit app with the following command:
streamlit run app.py

Directory Tree

│   app.py
│   README.md
│   requirements.txt
└───data
        # CSV files will be stored here

To Do

Implement support for handling more complex data types in CSV files. Improve the foreign key detection algorithm for better accuracy. Add support for creating indexes on columns.

Bug / Feature Request

If you find a bug or have a feature request, please open an issue here.

Technologies Used

Credits

HuggingFace LangChain

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published