A Backend build on Python & Fastapi with a RESTful API endpoint for sentiment analysis.
The API will accept text input, validate with Pydantic and return the sentiment analysis result using a pre-trained machine learning model.
Make sure python version >=3.9
.
Clone this repo, open in terminal and
Run :
python -m venv .venv
In Terminal, Run the following commands :
In Linux: source .venv/bin/activate
In Windows: .venv\Scripts\activate
Then install the required dependencies and start app
pip install -r requirements.txt
uvicorn main:app
- Minimal Static FrontEnd :
http://127.0.0.1:8000/
- Write an Sentence and Get Sentiment-Analyses instantly
- Request is validated
- Response is validated
- Added Extra Query Sentiment Analysis (%)Percentage Result
- Exception Handling included
API Routes
- GET REQUEST -
http://127.0.0.1:8000/hello
- Request Payload - Empty
- Expected Response - "Hello World"
- POST REQUEST
http://127.0.0.1:8000/analyze
- Request Payload - JSON : {"text": "STRING"}
- Expected Response - JSON : {"sentiment":"positive/negative/neutral"}
- To get a Response with Sentence Sentiment and Score
add
?withScore=True
i.e. - POST REQUESThttp://127.0.0.1:8000/analyze?withScore=True
- With Score Expected Response - JSON :
{"sentiment":"positive/negative/neutral", "score": float}