This project demonstrates how to use the Vanna AI library to connect to a SQLite database and query for the top 10 albums by sales from the Chinook database. Additionally, a Flask application is created to run the Vanna AI interface.
Before you begin, ensure you have met the following requirements:
- Python 3.6 or later installed on your machine.
- The required Python packages installed (listed in the
requirements.txt
).
-
Clone this repository to your local machine:
git clone https://github.com/your-username/vanna-ai-sql-query.git cd vanna-ai-sql-query
-
Install the required Python packages:
pip install -r requirements.txt
-
Ensure you have the Chinook SQLite database file (
Chinook.sqlite
) in thevannaAi
directory. You can download it from here.
-
Set your Vanna API key by replacing
your-email@example.com
with your email address:vn = VannaDefault(model='chinook', api_key=vanna.get_api_key('your-email@example.com'))
-
Ensure the path to your SQLite database is correct in the
connect_to_sqlite
method:vn.connect_to_sqlite('vannaAi/Chinook.sqlite') # Adjust the path if necessary
-
Run the application:
python app.py
This will start a Flask server running the Vanna AI interface.
-
Access the application in your web browser at
http://127.0.0.1:5000
.
Here is the main code used in the application:
import vanna
from vanna.remote import VannaDefault
from vanna.flask import VannaFlaskApp
# Initialize VannaDefault with the specified model and API key
vn = VannaDefault(model='chinook', api_key=vanna.get_api_key('pmadhan006@gmail.com'))
# Connect to the SQLite database
vn.connect_to_sqlite('vannaAi/Chinook.sqlite') # Path to your SQLite database
# Ask a query to Vanna
vn.ask("What are the top 10 albums by sales?")
# Create and run the Flask app
VannaFlaskApp(vn).run()