I am trying to integrate an image color detector I have trained with fastai in my flask application. There is a custom function exported with the learner for the model to be loaded. The function is getImages. I am getting the following error because it cant find the function in the main namespace:
Can't get attribute 'getImages' on <module '__main__' from 'C:\\Users\\MyUser\\Documents\\MyApp\\Scraper\\env\\Scripts\\flask.exe\\__main__.py'>
How do I add it to that namescope so I can load the model? Do I need to edit the flask module? or is there another way.
@app.route('/api/getRelatedPages', methods=['POST'])
async def getRelatedPagesEnd():
requestData = request.get_json()
productInfo = Model.Product(requestData['pageContent'])
with set_posix_windows():
colorClassfier ={
'name': 'Color',
'Model': load_learner(Colors.getColorClassifierPath()),
'Target': 'image',
}
await productInfo.getSimilarProducts(colorClassfier)
here is where I load the model in run.py. it is causing the error because it is trying to load the model and cant find the function in the main scope because that is where it was available during training. In a simple python scripts I can just add the getImage function in the main namescope to make it available. here is the function:
def getImages(d): return d['imagePath']
but in a flask app the main scope starts from the flask.exe and I don't know how to add it.