3 ms·
How does one connect a rails 6 app to a python tensor flow (inference) model?
by phodo 7y ago
How does one connect a rails 6 app to a python tensor flow (inference) model?
- aledalgrande 7y agoUsing a client to connect to a prediction HTTP service would be my choice (Flask app?). Otherwise if you want to you can do something with the backticks, which will run a shell process from Ruby and get the return value: `python3 predict.py <input>`
- nurettin 7y agoLike you connect anything to anything else. You use a myriad of Inter-process communication techniques from memory maps to named pipes to socket protocols to databases.
- GolDDranks 7y agoYou deploy the Python model to a backend service and expose a simple HTTP-based API, maybe using Flask? You should preferably keep the web part and heavy lifting separate.
- ssaunier_ 7y agoAs suggested, encapsulate your prediction model in a web service, then calling it from Rails would be a good way to go. An other way is to use something like Faktory (https://contribsys.com/faktory/ https://contribsys.com/faktory/) on top of Redis. You push jobs from Rails and then you pull them from Python to execute. Then Python can enqueue another job with the result which gets consumed by Rails (async callback).