This project implements a simple Sentiment Analysis tool using Streamlit, FastAPI, and Hugging Face Transformers. The application takes user reviews as input and analyzes their sentiment to classify them as Positive, Negative, or Neutral based on a pre-trained NLP model.
The project consists of two main components:
- FastAPI Backend: Serves as the backend API that uses a pre-trained model from the Hugging Face library to analyze sentiment.
- Streamlit Frontend: Provides a user-friendly interface where users can input their reviews and see the results of the sentiment analysis in real-time.
- Python
- FastAPI: To build the backend API that handles the sentiment analysis.
- Streamlit: To create a simple and interactive user interface.
- Hugging Face Transformers: To load the pre-trained model for sentiment analysis.
- Uvicorn: To run the FastAPI server.
- Requests: For sending HTTP requests from the Streamlit app to the FastAPI server.
- Make sure you have Python 3.x installed on your system.
git clone https://github.com/yourusername/sentiment-analysis-project.git
cd sentiment-analysis-project
Create and activate a virtual environment to manage your dependencies.
python -m venv venv
- Windows
venv\Scripts\activate
- MacOS/Linux:
source venv/bin/activate
Install all necessary libraries using pip:
pip install -r requirements.txt
Start the FastAPI server by running:
uvicorn api:app --reload --port 8000
This will run the API server on http://localhost:8000.
In a new terminal window (while keeping the FastAPI server running), start the Streamlit app:
streamlit run app.py
This will open a new browser window at http://localhost:8501 where you can interact with the app.
sentiment-analysis-project/
├── api.py # FastAPI backend code
├── app.py # Streamlit frontend code
├── venv/ # Virtual environment
├── requirements.txt # Project dependencies
└── README.md # Project documentation
- Open the Streamlit app in your browser.
- Enter any review or text in the provided text area.
- Click the Analyze button.
- The sentiment (e.g., "POSITIVE", "NEGATIVE") and confidence score will be displayed based on the analysis performed by the pre-trained model.
FastAPI - Swagger UI
- Home Screen
- Analyzing a Positive Review
- Analyzing a Megative Review
- Adding more detailed visualizations to the Streamlit interface.
- Extending the model to handle more nuanced sentiment classifications (e.g., "Very Positive", "Neutral", "Mixed", "Somewhat Negative").
- Hugging Face for providing the pre-trained NLP model.
- Streamlit and FastAPI for their easy-to-use frameworks.