Jakaria
commited on
Commit
·
83bce7e
1
Parent(s):
bde6f52
Add Bangla model API
Browse files- Dockerfile +10 -0
- app.py +31 -0
- banglish_label_encoder.pkl +3 -0
- banglish_tfid.pkl +3 -0
- requirements.txt +8 -0
- svm_model.pkl +3 -0
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
From python:3.9
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
|
| 5 |
+
COPY requirements.txt .
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
COPY . .
|
| 9 |
+
|
| 10 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from fastapi import FastAPI
|
| 2 |
+
from pydantic import BaseModel
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
app = FastAPI()
|
| 6 |
+
|
| 7 |
+
class PredictRequest(BaseModel):
|
| 8 |
+
text: str
|
| 9 |
+
|
| 10 |
+
# Load model and vectorizer
|
| 11 |
+
model = joblib.load("svm_model.pkl")
|
| 12 |
+
vectorizer = joblib.load("banglish_tfid.pkl")
|
| 13 |
+
label_encoder = joblib.load("banglish_label_encoder.pkl")
|
| 14 |
+
|
| 15 |
+
@app.get("/")
|
| 16 |
+
def root():
|
| 17 |
+
return {"message": "Welcome to the Banglish model API endpoint"}
|
| 18 |
+
|
| 19 |
+
@app.post("/predict")
|
| 20 |
+
def predict(request: PredictRequest):
|
| 21 |
+
vect = vectorizer.transform([request.text])
|
| 22 |
+
pred = model.predict(vect) # returns encoded int (0 or 1)
|
| 23 |
+
label = label_encoder.inverse_transform(pred) # convert back to "No" or "Yes"
|
| 24 |
+
|
| 25 |
+
# New mapping
|
| 26 |
+
mapping = {
|
| 27 |
+
"No": "Not Hate",
|
| 28 |
+
"Yes": "Hate Speech Detected"
|
| 29 |
+
}
|
| 30 |
+
|
| 31 |
+
return {"prediction": mapping[label[0]]}
|
banglish_label_encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:ba4c216df954c95c4862d1e9b45148afdf7248b9ea0bcc3f26e7f34478396645
|
| 3 |
+
size 483
|
banglish_tfid.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:dde4d4c7c034cd5a53be3f6d6c5cb273d11031d9f0f006b556739cc3344b9adb
|
| 3 |
+
size 564649
|
requirements.txt
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
scikit-learn==1.2.2
|
| 4 |
+
|
| 5 |
+
numpy==1.24.4
|
| 6 |
+
joblib==1.2.0
|
| 7 |
+
|
| 8 |
+
|
svm_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:54932761a59f56ecda8eb5a1eea35bd024f1f39d7a936585f5048aaca72e7aa4
|
| 3 |
+
size 354907
|