A machine learning web application that predicts flight delays with two frontend options: FastAPI with HTML templates and Streamlit.
Flight_Delay_Predictor/
├── main.py # FastAPI application with HTML frontend
├── api.py # Streamlit application
├── model/ # Trained ML models
│ ├── flight_delay_model.pkl
│ └── model_columns.pkl
├── templates/ # HTML templates for FastAPI
│ └── index.html # FastAPI frontend interface
├── venv/ # Virtual environment
├── requirements.txt # Python dependencies
├── start_fastapi.bat # FastAPI startup script
├── start_streamlit.bat # Streamlit startup script
└── test_api.py # Test script
- Virtual environment is already created and activated
- Dependencies are already installed
-
Start the FastAPI server:
start_fastapi.bat
Or manually:
venv\Scripts\activate uvicorn main:app --reload
-
Access the application:
- Web Interface: http://localhost:8000
- API Documentation: http://localhost:8000/docs
- Alternative API Docs: http://localhost:8000/redoc
-
Start the Streamlit app:
start_streamlit.bat
Or manually:
venv\Scripts\activate streamlit run api.py
-
Access the application:
- Streamlit Interface: http://localhost:8501
Serves the HTML frontend interface for making predictions.
Makes a flight delay prediction.
Request Body:
{
"month": 1,
"day_of_month": 15,
"day_of_week": 3,
"op_unique_carrier": "WN",
"origin": "LAX",
"dest": "SFO",
"crs_dep_time": 1400,
"dep_delay": -5.0,
"distance": 337.0
}Response:
{
"prediction": 0,
"prediction_label": "On Time",
"confidence_on_time": "0.8523",
"confidence_delayed": "0.1477"
}- Web Interface: Clean HTML form with real-time predictions
- REST API: JSON-based API for programmatic access
- Interactive Documentation: Auto-generated API docs with Swagger UI
- Responsive Design: Works on desktop and mobile devices
- Interactive UI: Python-based web interface with sliders and inputs
- Real-time Feedback: Instant predictions with confidence metrics
- Visual Elements: Progress bars and colored result displays
- Form Validation: Built-in input validation and error handling
The model uses the following features:
- Month (1-12)
- Day of Month (1-31)
- Day of Week (1-7)
- Carrier Code (e.g., WN, DL, AA)
- Origin Airport (e.g., LAX)
- Destination Airport (e.g., SFO)
- Scheduled Departure Time (HHMM format)
- Departure Delay (minutes, negative for early)
- Distance (miles)
Run the test script to verify the setup:
python test_api.pyThis project is available at: https://github.com/ChukwuemekaP1/figth_predict_model.git