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 BytesIOfrom 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).parentapp = 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 ^^