Skip to content

emsambit/image-classifier

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Image Classifier with Flask API and Streamlit Frontend

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.


Project Architecture

Architecture Diagram

[Streamlit UI]
     |
     v
[Flask API]
     |
     v
[Random Forest Model (iris_classifier.joblib)]
     |
     v
[Prediction Returned to Streamlit]

  1. Model Training: A RandomForestClassifier is trained using the Iris dataset and saved as a .joblib file.
  2. Flask API: Exposes a /predict endpoint to classify uploaded images.
  3. Streamlit Frontend: Provides an interactive UI to upload images and get predictions from the Flask API.
  4. Dockerized Services: Flask and Streamlit are containerized using Docker for easy deployment.

Model Training

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:


Project Structure

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

Docker Setup and Commands

Docker Compose Configuration

The project uses Docker Compose to manage the Flask and Streamlit services.

docker-compose.yml:

Docker Commands

  • Build the containers:
    docker-compose build
  • Start the services:
    docker-compose up
  • Stop the services:
    docker-compose down

Control Flow

  1. Model Training: A Random Forest model is trained and saved as a .joblib file.
  2. Flask API: The API loads the .joblib file and exposes a /predict endpoint.
  3. Streamlit Frontend: Users upload images, and the app sends the image to the Flask API for prediction.
  4. Dockerized Services: Both Flask and Streamlit run as separate Docker containers.

Screenshots

Streamlit Interface

![Streamlit Interface] image

Prediction Output

![Prediction Output] image


How to Run the Project

  1. Train the Model:

    python training_script.py

    This will generate the iris_classifier.joblib file in the joblib directory.

  2. Build and Run the Docker Containers:

    docker-compose build
    docker-compose up
  3. Access the Applications:

    • Flask API: http://127.0.0.1:5000
    • Streamlit App: http://127.0.0.1:8501

Future Improvements

  • Train a custom model specifically for image classification.
  • Deploy the service on cloud platforms like AWS or GCP.
  • Add authentication to the API.

License

N/A

About

Image Classifier with Flask API and Streamlit Frontend

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published