4

I need to execute some python machine learning code and was hoping to execute it from a node process within a Google Cloud Function.

I want to use node because I have some firebase admin tasks I want to run afterwards. I also have a deployment workflow with node that I'm content with.

Is this possible? If so, can you point me to an example?

1 Answer 1

3

Yes, this would be possible, you probably need to use http://www.pyinstaller.org/ to package the python code. Have a look at my python library for actually writing your functions in python to do it, or just copy paste whatever parts you need to do it yourself: https://github.com/MartinSahlen/cloud-functions-python/

Sign up to request clarification or add additional context in comments.

7 Comments

Can you elaborate a bit on how this works. Are you compiling Python into JS or are you co-locating the Python stuff in a container where the cloud function's JS can call it? I'm new to cloud functions and cannot yet imagine how it works, given the technology's current out-of-the-box limitation to JS.
So what is happening is that pyinstaller is used to package the python code into a self-executable unit. How that works is probably by embedding the necessary parts of the python runtime but exactly how that works is not known to me - but pyinstaller is open source and well documented so information should be there. After packaging the python code, there is a node script that executes the function sending and recieving data from the python executable using stdin / stdout. Again, please have a look at the source code in githhub - it's all there.
Thx for you response, I get the picture now.
I have packaged my python code into the self-executable unit..which creates a folder containing an executable and a lot of other stuff. I tried and that executable works sufficiently on my local machine. But being new to Firebase, I have no idea how to upload this and run it.I want to use it via spawn. Need help..how is that done?
@AakashChoubey this is what I answered above. You should check out the source code which does exactly this. keep in mind, this is not set up to work with firebase functions, only google cloud functions.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.