markdown guide
 

Hello, you might want to set up a python flask API endpoint and make a request to that endpoint from your React app to fetch the data.

 
 

Why would you write an API in node.js if the sentiment analysis is a python script?

Cause I want to deploy through MERN stack my application.Also I don't know if sentiment analysis can be done in tensorflow or not

Ah okay. Not sure if I fully understand your situation, but here's what I suggest:

Write your python sentiment analysis script as a serverless function (e.g. for AWS Lambda). Build an API for the script and call the API endpoint from the React Frontend. The rest of your app can follow the MERN stack.
As far as I understand, you'll have to build an API for the python script no matter what; I don't see how it can communicate with node or react otherwise.
E.g. if your app must absolutely follow the MERN stack, the React layer would read from the node endpoint... Which would itself get data from the Python API. So why not just call the Python API directly?

If you think this is a viable approach, I can share some boilerplate code I use to make serverless python functions on AWS Lambda with API Gateway

Sure :) But a heads-up first: please make sure you're willing to spend a bit of time learning AWS Lambda + API gateway and check that it's relevant to your needs. I don't want to accidentally send you down the wrong path if there's a better way to do it.

Anyway, here's the repo: github.com/jkhaui/serverless-pytho...

  1. Use the command npm i serverless -g to install the serverless framework globally.
  2. Clone the repo I sent you and follow instructions. Run serverless offline to edit your Python script locally. Test the API at localhost:4000
  3. If all goes well, use serverless deploy to host it on AWS Lambda. An endpoint URL should also be created automatically through API gateway.

Any questions/problems, let me know. Also, you'll be prompted for your AWS credentials at some point during these steps

Oh and btw, you can delete all the Spacy code in handler.py and also delete the directory en_core_web_sm-2.1.0. That's just for demo purposes.

Put your Python script in handler.py. This is the code that will let your script be accessed as an API:

    response = {
        'statusCode': 200,
        'headers': {
            'Content-Type': 'application/json',
            'Access-Control-Allow-Origin': '*',
        },
        'body': json.dumps(entities)
    }

    return response

sure Jordan, First I will also look into the alternatives. But I highly appreciate the help you provided :).Wish you good luck in your future endeavors.

No problem :) Thank you, and best of luck with your app too.

Classic DEV Post from Nov 1

Do developers have higher job satisfaction than non-developers?

SMAmmar profile image
I'm passionate about learning about the new technologies whether that's the frontend or backend. I enjoy creating user friendly responsive applications. I love working in fast-paced environments and l

Sore eyes?

dev.to now has dark mode.

Go to the "misc" section of your settings and select night theme ❤️