在服务器上托管 Python 并从 React Expo App 调用

我正在开发一个使用机器学习的应用,但最近遇到了问题.我发现 Expo 和 Python 并不能真正协同工作.

I am working on an app that uses machine learning, and recently run into a problem. I found out that Expo and Python do not really work together.

我认为解决方案是在服务器上托管和运行我的机器学习模型 (Python),然后从我的 JS Expo 应用程序发出请求,我认为与就在我的笔记本电脑上.

I thought that a solution would be to host and run my machine learning model (Python) on a server, and then make requests from my JS Expo app, and I thought this would also have the hidden bonus of faster processing compared to just on my laptop.

那么,人们能否首先确认这是否可行(从 JS Expo 应用程序调用在服务器上运行的 python 代码),如果可以,然后提供一些关于我可以在哪里托管的建议?

So, can people confirm whether firstly this is possible (to call python code running on a server, from a JS Expo app) and if so, then provide some recommendations as to where I can host this?

这是一个大学项目,所以我希望能找到免费或便宜的东西,谢谢.

This is for a university project, so I am hoping to find something either free or cheap, thanks.

推荐答案

我认为与仅在我的笔记本电脑上相比,这还有更快的处理速度.

I thought this would also have the hidden bonus of faster processing compared to just on my laptop.

如果您想免费这样做,那么任何云上的最低层实例都将具有 1 或 2 个内核以及 1-2 GB 的 RAM,它不会比您的本地设备更强大,也不会有任何硬件加速,但如果你打算在手机上运行它可能就足够了

If you want to do it for free then lowest tier instances on any cloud will have 1 or 2 cores plus 1-2 GB of RAM, it won't be stronger than your local device and it won't have any hardware acceleration, but if you planned to run that on your phone then it might be enough

那么,人们能否首先确认这是否可行(从 JS Expo 应用程序调用运行在服务器上的 python 代码)

So, can people confirm whether firstly this is possible (to call python code running on a server, from a JS Expo app)

简短的回答是,但是你提出这个问题的方式确实表明你不知道这种交流是如何进行的.你需要

Short answer yes, but The way you formulated this question does suggest that you don't know how this communication would work. You would need to

  • 从 expo 应用程序向您服务器上的某个端点发送 http 请求
  • 实现可以接受该请求的服务器代码,在您的情况下,最好在 python 中执行此操作(使用 django 或 flask 之类的东西)
  • 在您的服务器代码中执行 tensorflow 代码
  • 如果 tensorflow 代码执行速度很快,您可以在响应中发送结果,否则您需要第二个端点来检查结果

这是一个大学项目,所以我希望能找到免费或便宜的东西,谢谢.

This is for a university project, so I am hoping to find something either free or cheap, thanks.

对于本地开发,无论哪种方式,您都需要在本地托管它,对于大学项目,这应该足够了,但如果您想在公共服务器上拥有它,您可以获得免费套餐或几乎任何云服务上的一些起始积分,例如数字海洋为学生提供 100 美元的学分

for local development you will need to host it locally either way, for university project it should be enough, but if you want to have it on public server you can get free tier or some starting credits on almost any cloud service e.g. digital ocean gives 100$ credit for students


或者,您可以在 react-native 应用程序中使用 tensorflow,但不能在 python 中使用,https://blog.tensorflow.org/2020/02/tensorflowjs-for-react-native-is-here.html?m=1

相关文章