This project is a sentiment analysis tool that processes customer reviews uploaded in CSV or Excel format and returns the average sentiment scores (Positive, Negative, Neutral) using the Groq API. It is composed of a FastAPI backend to handle file uploads and sentiment analysis, a frontend built with Streamlit for user interaction, and uses Groq's AI model to perform sentiment analysis on the reviews.
Sriram2226-Sentiment-Analysis-Groq/
├── app.py # FastAPI backend for handling requests
├── commands.txt # Commands to run the project
├── customer_reviews.xlsx # Example input file with reviews
├── frontend.py # Streamlit frontend for uploading files and displaying results
└── requirements.txt # Required dependencies for the project
This file contains the FastAPI backend that processes the uploaded reviews and returns sentiment scores.
-
/(GET request):- Displays basic instructions on how to use the API.
-
/read_reviews(POST request):- Accepts a file containing reviews.
- Processes the reviews and returns the average sentiment scores (positive, negative, and neutral).
- Requires the file to have a column named
Review.
- Loads the file (CSV or Excel).
- Extracts reviews from the file.
- Sends the reviews to Groq's sentiment analysis model.
- Calculates the average sentiment scores from the response.
- Returns the calculated sentiment scores in JSON format.
This file contains the commands to run the application and set up the environment.
-
Activate the virtual environment:
env/Scripts/Activate -
Run FastAPI application with Uvicorn:
uvicorn app:app --reload -
Example of how to make a POST request to the API:
curl -X POST -F "file=@customer_reviews.xlsx" http://localhost:8000/read_reviews
This file contains the frontend built using Streamlit. It allows users to upload a file containing reviews and view the sentiment analysis results.
- Title and description for the tool.
- File uploader to allow the user to upload CSV or Excel files.
- Button to trigger the sentiment analysis.
- Displays the average sentiment scores after analysis.
To get started, clone the repository and install the required dependencies.
-
Clone the repository:
git clone https://github.com/Sriram2226-Sentiment-Analysis-Groq.git -
Navigate to the project directory:
cd Sentiment-Analysis-Groq -
Create a virtual environment:
python -m venv env -
Activate the virtual environment:
- On Windows:
env\Scripts\Activate - On Linux/Mac:
source env/bin/activate
- On Windows:
-
Install the required dependencies:
pip install -r requirements.txt
-
Run the FastAPI application with Uvicorn:
uvicorn app:app --reloadThe application will be available at
http://localhost:8000.
-
Run the Streamlit app:
streamlit run frontend.pyThe frontend will be available at
http://localhost:8501.
-
Upload Reviews File:
- The file should be in CSV or Excel format and must contain a column named
Review.
- The file should be in CSV or Excel format and must contain a column named
-
Analyze Sentiments:
- After uploading the file, click the "Analyze Sentiments" button.
- The tool will process the reviews and display the average sentiment scores (positive, negative, and neutral).
Returns the usage instructions for the API.
Response:
{
"How to use": "API takes in a CSV or EXCEL file containing reviews with a column named 'Review' and returns the average POSITIVE, NEGATIVE and NEUTRAL sentiment score of the reviews."
}Takes a CSV or Excel file with reviews and returns sentiment analysis results.
Request:
- Content-Type:
multipart/form-data - Body: Upload a file with a column
Review.
Response:
{
"data": {
"positive": 0.72,
"negative": 0.18,
"neutral": 0.10
}
}The project requires the GROQ_API_KEY to interact with the Groq API.
- Create a
.envfile in the project root directory. - Add your Groq API key to the
.envfile:GROQ_API_KEY=your_api_key_here
- If the file format is incorrect, the backend will return a
400status code with a message indicating the error. - If the required column
Reviewis not found, a400status code will be returned with a message indicating the missing column.
If you'd like to contribute to this project, feel free to fork the repository, make your changes, and submit a pull request.
Feel free to adjust or add any specific details as needed!