Generative Adversarial Network: Build a web application

Generative Adversarial Network: Build a web application

Quickly turn a Generative Adversarial Network model into a web application using Streamlit and deploy to Heroku. 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.

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

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

Artificial Intelligence, Machine Learning, Deep Learning 

Artificial Intelligence (AI) will and is currently taking over an important role in our lives — not necessarily through intelligent robots.

AI(Artificial Intelligence): The Business Benefits of Machine Learning

Enroll now at CETPA, the best Institute in India for Artificial Intelligence Online Training Course and Certification for students & working professionals & avail 50% instant discount.

Artificial Intelligence vs. Machine Learning vs. Deep Learning

Artificial Intelligence vs. Machine Learning vs. Deep Learning. We are going to discuss we difference between Artificial Intelligence, Machine Learning, and Deep Learning

Artificial Intelligence vs. Machine Learning vs. Deep Learning

Simple explanations of Artificial Intelligence, Machine Learning, and Deep Learning and how they’re all different

Artificial Intelligence vs. Machine Learning vs. Deep Learning

Learn the Difference between the most popular Buzzwords in today's tech. World — AI, Machine Learning and Deep Learning