Forums

A function takes longer to complete in a flask web app than in the console, why?

In my webapp I have a function that is a classifier from huggingface's transformers. When I call the endpoints that function is taking too long, eventually giving me 3 minute timeouts, while if I instantiate the same classifier in the console it works just fine. Does anyone know why that difference might be? It also doesn't generate any error log, just the timeout 504 response

from transformers import pipeline
classifier = pipeline("task name", model='model name')

PS I have a free account, and I doesn't seem to be a memory issue, because the classifier is instantiated in the web app just fine too

It's likely that you are trying to create threads in the web app, which will not work on PythonAnywhere. See https://help.pythonanywhere.com/pages/MachineLearningInWebsiteCode/

Thanks! The torch solution mentioned there worked