Introduction

Previously I made a GAN model that colorizes black and white photos. It is working okay so I wish to share it with people. Coding in Jupyter notebook is very convenient for development but not that convenient for sharing, therefore I decide to make a web application and deploy it to Heroku.

I did not have web development experience and skills so it took me some time to figure out how to do it. I found a useful tool Stremlit, which allows me to code in Python and quickly turn it into a web application.

There are several steps for me to make this app:

  1. export the model
  2. download the model
  3. create a photo upload tool for users
  4. resize the uploaded photo
  5. load the model
  6. analyze the uploaded photo
  7. display the result
  8. deploy it to Heroku

Export the model

I trained the GAN model using fastai, so I simply export the model using

learner.export(export.pkl)

this exports the model as a pkl file.

Download the model

The first thing for this app is to download the model. Because the size of the model is too big (>200MB), it is not convenient to push to Github or directly push to Heroku. Therefore I need the app to download the file from external url to make sure the model is ready.

I stored the model in my dropbox account and created a downloadable link.

EXTERNAL_DEPENDENCIES = {
"export_5.pkl": {
"url": "https://dl.dropboxusercontent.com/s/xxxxxxx/export_5.pkl?dl=0",
"size": 246698366}
}

Then I used the code from Streamlit’s demo (https://github.com/streamlit/streamlit) to create the download function with a progress bar

I can call the function and download the model

for filename in EXTERNAL_DEPENDENCIES.keys():
    download_file(filename)

Create an upload tool for users

I want to have a tool that allows users to upload their B&W photos for analysis.

Streamlit provides a tool to make it: st.file_uploader

uploaded_file = st.file_uploader("upload a black&white photo", type=['jpg','png','jpeg'])

#deep-learning #artificial-intelligence #programming #machine-learning #photography

Generative Adversarial Network: Build a web application
3.65 GEEK