A lightweight and production-ready sentiment analysis API built with Python, containerized with Docker, and deployed to Azure App Service. It accepts raw text and returns the sentiment label and confidence scores using modern NLP tools.
- 🔍 Analyze sentiment (positive / neutral / negative)
- ⚡ Fast and RESTful API (FastAPI-based)
- 🐳 Dockerized for consistency across environments
- ☁️ Azure-ready deployment
- 📊 Returns label + probability scores
- 🧪 Swagger UI for testing
- Framework: FastAPI
- NLP: TextBlob / HuggingFace / VADER (update as needed)
- Deployment: Docker + Azure App Service
- CI/CD: GitHub Actions
- Docs: Auto-generated via Swagger UI
git clone https://github.com/niketbhatt2002/sentiment-api-azure.git
cd sentiment-api-azure
2. Run with Docker
bash
Copy
Edit
docker build -t sentiment-api .
docker run -d -p 8000:8000 sentiment-api
Then go to: http://localhost:8000/docs for Swagger UI.
3. Without Docker (local)
bash
Copy
Edit
python -m venv venv
source venv/bin/activate # Windows: venv\Scripts\activate
pip install -r requirements.txt
uvicorn main:app --reload
🧪 Example Usage
Request
bash
Copy
Edit
POST /predict
Content-Type: application/json
{
"text": "I absolutely love this!"
}
Response
json
Copy
Edit
{
"sentiment": "positive",
"confidence": {
"positive": 0.91,
"neutral": 0.07,
"negative": 0.02
}
}
🐙 CI/CD with GitHub Actions
The repo includes a GitHub Actions workflow (.github/workflows/docker-build.yml) that:
Builds the Docker image
Optionally pushes it to Docker Hub or Azure Container Registry
Can auto-deploy to Azure App Service
☁️ Azure Deployment Steps
Create an Azure App Service & Resource Group.
Connect to GitHub repo via Deployment Center.
Set up environment variables (if needed).
Optionally push Docker image to Azure Container Registry (ACR).
🧾 API Documentation
Once running, you can access:
Swagger UI → /docs
ReDoc → /redoc
📄 License
This project is licensed under the MIT License.
👤 Author
Niket Bhatt
GitHub: @niketbhatt2002