Is it possible to use the python "pickle" module with workers?

I'm trying to create a worker to run my ML model. It is a pickled model. I'm trying to import the pickle module, however, transcrypt says it is not found. I see it is a native CPython module which transcrypt says they have support for some modules, however, I get an error that says:
Error while compiling (offending file last):
File '/Users/sean/Projects/alqen/apps/rhino/ai/sales-estimator/jon-sales-estimator/cloudflare-worker/index.py', line 1, at import of:
File 'pickle', line 152, namely:

Can't import module 'pickle'

Aborted
Error while compiling (offending file last):
File '/Users/sean/Projects/alqen/apps/rhino/ai/sales-estimator/jon-sales-estimator/cloudflare-worker/index.py', line 1, at import of:
File 'pickle', line 152, namely:

Can't import module 'pickle'

Aborted
This is my code:
import pickle


def handleRequest(request):
with open('./full_model_dict.pkl', 'rb') as handle:
cat_model_dict = pickle.load(handle)

test_feat_vec = [1334134.0, 6172404.0, 5753260.0, 1.0, 1.0]

res = cat_model_dict.predict(test_feat_vec)

return __new__(Response(res, {
'headers': {'content-type': 'text/plain'}
}))


addEventListener(
'fetch', (lambda event: event.respondWith(handleRequest(event.request))))
import pickle


def handleRequest(request):
with open('./full_model_dict.pkl', 'rb') as handle:
cat_model_dict = pickle.load(handle)

test_feat_vec = [1334134.0, 6172404.0, 5753260.0, 1.0, 1.0]

res = cat_model_dict.predict(test_feat_vec)

return __new__(Response(res, {
'headers': {'content-type': 'text/plain'}
}))


addEventListener(
'fetch', (lambda event: event.respondWith(handleRequest(event.request))))
Has anyone attempted to use pickle with cloudflare workers before? I have a hunch that its probably not supported given the transpilation w/ WASM but just wanted to be sure.
0 Replies
No replies yetBe the first to reply to this messageJoin
Want results from more Discord servers?
Add your server