A powerful emotion detection application that analyzes text to identify emotions using machine learning. Built with a React frontend and Flask backend, this application leverages state-of-the-art transformer models for accurate emotion classification.
- Features
- Architecture
- Technology Stack
- Project Structure
- Prerequisites
- Installation
- Usage
- API Endpoints
- Testing
- Deployment
- Contributing
- License
- π― Real-time Emotion Detection: Analyze text and detect emotions with confidence scores
- π§ Advanced ML Models: Uses Hugging Face transformer models for high accuracy
- π Beautiful UI: Modern, responsive interface with emotion-specific visual feedback
- π§ RESTful API: Clean API design for easy integration
- π± Responsive Design: Works on all device sizes
- β‘ Fast Processing: Quick analysis with loading states
- π‘οΈ Error Handling: Comprehensive error handling and user feedback
The application follows a client-server architecture:
βββββββββββββββββββ HTTP βββββββββββββββββββ
β React FrontendβββββββββββββΆβ Flask Backend β
β (Vite + TS) β β (Python) β
βββββββββββββββββββ βββββββββββββββββββ
β
βββββββββββββββββββ
β Hugging Face β
βTransformer Modelβ
βββββββββββββββββββ
- Built with React and TypeScript
- Uses Vite for fast development and building
- Styled with Tailwind CSS
- Component-based architecture
- Makes API calls to the backend for emotion detection
- Flask REST API
- Hugging Face transformer model for emotion detection
- CORS enabled for frontend communication
- Returns primary and secondary emotions with confidence scores
- React - JavaScript library for building user interfaces
- TypeScript - Typed superset of JavaScript
- Vite - Fast build tool and development server
- Tailwind CSS - Utility-first CSS framework
- Lucide React - Beautiful SVG icons
- Flask - Lightweight Python web framework
- Transformers - Hugging Face library for state-of-the-art NLP
- PyTorch - Machine learning framework
- Python - Programming language
- npm - Package manager
- ESLint - Code linting
- Prettier - Code formatting
senti-text-detection/
βββ backend/
β βββ app.py # Flask API server
β βββ Text-model.py # Emotion detection model implementation
β βββ tests/
β βββ manual_test.py # Manual testing script
βββ src/
β βββ components/
β β βββ ui/ # Reusable UI components
β β βββ About.tsx # About section
β β βββ Contact.tsx # Contact section
β β βββ Demo.tsx # Main demo/emotion detection component
β β βββ Features.tsx # Features showcase
β β βββ Footer.tsx # Footer component
β β βββ Hero.tsx # Hero section
β β βββ Index.tsx # Main page component
β βββ hooks/
β β βββ use-toast.ts # Toast notification hook
β βββ lib/
β β βββ utils.ts # Utility functions
β βββ index.css # Global CSS styles
β βββ main.tsx # Application entry point
βββ index.html # HTML template
βββ package.json # Frontend dependencies
βββ tsconfig.json # TypeScript configuration
βββ vite.config.ts # Vite configuration
βββ tailwind.config.ts # Tailwind CSS configuration
βββ postcss.config.js # PostCSS configuration
βββ README.md # This file
Before you begin, ensure you have the following installed:
- Node.js (v16 or higher)
- npm (v8 or higher)
- Python (v3.8 or higher)
- pip (Python package installer)
-
Clone the repository:
git clone <repository-url> cd senti-text-detection
-
Install frontend dependencies:
npm install
-
Navigate to the backend directory:
cd backend -
Install Python dependencies:
pip install flask flask-cors transformers torch
-
Start the backend server:
cd backend python app.pyThe backend will be available at
http://127.0.0.1:5000 -
In a new terminal, start the frontend development server:
npm run dev
The frontend will be available at
http://localhost:5173 -
Open your browser and navigate to
http://localhost:5173to use the application
- Navigate to the "Live Sentiment Analysis" section
- Enter text in the text area (e.g., "I'm so happy today!")
- Click "Analyze Sentiment"
- View the detected emotion with confidence percentage
Health check endpoint
Response:
{
"message": "Senti Emotion Detection API is running!"
}Emotion detection endpoint
Request:
{
"text": "Your text here"
}Response:
{
"primary_emotion": "joy",
"primary_confidence": 95.24,
"secondary_emotion": "surprise",
"secondary_confidence": 3.6
}Supported Emotions:
- joy
- sadness
- anger
- fear
- love
- surprise
Manual testing script is available in the backend tests directory:
cd backend
python tests/manual_test.pyThis script allows you to manually enter text and see emotion detection results in the terminal.
You can test the API using curl:
curl -X POST http://127.0.0.1:5000/predict \
-H "Content-Type: application/json" \
-d '{"text": "I am feeling great today!"}'To build the frontend for production:
npm run buildThe built files will be in the dist/ directory.
For production deployment, consider using a WSGI server like Gunicorn:
pip install gunicorn
gunicorn -w 4 -b 0.0.0.0:5000 app:appCreate a .env file in the backend directory for configuration:
FLASK_ENV=production
FLASK_DEBUG=False- Fork the repository
- Create a feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
Built with β€οΈ using React, Flask, and Hugging Face Transformers