New guide for easy web app deployment

Hi qq88 hope you are having a beautiful day today!

How difficult is it to downgrade?

I wouldn’t bother downgrading if your machine is working, 3.8 is the future. :smiley:

In my humble opinion the only way to program in python is with virtual environments.
I literally have probably 100’s of virtual environments from tutorials and different apps and things I work on. If I don’t have a virtual env with the libraries I want, I create another you can specify the version of python you want to use.

I don’t consider virtual environments temporary, they allow me to try all all sorts of experiments and work with code from other peoples environments without trashing my machine.

if you don’t use virtual environments and you install lots of libraries and are always trying new things in python I guarantee you will end up trashing parts of the software on your machine.

Is it not possible to change the code in such a way it works with 3.8?

I don’t know enough about the python and fastai to answer this, and am not sure if this is the best approach.

Cheers mrfabulous1 hope this helps :smiley: :smiley:

2 Likes

Thanks for your response.
I do work only with virtual environments, luckily I was exposed to this credo right at the start of my learning.

What I was referring to with:

I already messed up my comp when upgrading to 3.8 and am having now two versions.

is that after installing 3.8 with via the official upgrade the old version stayed on my computer. Or smth like that. I tried to resolve it but no success but found out other people suffer from this as well.

1 Like

OK, so made some progress, was able to create the app with flask but now I’m struggling with the evaluation phase, here is the error.

This is my code:

from fastai import *
from fastai.vision import *

path = Path('')
model = load_learner(path)

def get_veggie(image_bytes):
    img_bytes = image_bytes['file'].read()
    img = open_image(BytesIO(img_bytes))
    prediction = model.predict(img)[0]
    print(prediction)

And this is the app.py part:

from flask import Flask, render_template, request
from commons import get_tensor
from inference import get_veggie

app = Flask(__name__)

@app.route('/', methods=['GET', 'POST'])
def hello_world():
    if request.method == 'GET':
        return render_template('index.html', value='O')
    if request.method == 'POST':
        if 'file' not in request.files:
            print('image not uploaded')
            return
        file = request.files['file']
        image = file.read()
        get_veggie(image_bytes=image)
        return render_template('result.html', veggie='cucumber')

if __name__ == '__main__':
    app.run(debug=True)

@jeremy The link that you have mentioned for production using Zeit doesn’t seem to work .I am a new learner and I have been struggling to find resources , so that i can create a web application just like you did. can you show me the right way to go about for creating an web application and deploy the fastai model ,I stumble across platforms that needs me to pay and I have no clue how to proceed ,I am a student and I cannot afford to pay ,Is there a way for me to create the web application free of cost ?Help me with resources please ! Thank you .

Looking at the cached link ( https://webcache.googleusercontent.com/search?q=cache:sOKE-XRyBjoJ:https://course.fast.ai/deployment_zeit.html+&cd=1&hl=en&ct=clnk&gl=uk ), it seems this method no longer works sadly.

1 Like

After some reading, I too think that Zeit (now Vercel) is the best way to deploy the web app.

The link for the guide does not work. Where can I find one?

I would like to find out how to deploy the model to an web app. A step by step guide is expected.

the post above yours seems to suggest that vercel no longer works for fastai.

if you want an easy deployment option i’d recommend heroku. there’s a guide here.

if you want a guide for somewhere else google it. if you don’t find one, write one and post it.

2 Likes

I have deployed to Heroku for free. You can refer to this or the method mentioned by @joedockrill

I too have deployed to heroku. Initially, I had problems because I had to install some libraries to install for opencv but figured it out eventually.

Looking for some guidance to get my heroku app to work. I am getting an error with

2021-01-16T17:16:29.430526+00:00 app[web.1]:   File "/app/.heroku/python/lib/python3.7/site-packages/torch/serialization.py", line 211, in __init__
2021-01-16T17:16:29.430965+00:00 app[web.1]:     super(_open_file, self).__init__(open(name, mode))
2021-01-16T17:16:29.431055+00:00 app[web.1]: IsADirectoryError: [Errno 21] Is a directory: 'app'
2021-01-16T17:16:30.377978+00:00 heroku[web.1]: Process exited with status 1

I believe it has something to do with the load_learner step, but I can’t seem to figure out what it is.
Any ideas?