Spaces:
Sleeping
Sleeping
ahmedmbutt
commited on
Commit
β’
27f9342
1
Parent(s):
d6a890c
Add application file
Browse files- Dockerfile +13 -0
- README.md +3 -3
- app.py +59 -0
- requirements.txt +3 -0
- svm.pkl +3 -0
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
|
5 |
+
WORKDIR /app
|
6 |
+
|
7 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
8 |
+
|
9 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
10 |
+
|
11 |
+
COPY --chown=user . /app
|
12 |
+
|
13 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
---
|
2 |
title: Heart Disease Prediction
|
3 |
-
emoji:
|
4 |
-
colorFrom:
|
5 |
-
colorTo:
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
|
|
1 |
---
|
2 |
title: Heart Disease Prediction
|
3 |
+
emoji: π«
|
4 |
+
colorFrom: red
|
5 |
+
colorTo: blue
|
6 |
sdk: docker
|
7 |
pinned: false
|
8 |
---
|
app.py
ADDED
@@ -0,0 +1,59 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
import pandas as pd
|
4 |
+
from scipy.stats import boxcox
|
5 |
+
from joblib import load
|
6 |
+
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
|
11 |
+
class HeartModel(BaseModel):
|
12 |
+
age: int
|
13 |
+
sex: int
|
14 |
+
trestbps: int
|
15 |
+
chol: int
|
16 |
+
fbs: int
|
17 |
+
thalach: int
|
18 |
+
exang: int
|
19 |
+
oldpeak: float
|
20 |
+
slope: int
|
21 |
+
ca: int
|
22 |
+
cp_1: bool
|
23 |
+
cp_2: bool
|
24 |
+
cp_3: bool
|
25 |
+
restecg_1: bool
|
26 |
+
restecg_2: bool
|
27 |
+
thal_1: bool
|
28 |
+
thal_2: bool
|
29 |
+
thal_3: bool
|
30 |
+
|
31 |
+
|
32 |
+
@app.get("/")
|
33 |
+
def read_root():
|
34 |
+
return {"Heart": "Prediction"}
|
35 |
+
|
36 |
+
|
37 |
+
@app.post("/predict")
|
38 |
+
def read_item(data: HeartModel):
|
39 |
+
lambdas = {
|
40 |
+
"age": 1.1884623210915386,
|
41 |
+
"trestbps": -0.566961719937906,
|
42 |
+
"chol": -0.12552647234590764,
|
43 |
+
"thalach": 2.4454557922261086,
|
44 |
+
"oldpeak": 0.17759774936241574,
|
45 |
+
}
|
46 |
+
|
47 |
+
with open("svm.pkl", "rb") as f:
|
48 |
+
clf = load(f)
|
49 |
+
|
50 |
+
data = data.dict()
|
51 |
+
data["oldpeak"] = data["oldpeak"] + 0.001
|
52 |
+
for col in lambdas.keys():
|
53 |
+
if data[col] > 0:
|
54 |
+
data[col] = boxcox(data[col], lmbda=lambdas[col])
|
55 |
+
|
56 |
+
data = pd.DataFrame([data])
|
57 |
+
|
58 |
+
target = clf.predict(data)
|
59 |
+
return {"target": target[0].item()}
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
|
2 |
+
fastapi
|
3 |
+
uvicorn[standard]
|
svm.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:42c1b7fbc6c9e31114f0dff8811a3bc6e12cec431309c1402cac5aee8f6d3795
|
3 |
+
size 39290
|