A full-stack sentiment analysis application with separate frontend and backend services. Built with Next.js frontend and FastAPI backend.
- Real-time Sentiment Analysis: Analyze text sentiment using Naive Bayes classifier
- Modern Web Interface: Built with Next.js 14 and Tailwind CSS
- RESTful API: FastAPI backend with automatic documentation
- Machine Learning: Trained on movie reviews dataset using NLTK and scikit-learn
- Independent Services: Frontend and backend can be deployed separately
- Frontend: Next.js 14 (React/TypeScript)
- Backend: FastAPI (Python)
- ML Library: scikit-learn with NLTK
- Styling: Tailwind CSS with shadcn/ui components
sentiment-analyzer/
├── frontend/ # Next.js frontend
│ ├── app/ # Next.js app directory
│ ├── components/ # React components
│ ├── lib/ # Utility functions
│ ├── package.json # Node.js dependencies
│ └── next.config.mjs # Next.js configuration
├── backend/ # FastAPI backend
│ ├── main.py # FastAPI application
│ ├── requirements.txt # Python dependencies
│ └── README.md # Backend documentation
├── venv/ # Python virtual environment
└── README.md # This file
- Python 3.11+
- Node.js 18+
- npm or yarn
-
Create and activate virtual environment:
python -m venv venv # Windows .\venv\Scripts\Activate.ps1 # Linux/Mac source venv/bin/activate
-
Install Python dependencies:
pip install -r backend/requirements.txt
-
Run the backend:
python backend/main.py
The API will be available at
http://localhost:8000
-
Install Node.js dependencies:
cd frontend npm install -
Run the development server:
npm run dev
The frontend will be available at
http://localhost:3000
Once the backend is running, visit:
- API Docs:
http://localhost:8000/docs - ReDoc:
http://localhost:8000/redoc
GET /- API informationGET /api/health- Health check endpointPOST /api/predict- Analyze sentimentGET /api/demo- Demo with sample predictions
# Analyze sentiment
curl -X POST "http://localhost:8000/api/predict" \
-H "Content-Type: application/json" \
-d '{"text": "I love this movie!"}'
# Response
{
"text": "I love this movie!",
"sentiment": "pos",
"confidence": 0.85
}# Health check
curl http://localhost:8000/api/health
# Sentiment analysis
curl -X POST "http://localhost:8000/api/predict" \
-H "Content-Type: application/json" \
-d '{"text": "This is amazing!"}'Visit http://localhost:3000 and test the web interface.
- Framework: FastAPI
- ML Libraries: scikit-learn, NLTK
- Model: Naive Bayes classifier trained on movie reviews
- Features: Text preprocessing, feature extraction, sentiment prediction
- Framework: Next.js 14 with App Router
- Styling: Tailwind CSS
- Components: shadcn/ui component library
- TypeScript: Full type safety
- FastAPI 0.104.1
- Uvicorn 0.24.0
- NLTK 3.9.1
- scikit-learn 1.5.2
- NumPy 2.3.3
- SciPy 1.16.2
- Next.js 14.2.16
- React 18
- TypeScript 5
- Tailwind CSS 3.4.0
- shadcn/ui components
- Fork the repository
- Create a feature branch
- Make your changes
- Test thoroughly
- Submit a pull request
Frontend: Sentiment Analyzer Link
- Movie reviews dataset from NLTK
- FastAPI for the excellent web framework
- Next.js team for the React framework
- shadcn/ui for the beautiful components