Jakaria commited on
Commit ·
889ca35
1
Parent(s): 5a850ef
first commit
Browse files- Dockerfile +10 -0
- app.py +25 -0
- label_encoder.pkl +3 -0
- language_tfid.pkl +3 -0
- requirements.txt +6 -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,25 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 + vectorizer + label encoder
|
| 11 |
+
model = joblib.load("svm_model.pkl")
|
| 12 |
+
vectorizer = joblib.load("language_tfid.pkl")
|
| 13 |
+
label_encoder = joblib.load("label_encoder.pkl")
|
| 14 |
+
|
| 15 |
+
@app.get("/")
|
| 16 |
+
def root():
|
| 17 |
+
return {"message": "Language Identification API"}
|
| 18 |
+
|
| 19 |
+
@app.post("/predict")
|
| 20 |
+
def predict(request: PredictRequest):
|
| 21 |
+
vect = vectorizer.transform([request.text])
|
| 22 |
+
pred = model.predict(vect)
|
| 23 |
+
label = label_encoder.inverse_transform(pred)[0]
|
| 24 |
+
|
| 25 |
+
return {"prediction": label}
|
label_encoder.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f57c0651ef8591e5c1a156c9b0e2544876542761930c746091b6a10da118c64b
|
| 3 |
+
size 502
|
language_tfid.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9425dfde7d5a2e206a6ce971f975ed30919ea563150ebe78c7d65e9505e0003a
|
| 3 |
+
size 2510787
|
requirements.txt
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn
|
| 3 |
+
scikit-learn==1.2.2
|
| 4 |
+
|
| 5 |
+
numpy==1.24.4
|
| 6 |
+
joblib==1.2.0
|
svm_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a10fec1b80bae7744d440e0819919e58f9bfd7cffbf8b491540a4ea9b2414258
|
| 3 |
+
size 191331
|