Spaces:
Running
Running
contact.nampham.work
commited on
Commit
•
5a648b0
1
Parent(s):
f5a5de6
first upload
Browse files- .env +0 -0
- Dockerfile +11 -0
- api/__pycache__/main.cpython-310.pyc +0 -0
- api/main.py +53 -0
- models/model.pkl +3 -0
- requirements.txt +7 -0
.env
ADDED
File without changes
|
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10-slim
|
2 |
+
|
3 |
+
RUN apt update && apt install -y default-jdk
|
4 |
+
|
5 |
+
WORKDIR /app
|
6 |
+
COPY . .
|
7 |
+
RUN python -m pip install --upgrade pip
|
8 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
9 |
+
RUN echo 'export PATH="/root/.local/bin:$PATH"' >> /root/.bashrc
|
10 |
+
|
11 |
+
CMD ["uvicorn", "--host", "0.0.0.0", "--port", "7860", "--app-dir=api", "--reload", "--reload-dir", "api", "main:app"]
|
api/__pycache__/main.cpython-310.pyc
ADDED
Binary file (1.88 kB). View file
|
|
api/main.py
ADDED
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import joblib
|
2 |
+
import pandas as pd
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from fastapi.encoders import jsonable_encoder
|
5 |
+
from loguru import logger
|
6 |
+
from pydantic import BaseModel
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
class Diabetes_measures(BaseModel):
|
11 |
+
Pregnancies: int = 6 # Number of times pregnant
|
12 |
+
Glucose: int = (
|
13 |
+
148 # Plasma glucose concentration a 2 hours in an oral glucose tolerance test
|
14 |
+
)
|
15 |
+
BloodPressure: int = 72 # Diastolic blood pressure (mm Hg)
|
16 |
+
SkinThickness: int = 35 # Triceps skin fold thickness (mm)
|
17 |
+
Insulin: int = 0 # 2-Hour serum insulin
|
18 |
+
BMI: float = 33.6 # Body mass index
|
19 |
+
DiabetesPedigreeFunction: float = 0.627
|
20 |
+
Age: int = 50 # Age (years)
|
21 |
+
|
22 |
+
model = joblib.load('./models/model.pkl')
|
23 |
+
|
24 |
+
@app.get("/")
|
25 |
+
def check_health():
|
26 |
+
return {"Status": "Hello World!"}
|
27 |
+
|
28 |
+
cache = {}
|
29 |
+
|
30 |
+
@app.post("/predict")
|
31 |
+
def predict(data: Diabetes_measures):
|
32 |
+
logger.info('Making predictions...')
|
33 |
+
logger.info(data)
|
34 |
+
logger.info(jsonable_encoder(data))
|
35 |
+
logger.info(pd.DataFrame(jsonable_encoder(data), index=[0]))
|
36 |
+
result = model.predict(pd.DataFrame(jsonable_encoder(data), index=[0]))[0]
|
37 |
+
|
38 |
+
return {'result': ['Normal', 'Diabetes'][result]}
|
39 |
+
|
40 |
+
@app.post("/predict_cache")
|
41 |
+
def predict_cache(data: Diabetes_measures):
|
42 |
+
if (str(data)) in cache:
|
43 |
+
logger.info("Getting result from cache!")
|
44 |
+
return cache[str(data)]
|
45 |
+
else:
|
46 |
+
logger.info('Making preidictions...')
|
47 |
+
logger.info(data)
|
48 |
+
logger.info(jsonable_encoder(data))
|
49 |
+
logger.info(pd.DataFrame(jsonable_encoder(data), index=[0]))
|
50 |
+
result = model.predict(pd.DataFrame(jsonable_encoder(data), index=[0]))[0]
|
51 |
+
cache[str(data)] = ["Normal", "Diabetes"][result]
|
52 |
+
|
53 |
+
return {"result": ['Normal', "Diabetes"][result]}
|
models/model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:1f78c7d34d3e5f7821e9dc329faba664c092fc2f5dbcf307e2b484c978e60ee3
|
3 |
+
size 37953
|
requirements.txt
ADDED
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
pandas
|
2 |
+
numpy
|
3 |
+
loguru
|
4 |
+
fastapi == 0.111.0
|
5 |
+
uvicorn
|
6 |
+
urllib3
|
7 |
+
catboost
|