This project demonstrates an Image Classifier using a Flask API for prediction and a Streamlit application as a user interface. The classifier uses a Random Forest model trained on the Iris dataset, and the predictions are made based on basic image features.
[Streamlit UI]
|
v
[Flask API]
|
v
[Random Forest Model (iris_classifier.joblib)]
|
v
[Prediction Returned to Streamlit]
- Model Training: A
RandomForestClassifier
is trained using the Iris dataset and saved as a.joblib
file. - Flask API: Exposes a
/predict
endpoint to classify uploaded images. - Streamlit Frontend: Provides an interactive UI to upload images and get predictions from the Flask API.
- Dockerized Services: Flask and Streamlit are containerized using Docker for easy deployment.
The Random Forest model is trained on the Iris dataset and saved as a joblib
file in the joblib
directory. Here is the code for training and saving the model:
image-classifier/
│
├── joblib/ # Directory containing the .joblib file
│ └── iris_classifier.joblib
├── flask_app/ # Flask application directory
│ ├── app.py # Flask API code
│ ├── Dockerfile # Dockerfile for Flask
│ └── requirements.txt # Dependencies for Flask
├── streamlit_app/ # Streamlit application directory
│ ├── app.py # Streamlit UI code
│ ├── Dockerfile # Dockerfile for Streamlit
│ └── requirements.txt # Dependencies for Streamlit
└── docker-compose.yml # Docker Compose configuration
The project uses Docker Compose to manage the Flask and Streamlit services.
docker-compose.yml
:
- Build the containers:
docker-compose build
- Start the services:
docker-compose up
- Stop the services:
docker-compose down
- Model Training: A Random Forest model is trained and saved as a
.joblib
file. - Flask API: The API loads the
.joblib
file and exposes a/predict
endpoint. - Streamlit Frontend: Users upload images, and the app sends the image to the Flask API for prediction.
- Dockerized Services: Both Flask and Streamlit run as separate Docker containers.
-
Train the Model:
python training_script.py
This will generate the
iris_classifier.joblib
file in thejoblib
directory. -
Build and Run the Docker Containers:
docker-compose build docker-compose up
-
Access the Applications:
- Flask API:
http://127.0.0.1:5000
- Streamlit App:
http://127.0.0.1:8501
- Flask API:
- Train a custom model specifically for image classification.
- Deploy the service on cloud platforms like AWS or GCP.
- Add authentication to the API.
N/A