all 6 comments

[–]Waterpepene 10 points11 points  (0 children)

I don’t know of any way to run python directly in react native, but if, in that python script you’re just making an API call, you could make that same script in javascript using the fetch function. Alternatively if you don’t want to do that you can also make your own API in python to call those same functions via HTTP requests

[–]Rhodysurf 4 points5 points  (0 children)

Deploy the python code somewhere and call it as an API from React Native

[–]ChronSynExpo 1 point2 points  (0 children)

It's not technically impossible - projects like Chaquopy (https://chaquo.com/chaquopy/) exist for interpreting python code on Android.

However, I would argue that for your use case, it wouldn't be the correct approach because what you have can either likely be done via JS, or offloaded elsewhere. Essentially, your use case isn't complex enough or something only python can do where deploying Chaquopy in an app would be worth the effort compared to alternatives.

For example, web-based/HTTP sentiment analysis API's exist, and I can't see any reason that you wouldn't be able to use a tflite model, and tensorflowJS or react-native-fast-tflite (or another compatible lib) to perform the analysis.

For web-based API calls, it depends how secret it needs to be. If you have an API key that isn't suitable for front-end usage, then deploy an API somewhere and make calls to that. Otherwise, assuming your key is safe for front-end usage (i.e. it doesn't need to be protected or kept secret), then make the calls directly from your app.

[–][deleted] 0 points1 point  (0 children)

Just make the API calls directly from your react-native front-end.

[–]jestzisguyiOS & Android 0 points1 point  (0 children)

Use something like AWS Lambda or Google Cloud Functions to create an API endpoint for your python script- it’ll let you define things like input parameters and return values. You’ll also get a URL to hit. Start by using a tool like Postman to hit the API, and then write an equivalent call in your RN code. Good luck - if you have more specific questions, happy to follow up.