This project is a Sentiment Analysis Application. The application allows users to input text, analyzes the sentiment of the input using a pre-trained model, and visualizes the results through various charts.
- User-friendly interface for text input
- Sentiment analysis using the Hugging Face API
- Multiple visualizations of sentiment analysis results:
- Pie chart
- Bar chart
- Horizontal bar chart
- Donut chart
- Integration with GPT-2 for text generation (not implemented in the current version)
- Python 3.8+
- Streamlit
- Plotly
- Hugging Face API
- Requests library
|-- your_project_folder/
|-- app.py # Main Streamlit app to interact with the user and visualize results
|-- gpt_api.py # Handles the GPT-2 text generation API calls
|-- visualization.py # Contains functions to visualize sentiment analysis results
|-- README.md # This documentation file
|-- requirements.txt # Dependencies for the project
It's recommended to use a virtual environment to manage dependencies for your project. Here's how you can set it up:
-
Make sure you have Python 3.8 or newer installed on your system.
-
Install virtualenv if you haven't already:
pip install virtualenv -
Navigate to your project directory:
git clone https://github.com/maheshmm7/Sentiment-Analysis-ChatBot.git -
Create a new virtual environment:
python -m venv venv -
Activate the virtual environment:
- On Windows:
venv\Scripts\activate - On macOS and Linux:
source venv/bin/activate
- On Windows:
Once your virtual environment is activated, you can install the project dependencies:
- Install the required packages:
pip install -r requirements.txt
-
Clone the repository (if you haven't already):
git clone https://github.com/maheshmm7/Sentiment-Analysis-ChatBot.git -
Set up your Hugging Face API key:
- Sign up for a Hugging Face account and obtain an API key
- Replace the
headersvariable inapp.pywith your API key:headers = {"Authorization": "Bearer YOUR_API_KEY_HERE"}
-
Run the Streamlit app:
streamlit run app.py
The application uses the following Hugging Face API endpoints:
-
Sentiment Analysis API:
- URL:
https://api-inference.huggingface.co/models/cardiffnlp/twitter-roberta-base-sentiment - Method: POST
- Headers:
{"Authorization": "Bearer YOUR_API_KEY_HERE"} - Body:
{"inputs": "Your text here"}
- URL:
-
GPT-2 Text Generation API (not currently implemented in the main app):
- URL:
https://api-inference.huggingface.co/models/openai-community/gpt2 - Method: POST
- Headers:
{"Authorization": "Bearer YOUR_API_KEY_HERE"} - Body:
{"inputs": "Your prompt here"}
- URL:
-
User Input:
- The user enters text into the Streamlit interface.
-
Sentiment Analysis:
- The input text is sent to the Hugging Face Sentiment Analysis API.
- The API returns sentiment scores for positive, neutral, and negative sentiments.
-
Data Processing:
- The application processes the API response, extracting sentiment labels and scores.
-
Visualization:
- The processed data is used to create various charts (pie, bar, horizontal bar, and donut) using Plotly.
-
Display Results:
- The Streamlit interface displays the sentiment analysis results and visualizations to the user.
-
Ensure your virtual environment is activated.
-
Launch the application:
streamlit run app.py -
In the text area, enter a sentence or paragraph to analyze. For example:
I absolutely love this new restaurant! The food is delicious and the service is excellent. -
Click the "Analyze Sentiment" button.
-
View the results:
- You'll see the sentiment scores displayed as text.
- Below the text, you'll find four different charts visualizing the sentiment distribution.
-
Try different inputs to see how the sentiment analysis changes:
The weather today is quite gloomy and it's making me feel a bit down.I'm not sure how I feel about this movie. It had some good parts, but also some boring scenes.
- Implement GPT-2 text generation functionality
- Add more advanced NLP features
- Improve error handling and user feedback
- Optimize performance for larger text inputs
- RANGALA MAHESH
- maheshrangala7@gmail.com
- +919032017670
- Hugging Face for providing the sentiment analysis model
- Streamlit and Plotly for the interactive web interface and visualizations