Sadeep Sachintha commited on
Commit ·
8fae7b4
1
Parent(s): 586f9cf
docs: overhaul README with enhanced formatting, project badges, and detailed deployment guides
Browse files
README.md
CHANGED
|
@@ -1,76 +1,114 @@
|
|
| 1 |
-
# Sinhala NLP
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
-
|
| 6 |
-
- **AI Model**: Utilizes a fine-tuned Hugging Face transformer model (`keshan/sinhala-sentiment-analysis`) for native Sinhala text sentiment analysis.
|
| 7 |
-
- **Backend**: Built with **FastAPI** for high performance, automatic documentation (Swagger UI), and validation.
|
| 8 |
-
- **Containerization**: Packaged using **Docker**, ensuring consistency across environments and seamless cloud deployment.
|
| 9 |
-
- **CI/CD Pipeline**: Automated testing and deployment to Hugging Face Spaces using **GitHub Actions**.
|
| 10 |
|
| 11 |
-
|
| 12 |
-
- **Python 3.10**
|
| 13 |
-
- **FastAPI** & **Uvicorn**
|
| 14 |
-
- **Hugging Face Transformers** & **PyTorch**
|
| 15 |
-
- **Docker**
|
| 16 |
-
- **GitHub Actions**
|
| 17 |
-
- **Hugging Face Spaces** (Free Docker Hosting)
|
| 18 |
|
| 19 |
-
|
| 20 |
|
| 21 |
-
##
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
```bash
|
| 23 |
-
|
|
|
|
| 24 |
cd "NLP + Deployment"
|
| 25 |
-
```
|
| 26 |
|
| 27 |
-
#
|
| 28 |
-
```bash
|
| 29 |
docker build -t sinhala-nlp-api .
|
|
|
|
|
|
|
| 30 |
docker run -p 7860:7860 sinhala-nlp-api
|
| 31 |
```
|
| 32 |
-
The API
|
| 33 |
|
| 34 |
-
###
|
| 35 |
```bash
|
|
|
|
| 36 |
python -m venv venv
|
| 37 |
-
source venv/bin/activate # On Windows: venv\Scripts\activate
|
|
|
|
|
|
|
| 38 |
pip install -r requirements.txt
|
|
|
|
|
|
|
| 39 |
uvicorn app.main:app --host 0.0.0.0 --port 7860 --reload
|
| 40 |
```
|
| 41 |
|
| 42 |
-
|
|
|
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
- **
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
### 2. Predict Sentiment
|
| 50 |
-
- **
|
| 51 |
-
- **
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
## CI/CD Deployment
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
|
|
|
| 74 |
- `HF_USERNAME`: Your Hugging Face username.
|
| 75 |
-
- `HF_SPACE_NAME`: The name of the
|
| 76 |
-
4.
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# 🚀 Sinhala NLP Model Deployment (Cloud-Based API)
|
| 2 |
|
| 3 |
+
[](https://fastapi.tiangolo.com/)
|
| 4 |
+
[](https://www.docker.com/)
|
| 5 |
+
[](https://huggingface.co/)
|
| 6 |
+
[](https://github.com/features/actions)
|
| 7 |
+
[](https://www.python.org/)
|
| 8 |
|
| 9 |
+
**🔴 [Live Demo on Hugging Face Spaces](https://huggingface.co/spaces/dwssp/NLP_Model)**
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
An automated, scalable, and production-ready REST API for Sinhala Sentiment Analysis. This project demonstrates the intersection of **AI/ML, Backend Engineering, and DevOps** by deploying a fine-tuned Hugging Face transformer model using FastAPI, Dockerized for portability, and automated via a GitHub Actions CI/CD pipeline.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
+
---
|
| 14 |
|
| 15 |
+
## 🌟 Key Features
|
| 16 |
+
|
| 17 |
+
- **🧠 Native Sinhala NLP:** Utilizes `keshan/sinhala-sentiment-analysis` for accurate sentiment detection (Positive/Negative) in Sinhala text.
|
| 18 |
+
- **⚡ High-Performance Backend:** Built with **FastAPI** and **Uvicorn**, ensuring rapid response times, data validation via Pydantic, and automatic OpenAPI documentation.
|
| 19 |
+
- **🐳 Containerized Portability:** Fully Dockerized. The model is downloaded and cached during the Docker build stage for lightning-fast container startup.
|
| 20 |
+
- **⚙️ CI/CD Automation:** A robust **GitHub Actions** pipeline automatically tests the codebase and deploys the latest version to a free Hugging Face Docker Space upon merging to `main`.
|
| 21 |
+
- **☁️ Cloud-Native Architecture:** Designed to scale and run effortlessly on any cloud provider supporting Docker (currently deployed on Hugging Face Spaces).
|
| 22 |
+
|
| 23 |
+
---
|
| 24 |
+
|
| 25 |
+
## 🏗️ Architecture Flow
|
| 26 |
+
|
| 27 |
+
1. **Client** sends a POST request with Sinhala text to the API.
|
| 28 |
+
2. **FastAPI** validates the payload.
|
| 29 |
+
3. The **Transformers Pipeline** processes the text and infers sentiment.
|
| 30 |
+
4. The system returns a JSON response containing the sentiment label and confidence score.
|
| 31 |
+
5. All updates to the code trigger **GitHub Actions** -> Builds Docker Image -> Pushes to **HF Spaces**.
|
| 32 |
+
|
| 33 |
+
---
|
| 34 |
+
|
| 35 |
+
## 🚀 Getting Started Locally
|
| 36 |
+
|
| 37 |
+
### Prerequisites
|
| 38 |
+
- Python 3.10+
|
| 39 |
+
- Docker (Optional but recommended)
|
| 40 |
+
|
| 41 |
+
### Option 1: Run via Docker (Recommended)
|
| 42 |
```bash
|
| 43 |
+
# 1. Clone the repository
|
| 44 |
+
git clone https://github.com/yourusername/sinhala-nlp-deployment.git
|
| 45 |
cd "NLP + Deployment"
|
|
|
|
| 46 |
|
| 47 |
+
# 2. Build the Docker image (This will download the ML model)
|
|
|
|
| 48 |
docker build -t sinhala-nlp-api .
|
| 49 |
+
|
| 50 |
+
# 3. Run the container
|
| 51 |
docker run -p 7860:7860 sinhala-nlp-api
|
| 52 |
```
|
| 53 |
+
*The API is now running at `http://localhost:7860`*
|
| 54 |
|
| 55 |
+
### Option 2: Run via Python Virtual Environment
|
| 56 |
```bash
|
| 57 |
+
# 1. Create and activate a virtual environment
|
| 58 |
python -m venv venv
|
| 59 |
+
source venv/bin/activate # On Windows use: venv\Scripts\activate
|
| 60 |
+
|
| 61 |
+
# 2. Install dependencies
|
| 62 |
pip install -r requirements.txt
|
| 63 |
+
|
| 64 |
+
# 3. Start the FastAPI server
|
| 65 |
uvicorn app.main:app --host 0.0.0.0 --port 7860 --reload
|
| 66 |
```
|
| 67 |
|
| 68 |
+
---
|
| 69 |
+
|
| 70 |
+
## 📖 API Documentation
|
| 71 |
|
| 72 |
+
Once the server is running, you can access the interactive Swagger UI at: `http://localhost:7860/docs`
|
| 73 |
+
|
| 74 |
+
### 1. Check Server Status
|
| 75 |
+
- **Endpoint:** `GET /`
|
| 76 |
+
- **Response:**
|
| 77 |
+
```json
|
| 78 |
+
{
|
| 79 |
+
"message": "Welcome to the Sinhala Sentiment Analysis API. Use POST /predict to analyze text."
|
| 80 |
+
}
|
| 81 |
+
```
|
| 82 |
|
| 83 |
### 2. Predict Sentiment
|
| 84 |
+
- **Endpoint:** `POST /predict`
|
| 85 |
+
- **Payload:**
|
| 86 |
+
```json
|
| 87 |
+
{
|
| 88 |
+
"text": "මෙය ඉතා හොඳ නිර්මාණයක්."
|
| 89 |
+
}
|
| 90 |
+
```
|
| 91 |
+
- **Response:**
|
| 92 |
+
```json
|
| 93 |
+
{
|
| 94 |
+
"label": "LABEL_1",
|
| 95 |
+
"score": 0.987654321
|
| 96 |
+
}
|
| 97 |
+
```
|
| 98 |
+
|
| 99 |
+
---
|
| 100 |
+
|
| 101 |
+
## 🚢 CI/CD Deployment Guide
|
| 102 |
+
|
| 103 |
+
This project is pre-configured to deploy automatically to **Hugging Face Spaces**.
|
| 104 |
+
|
| 105 |
+
1. Create a free **Docker Space** on [Hugging Face](https://huggingface.co/spaces).
|
| 106 |
+
2. Navigate to your GitHub repository **Settings > Secrets and variables > Actions**.
|
| 107 |
+
3. Add the following repository secrets:
|
| 108 |
+
- `HF_TOKEN`: Your Hugging Face Access Token.
|
| 109 |
- `HF_USERNAME`: Your Hugging Face username.
|
| 110 |
+
- `HF_SPACE_NAME`: The name of the space you created.
|
| 111 |
+
4. Push your code to the `main` branch. The GitHub Action will automatically run tests, build the Docker container, and deploy!
|
| 112 |
+
|
| 113 |
+
---
|
| 114 |
+
*Developed as a demonstration of scalable ML deployment pipelines.*
|