A web application that analyzes the sentiment of movie reviews using Cohere's LLM API. The application consists of a ReactJS frontend and a FastAPI backend, containerized with Docker and deployed on the GCP Compute Engine.
Deployed Application URL
Screenshot
The application follows a microservices architecture with the following components:
- Frontend: React application that provides the user interface for submitting movie reviews and displaying sentiment analysis results
- Backend: FastAPI service that interfaces with Cohere's API to perform sentiment analysis
- API Integration: Cohere's LLM API for natural language processing and sentiment classification
- Docker: Containerization of both frontend and backend services
- Nginx: Reverse proxy to handle routing and serve the application
- Docker and Docker Compose
- Cohere API key (get it from Cohere Dashboard)
- GCP account with Compute Engine access (for deployment)
- Clone the repository:
git clone https://github.com/NehaKoppikar/cohere-sentiment-analysis.git
cd cohere-sentiment-analysis
- Create a
.env
file in the root directory:
cohere_api=your_api_key_here
CORS_ORIGINS=http://localhost:5173
- Start the application using Docker Compose:
docker compose up -d --build
- Access the application:
- Frontend: http://localhost:5173
- Backend testing: http://localhost:8080/docs (FastAPI Swagger UI)
The frontend looks something like this:
The backend provides two endpoints:
- SSH into your GCP Compute Engine instance:
gcloud compute ssh your-instance-name
- Install Docker and Docker Compose:
# Install Docker
sudo apt-get update
sudo apt-get install ca-certificates curl gnupg
sudo install -m 0755 -d /etc/apt/keyrings
curl -fsSL https://download.docker.com/linux/ubuntu/gpg | sudo gpg --dearmor -o /etc/apt/keyrings/docker.gpg
sudo chmod a+r /etc/apt/keyrings/docker.gpg
echo \
"deb [arch="$(dpkg --print-architecture)" signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/ubuntu \
"$(. /etc/os-release && echo "$VERSION_CODENAME")" stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin -y
- Clone the repository and set up the environment:
git clone https://github.com/NehaKoppikar/cohere-sentiment-analysis.git
cd cohere-sentiment-analysis
cp .env.example .env
# Edit .env with your Cohere API key
nano .env
- Install and configure Nginx:
sudo apt install nginx -y
sudo nano /etc/nginx/sites-available/app.conf
# Copy the Nginx configuration provided in the repository
sudo ln -s /etc/nginx/sites-available/app.conf /etc/nginx/sites-enabled/
sudo rm /etc/nginx/sites-enabled/default
sudo nginx -t
sudo systemctl restart nginx
- Start the application:
docker compose up -d --build
-
If containers fail to start:
docker compose logs
-
Common issues:
- Verify Cohere API key is correctly set in
.env
- Check if ports 5173 and 8080 are available
- Ensure Docker service is running
- Verify all containers are up:
docker compose ps
- Verify Cohere API key is correctly set in
-
For deployment issues:
- Check GCP firewall rules for ports 80, 5173, and 8080
- Verify Nginx configuration
- Check application logs:
docker compose logs frontend
ordocker compose logs backend
- The Cohere API key is stored in the
.env
file (not committed to the repository) - CORS is configured to allow only localhost origins for development
- Nginx is configured with security headers
- Input validation is implemented on the backend