Transform a dataset into a predictive AI model that recommends the best flight based on the route selected.
Topics covered:
- Using AWS EC2, deploy Docker-based MariaDB Instance
- Aggregate Kaggle-based dataset via Python Pandas
- Load a dataset via Pandas and Jupyter to MariaDB
- Connect MariaDB to MindsDB
- Train two forecasting models within MindsDB
- housing prices
- flight prices
- Use SQL to run predictions in MindsDB Console
- Connect MariaDB with FastAPI, SQLAlchemy, and Pydantic
- Connect FastAPI to NextJS
- Build forms and routes with Next.js and App Router
- Craft UI elements with TailwindCSS and Flowbite
- Build Reusable Airport-select React/Next Client Component
- Connect FastAPI to MindsDB for SQL via Rest API
- Generate Synthetic Data with Gretel.ai
⦿ Profile: cfe.sh/github or github.com/codingforentrepreneurs
⦿ Project: https://github.com/codingforentrepreneurs/ai-travel-agent
⦿ MariaDB: https://mariadb.com/
⦿ MindsDB: https://mindsdb.com/
⦿ Gretel: https://gretel.ai
⦿ OpenAI: https://openai.com/
⦿ AWS EC2: https://aws.amazon.com/ec2/
⦿ MariaDB Docker Image: https://hub.docker.com/_/mariadb
⦿ Docker Engine: https://docs.docker.com/engine/
⦿ Python: https://www.python.org/
⦿ Node.js: https://nodejs.org/en
⦿ FastAPI: https://fastapi.tiangolo.com/
⦿ Next.js: https://nextjs.org/
⦿ Pandas: https://pandas.pydata.org/
⦿ Jupyter Notebooks: https://jupyter.org/
⦿ Pydandtic: https://docs.pydantic.dev/latest/
Each Git branch corresponds to the start and end of a section when it makes sense to do so. For example, section 33 starts at Branch 33-start
and ends with branch 33-end
. These branches exist for your reference where main branch has the latest code.
Enter you EC2 Instance
ssh -i your-private-key.pem ubuntu@<your-ec2-instance-public-ip>
Escalate to Root
sudo su
Install Docker
curl -fsSL https://get.docker.com | sudo sh
python3 -c "import secrets;print(secrets.token_urlsafe(32))"
Ensure the security groups are setup correctly to allow port 3306 access for MariaDB.
SSH into EC2 Instance with your private key and the ubuntu
user:
ssh -i your-private-key.pem ubuntu@<your-ec2-instance-public-ip>
Once complete, install Docker Compose as written above.
On the EC2 instance create the .env
add the following line with your own password:
MARIADB_ROOT_PASSWORD=your-secret-password
Such as:
echo "MARIADB_ROOT_PASSWORD=$(python3 -c 'import secrets;print(secrets.token_urlsafe(32))')" >> .env
Copy the contents of config/compose.yaml file to your EC2 instance to run MariaDB with:
curl https://raw.githubusercontent.com/codingforentrepreneurs/ai-travel-agent/main/config/compose.yaml -o compose.yaml
docker compose -f compose.yaml up -d
Make note of the EC2 instance public IP address so you can re-use it anywhere with the following database connection string:
mariadb://root:your-secret-password@<your-ec2-instance-public-ip>:3306
Link: https://youtu.be/F5ZsLbBqWLU
- 00:00:00 Welcome
- 00:03:34 Overview
- 00:07:59 References and Requirements
- 00:11:05 Provision EC2 Instance
- 00:16:58 Connect to EC2 Instance via SSH
- 00:21:11 Install Docker on EC2 Instance
- 00:23:35 Provision MariaDB wih Docker Compose
- 00:34:04 Connect to EC2-Docker-based MariaDB Instance Locally
- 00:40:55 Configure Virtual Environment and Jupyter
- 00:47:54 Loading Dotenv with Python Decouple and Jupyter
- 00:56:43 Connect to MariaDB via SQLAlchemy
- 01:03:52 Load a Kaggle Dataset to MariaDB
- 01:15:47 Create MariaDB User for MindsDB
- 01:23:13 Integrate MariaDB & MindsDB
- 01:31:31 Creating a Forecasting Model with MindsDB
- 01:40:39 Predicting Future Values with MindsDB
- 01:46:37 Load Flight Prices Dataset to MariaDB
- 01:53:28 Prepare Flight Data for Predictions
- 02:03:25 MindsDB Predictor for Flight Price Data
- 02:08:09 More Data Features for Better Predictions
- 02:17:21 SQLAlchemy Model from Database Table
- 02:29:26 Pydantic Schema for SQLAlchemy Model
- 02:34:05 SQLAlchemy Lookup Functions for Model Data
- 02:39:04 MindsDB SQL Queries via Rest API and Python Part 1
- 02:47:25 MindsDB SQL Queries via Rest API and Python Part 2
- 02:59:34 FastAPI Backend App
- 03:07:32 Why the FastAPI Backend
- 03:10:16 Create the Next.js Frontend
- 03:16:56 FastAPI CORS for Next.js
- 03:26:26 Integrate MariaDB to FastAPI
- 03:31:02 Listing Database Data via API View
- 03:34:32 Detail View and Schema with FastAPI and Pydantic
- 03:39:32 Listing API Data with Next.js
- 03:44:37 Styling a Link with Tailwind
- 03:46:44 Dynamic URL Route Detail Page in Next.js
- 03:53:03 Next.js Layout & CSS Class
- 03:58:17 Reusable Next.js Link Component
- 04:03:09 Backend API Client in Next.js
- 04:08:38 Handling request errors with swr and Next.js
- 04:15:05 Next.js Form sending POST Requests to FastAPI
- 04:23:43 MindsDB with FastAPI and Next.js
- 04:30:23 Generate and Load Airport Data in MariaDB and FastAPI
- 04:39:36 Airport Dropdown Selector
- 04:45:32 Handling POST Data with FastAPI and Pydantic
- 04:50:51 Prevent Duplicate Airports in Nextjs
- 04:57:56 Improve Flight Price Prediction UI
- 05:06:10 TailwindCSS Global Styles
- 05:14:16 Form Styling with Flowbite References
- 05:21:38 Prediction Results UI Table
- 05:35:36 Integrate MindsDB with OpenAI to Make Flight Recommendations
- 05:45:39 OpenAI Recommendation Response in UI
- 05:56:28 Unique Request ID for Forecasts
- 05:59:24 Recommendation Display
- 06:05:47 Purchase Links
- 06:10:08 Starting to Handle New Data
- 06:11:51 Export Data and Train a Gretel Model
- 06:16:49 Load Gretel Data to MariaDB via Pandas
- 06:31:52 Train MindsDB Forecast Model via Jupyter
- 06:43:07 Final Clean Up
- 06:45:04 Thank you and your next challenge