App deployment : Zeit stuck on "analyzing"

Hi !

I used the following https://course.fast.ai/deployment_zeit.html#per-project-setup to deploy a dogs vs cats classifier.
For some reason, the classifier is stuck on “analyzing”.

Here is my server.py code :

from starlette.applications import Starlette
from starlette.responses import HTMLResponse, JSONResponse
from starlette.staticfiles import StaticFiles
from starlette.middleware.cors import CORSMiddleware
import uvicorn, aiohttp, asyncio
from io import BytesIO

from fastai import *
from fastai.vision import *

learner_file_url = ‘https://drive.google.com/uc?export=download&id=1HZ5tpKeUTXDKm-LV1rG3kekH1w-1oyCT
learner_file_name = ‘export’
classes = [‘cat’, ‘dog’]
path = Path(file).parent

app = Starlette()
app.add_middleware(CORSMiddleware, allow_origins=[’*’], allow_headers=[‘X-Requested-With’, ‘Content-Type’])
app.mount(’/static’, StaticFiles(directory=‘app/static’))

async def download_file(url, dest):
if dest.exists(): return
async with aiohttp.ClientSession() as session:
async with session.get(url) as response:
data = await response.read()
with open(dest, ‘wb’) as f: f.write(data)

async def setup_learner():
await download_file(learner_file_url, path/f’{learner_file_name}.pkl’)
return load_learner(path)

loop = asyncio.get_event_loop()
tasks = [asyncio.ensure_future(setup_learner())]
learn = loop.run_until_complete(asyncio.gather(*tasks))[0]
loop.close()

@app.route(’/’)
def index(request):
html = path/‘view’/‘index.html’
return HTMLResponse(html.open().read())

@app.route(’/analyze’, methods=[‘POST’])
async def analyze(request):
data = await request.form()
img_bytes = await (data[‘file’].read())
img = open_image(BytesIO(img_bytes))
return JSONResponse({‘result’: str(learn.predict(img)[0])})

if name == ‘main’:
if ‘serve’ in sys.argv: uvicorn.run(app, host=‘0.0.0.0’, port=5042)

you’ll find the app here : https://app-680fwws60.now.sh/view/
and the model here : https://drive.google.com/uc?export=download&id=1HZ5tpKeUTXDKm-LV1rG3kekH1w-1oyCT

I just have no clue what I did wrong. Can anybody help me out with that ?

edit : @arunoda ? I just saw you told people they could ping you ^^

1 Like

Zeit was removed from the list of services because it no longer works I think. You should try one of the 3 ways still listed. My recommendation is to go with Render at first, it’s really easy.

2 Likes

Hi !

thanks for your feedback ! I think in this case this page shouldn’t exist anymore : https://course.fast.ai/deployment_zeit.html#per-project-setup

it makes it look official, like a service FASTAI recommends. What do you think ?

The page about Zeit is no longer in the menu of the website. I think the page is still there because it was easier to remove it from the menu and assume people wouldn’t find it without a direct link like you.

this https://course.fast.ai/deployment_zeit.html#per-project-setup page is still active. The steps mentioned on that page are not working though. @jeremy

Hi, these steps won’t work anymore. The page still exists, but as PierreO mentionned it has been removed from the website’s menu, AND now it is also removed from the enriched videos. So nobody should end up on this page, except somebody who peruse the forums. But then they’ll find our posts and realize it’s not working :wink:

Hi @bdubreu
Were you able to solve your problem of your app being stuck at “analyzing”? I am using GCP and my app is stuck at analyzing.
Have no idea about what could be the problem.

3 Likes

Have you dealt with it? I have same problem. Don’t know what to do

1 Like

Hi @DDB89,
The problem is in setup.py file.
change “return JSONResponse({‘result’: learn.predict(img)[0]})”
to " return JSONResponse({‘result’: str(learn.predict(img)[0])})".
It worked in my case and app ran.
Hope this helps!

1 Like

Can you send whole this block from async def analyze. This didn’t help, unfortunatelly.

It was needed to change the pytorch version in requirements.txt from 1.0.1 to 1.1.0.
https://download.pytorch.org/whl/cpu/torch-1.1.0-cp37-cp37m-linux_x86_64.whl
Everything worked!

Great job. Couldn’t resolve the issue so I moved to “render”, but three months later they started to ask me for money ^^

That’s great to hear. Did you performed both the changes the one I suggested in setup.py and updating pytorch version in requirements.txt or just updated the pytorch version?

I already had the string you wrote in server.py, so the problem was in Pytorch version.

For me I noticed If the image is over 200kb, it gets stuck on analysing.