Deploying FastAPI app to Deta but an error comes up saying sklearn library too large

Viewed 22

I have a simple machine learning model, it is built with DecisionTreeClassifier from sci-kit learn. I pickled and then pickle-loaded the model into a main.py file, my API app file. I then deployed it locally with FastAPI and tested it with localhost. Everything works well.

I then try to deploy it to Deta. The URL is https://4r8c6b.deta.dev/docs, but it throws an error Bad Gateway.

I go to the Deta Visor and check out the error message, and it is copied below.

Traceback (most recent call last):
  File "/opt/python/detalib/debugger.py", line 142, in wrap
    result = func(event, context)
  File "/var/task/_entry.py", line 12, in handler
    import main  # noqa
  File "/var/task/main.py", line 25, in <module>
    stroke_model = pickle.load(open('tree.sav','rb'))
ModuleNotFoundError: No module named 'sklearn'

I have only 3 items in my requirements.txt,

fastapi
pydantic
scikit-learn

I then try deta deploy again, and it throws this error in the Terminal,

(api) ➜  my_api deta deploy
Updating dependencies...
Error: failed to update dependencies: Request entity too large 

It looks like the sklearn library is too big to load so that the entire main.py isn't running as lacking proper libraries.

Is there any way to shrink, or only load part of the sklearn library and specify it in requirements.txt?

0 Answers
Related