Sadeep Sachintha commited on
Commit
8fae7b4
·
1 Parent(s): 586f9cf

docs: overhaul README with enhanced formatting, project badges, and detailed deployment guides

Browse files
Files changed (1) hide show
  1. README.md +92 -54
README.md CHANGED
@@ -1,76 +1,114 @@
1
- # Sinhala NLP API Deployment
2
 
3
- This project demonstrates the deployment of a Sinhala NLP (Sentiment Analysis) model as a scalable cloud-based API using FastAPI, Docker, and Hugging Face Spaces. It effectively combines AI model serving, Backend development, and DevOps practices.
 
 
 
 
4
 
5
- ## Features
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
- ## Tech Stack
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
- ## Local Setup
20
 
21
- ### 1. Clone the repository
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
22
  ```bash
23
- git clone <your-repo-url>
 
24
  cd "NLP + Deployment"
25
- ```
26
 
27
- ### 2. Run with Docker (Recommended)
28
- ```bash
29
  docker build -t sinhala-nlp-api .
 
 
30
  docker run -p 7860:7860 sinhala-nlp-api
31
  ```
32
- The API will be available at `http://localhost:7860`.
33
 
34
- ### 3. Run with Python Virtual Environment
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
- ## API Endpoints
 
 
43
 
44
- ### 1. Root Endpoint
45
- - **URL**: `/`
46
- - **Method**: `GET`
47
- - **Response**: Welcome message.
 
 
 
 
 
 
48
 
49
  ### 2. Predict Sentiment
50
- - **URL**: `/predict`
51
- - **Method**: `POST`
52
- - **Body**: JSON containing Sinhala text.
53
- ```json
54
- {
55
- "text": "මෙය ඉතා හොඳ නිර්මාණයක්."
56
- }
57
- ```
58
- - **Response**: JSON containing the sentiment label and score.
59
- ```json
60
- {
61
- "label": "LABEL_1",
62
- "score": 0.987654321
63
- }
64
- ```
65
- > *Note: Model labels might vary (e.g., `LABEL_0` for Negative, `LABEL_1` for Positive, or explicit strings like `Positive`, depending on the specific model used).*
66
-
67
- ## CI/CD Deployment
68
- This repository is configured with a GitHub Actions workflow `.github/workflows/deploy.yml`.
69
- To enable automatic deployment to your Hugging Face Space:
70
- 1. Create a **Docker Space** on Hugging Face.
71
- 2. Go to your GitHub Repository Settings > Secrets and variables > Actions.
72
- 3. Add the following Repository Secrets:
73
- - `HF_TOKEN`: Your Hugging Face Access Token (with Write permissions).
 
74
  - `HF_USERNAME`: Your Hugging Face username.
75
- - `HF_SPACE_NAME`: The name of the Space you created.
76
- 4. Any push to the `main` branch will automatically run tests and deploy to your Space.
 
 
 
 
1
+ # 🚀 Sinhala NLP Model Deployment (Cloud-Based API)
2
 
3
+ [![FastAPI](https://img.shields.io/badge/FastAPI-005571?style=for-the-badge&logo=fastapi)](https://fastapi.tiangolo.com/)
4
+ [![Docker](https://img.shields.io/badge/docker-%230db7ed.svg?style=for-the-badge&logo=docker&logoColor=white)](https://www.docker.com/)
5
+ [![Hugging Face](https://img.shields.io/badge/%F0%9F%A4%97%20Hugging%20Face-Spaces-blue?style=for-the-badge)](https://huggingface.co/)
6
+ [![GitHub Actions](https://img.shields.io/badge/github%20actions-%232671E5.svg?style=for-the-badge&logo=githubactions&logoColor=white)](https://github.com/features/actions)
7
+ [![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)](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.*