mdadul commited on
Commit
2bbbb9f
·
1 Parent(s): ea6577d

update readme

Browse files
Dockerfile ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # First stage: Install dependencies
2
+ FROM python:3.9-slim as builder
3
+ WORKDIR /app
4
+
5
+ # Copy requirements and install dependencies
6
+ COPY app/requirements.txt /app/requirements.txt
7
+ RUN pip install --no-cache-dir -r /app/requirements.txt
8
+
9
+ # Second stage: Copy app code and define production image
10
+ FROM python:3.9-slim
11
+ WORKDIR /app
12
+ COPY --from=builder /usr/local/lib/python3.9/site-packages /usr/local/lib/python3.9/site-packages
13
+ COPY app /app
14
+
15
+ # Expose port for the API
16
+ EXPOSE 8000
17
+
18
+ # Set environment variables
19
+ ENV PYTHONUNBUFFERED=1
20
+
21
+ # Command to run the FastAPI app
22
+ CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "8000"]
README.md CHANGED
@@ -1,11 +1,28 @@
1
  ---
2
- title: Bangla Spam Detection
3
- emoji: 📚
4
- colorFrom: purple
5
- colorTo: pink
6
- sdk: docker
7
- pinned: false
8
- license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9
  ---
10
 
11
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
1
  ---
2
+ tags:
3
+ - bangla
4
+ - spam-detection
5
+ - text-classification
6
+ - transformers
7
+ - fastapi
8
+ datasets:
9
+ - custom
10
+ metrics:
11
+ - accuracy
12
+ model-index:
13
+ - name: bangla_spam_detection
14
+ results:
15
+ - task:
16
+ type: text-classification
17
+ name: Spam Detection
18
+ dataset:
19
+ name: Custom Dataset
20
+ type: custom
21
+ metrics:
22
+ - type: accuracy
23
+ value: 0.95 # example value
24
  ---
25
 
26
+ # Bangla Spam Detection API
27
+
28
+ This project uses a Hugging Face transformer model to detect spam in Bangla SMS messages...
app/api/v1/endpoints/predict.py ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import APIRouter, HTTPException
2
+ from pydantic import BaseModel
3
+ from app.models.nlp_model import classify_text
4
+
5
+ router = APIRouter()
6
+
7
+ class SMSInput(BaseModel):
8
+ text: str
9
+
10
+ @router.post("/predict")
11
+ async def predict_sms(input: SMSInput):
12
+ try:
13
+ prediction = classify_text(input.text)
14
+ return {"text": input.text, "prediction": prediction}
15
+ except Exception as e:
16
+ raise HTTPException(status_code=500, detail="Model prediction error.")
app/core/config.py ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from pydantic import BaseSettings
2
+
3
+ class Settings(BaseSettings):
4
+ PROJECT_NAME: str = "Bangla Spam Detection API"
5
+ PROJECT_VERSION: str = "1.0.0"
6
+ MODEL_NAME: str = "Bijoy09/bangla_spam_detection"
7
+
8
+ class Config:
9
+ env_file = ".env"
10
+
11
+ settings = Settings()
app/main.py ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from app.api.v1.endpoints import predict
3
+ from app.core.config import settings
4
+
5
+ app = FastAPI(title=settings.PROJECT_NAME, version=settings.PROJECT_VERSION)
6
+
7
+ # Include router for the prediction endpoint
8
+ app.include_router(predict.router, prefix="/api/v1")
app/models/nlp_model.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from app.core.config import settings
3
+
4
+ # Initialize the NLP model pipeline
5
+ pipe = pipeline("text-classification", model=settings.MODEL_NAME)
6
+
7
+ def classify_text(text: str) -> str:
8
+ result = pipe(text)[0]
9
+ return result["label"]
app/requirements.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ fastapi
2
+ uvicorn
3
+ transformers
4
+ torch
5
+ pydantic
6
+ python-dotenv
docker-compose.yml ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ version: "3.8"
2
+
3
+ services:
4
+ api:
5
+ build:
6
+ context: .
7
+ environment:
8
+ - MODEL_NAME=${MODEL_NAME}
9
+ ports:
10
+ - "8000:8000"
11
+ deploy:
12
+ replicas: 3
13
+ update_config:
14
+ parallelism: 2
15
+ networks:
16
+ - app-network
17
+
18
+ networks:
19
+ app-network:
20
+ driver: bridge