mohamedahraf273 commited on
Commit
0234723
·
1 Parent(s): af40251

Add application file

Browse files
Files changed (5) hide show
  1. Dockerfile +16 -0
  2. api.py +20 -0
  3. label_encoder.pkl +3 -0
  4. model.pkl +3 -0
  5. requirements.txt +12 -0
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
2
+ # you will also find guides on how best to write your Dockerfile
3
+
4
+ FROM python:3.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
api.py ADDED
@@ -0,0 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import pickle
2
+
3
+ import numpy as np
4
+ from fastapi import FastAPI
5
+
6
+ app = FastAPI()
7
+
8
+ with open("model.pkl", "rb") as f:
9
+ model = pickle.load(f)
10
+
11
+ with open("label_encoder.pkl", "rb") as f:
12
+ le = pickle.load(f)
13
+
14
+
15
+ @app.post("/predict")
16
+ def predict(embedding: np.ndarray):
17
+ embedding = embedding.reshape(1, -1)
18
+ pred = model.predict(embedding)
19
+ pred_class = le.inverse_transform(pred)[0]
20
+ return {"result": pred_class}
label_encoder.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4ad1489188bcc6e3f9a9650258fe8123e3797930d0b56b178564270e4b1e251f
3
+ size 276
model.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:789a2e60a17d42fd5a46a38af1d40c7274048dd441c93b410377e87897fea0d7
3
+ size 11238840
requirements.txt ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Core Python Utilities
2
+ setuptools
3
+ regex
4
+ packaging
5
+ build
6
+ dm-tree
7
+ scikit-learn
8
+ pandas
9
+ numpy
10
+ xgboost==2.0.3
11
+ fastapi
12
+ uvicorn[standard]