Spaces:
Sleeping
Sleeping
File size: 2,838 Bytes
3b29dee b01fcc1 3b29dee b01fcc1 3b29dee b01fcc1 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | ---
title: Sentiment Analysis
emoji: π
colorFrom: pink
colorTo: yellow
sdk: streamlit
sdk_version: 1.43.2
app_file: app.py
pinned: false
license: mit
short_description: Real-time text sentiment analysis with Streamlit.
---
# Sentiment Analysis Web App
## Overview
This project consists of a sentiment analysis web application built using **Streamlit** for the frontend and **Flask** for the backend. The model used is **cardiffnlp/twitter-roberta-base-sentiment-latest**, which classifies input sentences into three sentiment categories: **Positive, Neutral, and Negative**.
## Features
- Users can input multiple sentences for analysis.
- Sentiment analysis is performed using a pre-trained **RoBERTa** model.
- Sentiment percentages are calculated and displayed.
- A **Flask API** endpoint (`/sentiment`) is available for programmatic access.
---
## Project Structure
```
π sentiment-analysis
βββ .gitignore # Ignored files
βββ app.py # Flask API for sentiment analysis
βββ stream.py # Streamlit app for user interaction
βββ requirements.txt # Dependencies
βββ README.md # Project documentation
```
---
## Installation and Setup
### 1. Clone the Repository
```bash
git clone <repo-url>
cd sentiment-analysis
```
### 2. Create a Virtual Environment (Optional but Recommended)
```bash
python -m venv venv
source venv/bin/activate # On macOS/Linux
venv\Scripts\activate # On Windows
```
### 3. Install Dependencies
```bash
pip install -r requirements.txt
```
---
## Running the Flask API (Backend)
### 1. Run the Flask App
```bash
python app.py
```
### 2. API Endpoint
Once the server is running, the API can be accessed at:
```
POST http://localhost:5000/sentiment
```
**Request Body (JSON Example):**
```json
{
"sentence1": "I love this product!",
"sentence2": "It's okay, nothing special.",
"sentence3": "I hate waiting in long lines."
}
```
**Response Example:**
```json
{
"positive": 33.33,
"neutral": 33.33,
"negative": 33.33
}
```
---
## Running the Streamlit Web App (Frontend)
### 1. Run the Streamlit App
```bash
streamlit run stream.py
```
The web app will be accessible at:
**http://localhost:8501**
---
## Technologies Used
- **Python** (Backend and Frontend)
- **Flask** (API Development)
- **Streamlit** (Web Interface)
- **Transformers** (Hugging Face model)
- **NumPy, SciPy** (Mathematical Operations)
- **Collections (Counter)** (Sentiment Analysis Computation)
---
## Future Enhancements
- Deploy the application on **AWS/GCP/Heroku**.
- Improve UI/UX with interactive graphs.
- Support for more languages.
---
## License
This project is open-source and available under the **MIT License**.
---
## Contact
For queries or contributions, reach out to:
**Tahir Abbas Shaikh**
π§ tahirabbasshaikh555@gmail.com
π +923022024206 |