smaranjitghose / img_ai_app_boilerplate

An image classification app boilerplate to serve your deep learning models asap!
https://smaranjitghose.github.io/img_ai_app_boilerplate/
MIT License
31 stars 24 forks source link
artificial-intelligence aws aws-ec2 azure convolutional-neural-networks deeplearning digitalocean gcp hacktoberfest heroku heroku-deployment keras python slop slop20 streamlit swoc2021 tensorflow webapp

Image🖼 Classification App Boilerplate

Have you been puzzled by tons of videos, blogs and other resources on the internet and don't know where and how to deploy your AI models?

Won't it be nice if you could have a template where you just insert your trained model files, edit some promo text and Voila, it's done.

Well, look no further because this repository makes it as easy for you as it sounds!

How to use this project?🤔🤔:

NOTE: For now, we are exclusively focused on image classification models built using tensorflow/pytorch. Later we would expand to models dealing with text and speech data as well as training using MXNet or a julia environment

A. Fetching our template and setting it up:

  1. Open GitHub

  2. Log in with your credentials. [ Create an account if you have not done it already]

  3. Open the terminal/command prompt on your system

  4. Move to a suitable location where you want to keep the project files locally

Example: cd Desktop/projects

  1. Clone this repository.
git clone --depth 1 https://github.com/smaranjitghose/img_ai_app_boilerplate.git
  1. Navigate inside your cloned copy of the template
cd img_ai_app_boilerplate
  1. Now, let's fetch our dependencies to run our app. [A python package called StreamLit is at the heart of this app]
 pip install -r requirements.txt
  1. Now, let's put our model files inside the app.

B. Integrating our Trained Model:

  1. Open the model sub-directory
cd model
start .
  1. Paste your Keras.h5 model files there

  2. Shoot up your favorite code editor/IDE (I prefer VSCode).

    code . [Type this in the terminal to open VSCode if you already have it installed]

  3. Now open the file img_classifier.py.

  4. Search for the variable labels in the code and set its' value as per the labels of the dataset used for training your model. [say if you are doing Cats Vs Dogs classification, then labels = {0: "Cats", 1: "Dogs"} ]

    NOTE: This is totally dependent on your model training

  5. Update the value of the variable model with the path of your model file.

    [say model = tensorflow.keras.models.load_model('model/catsvsdogs.h5')]

  6. Save the changes.

C. Frontend and Content Changes

Continuing with changes to the User Interface or the frontend of our app please follow the steps mentioned below:

Home Page🏡

  1. Open app.py.

  2. Search for st.title and update the Title of the app as per your application's needs.

    [say st.title('Our Cats vs Dogs Classifier')]

  3. Now search for variable page_title and update it with the same. This will tweak the SEO.

    [say page_title="Cats Vs Dogs",]

  4. If you have some affiliation or maybe the app is made completely by you (perhaps with a group of your friends/colleagues) as a pet project, you can reflect that in the app by searching for st.subheader and updating it

    [say st.subheader("By John Doe and Jane Doe")]

^^ Delete any or all code that you won't use from the above

Contact Page🤳

  1. Search for the function call display_team("Your Awesome Name", "./assets/profile_pic.png","Your Awesome Affliation","hello@youareawesome.com" and update the following parameters as per your own discretion:

    • Name
    • path_to_image (I would suggest storing the images inside assets/images/
    • Affiliation
    • email
  2. For adding multiple members, you can call the same function multiple times. For example:

    display_team("John Doe","./assets/john_doe.png","Stanford University","contact@johndoe.com")
    display_team("Jane Doe","./assets/jane_doe.png","Harvard University","contact@janedoe.com")

D. Storing the Images📤 and User Feedback Online

Setting up Firebase

Creating a project

Setting up Storage

Setting up Realtime Database

  1. Click on the Realtime Database Option on the left panel.

  2. Once on the page, click on Create Database button.

  3. When you click the button, there will be a prompt to set the Security rules. It is recommended to start in locked mode so as to ensure security of the data.

  4. With this you have set up the Database successfully. Now whenever a user writes a feedback, you can check it here in this database. Since this database stores data in terms of JSON files, you can also export the JSON file and use it in whichever way you like.

Linking Firebase in the App

Since everything is set up in the Firebase Console, the only thing left to do is to link the services to your app. You can do it this way:

  1. Open firebase_bro.py

  2. Remember the config.txt file which we created earlier? Open it up and copy the contents of firebaseConfig into config variable inside firebase_bro.py.

  3. Save the File.

Voila! You have Successfully set up Firebase into your app!

Removing FIREBASE👋👋

If you do not want to use firebase please feel free to:

REMEMBER: The current version of the app only supports jpg, png and jpeg images as input

E. Testing🧪 the app Locally

NOTE: If you face any difficulties please raise an issue and let me know

Congrats! You have successfully deployed your models

F. Hosting the App 🚛

If you wish to share this as a prototype for others to try or showcase it to your friends and collegeues, please follow these steps:

Pushing the code to GitHub

  1. Create a new github repository with an approriate name say my my_app ( DO NOT ADD LICENSE, README, CODE OF CONDUCT, GITIGNORE files at this moment)

Depending upon your preference, you can make the repository private or public

  1. Open the Terminal/Command Prompt once again

  2. Make new folder having the same name as the github repository name

mkdir my_app
  1. Now let's copy all the files of the folder containing our prototype to this folder
cp -a ./img_ai_app_boilerplate/. ./my_app/
  1. Navigate to the location of the above newly created directory

cd my_app

  1. After copying, please feel free to remove the documentation related files that are unnecessary for your prototype
rm -r Guides\
rm LICSENSE CODE_OF_CONDUCT.md CONTRIBUTING.md README.MD
rm -r assets\readme_assets\
  1. Intiatilize the directory as a git repository
git init
  1. Set remote to your repository on GitHub( Copy the link of the repository from the Address Bar)
git remote add origin https://github.com/your_github_username/my_app.git 
  1. Track and commit the current changes
git add .
git commit -m "v.0.0.1"
  1. Push the changes to your remote repository on GitHub
git push origin main
  1. Once successsfull, close the terminal.

  2. Go to GitHub and locate the repository to check if the changes are reflected

  3. Now Add your own custom:

    • README.MD file (To descibe your project in brief)
    • LICENSE file (This depends upon you. I prefer going with MIT License for my open source repositories)
    • CODE_OF_CONDUCT.MD ( GitHub already provides a template for this)
    • Short Repository Description on the right
    • Relevant Tags

Hosting using a cloud service ☁:

Now as per your choice of hosting, please refer the following guides:

Code of Conduct

License

Future Work 🏗

If this project helped you, do give it a 🌟 on GitHub and share your work over LinkedIN and/or Twitter by tagging me!