Skip to content

Commit

Permalink
heart stroke project is added
Browse files Browse the repository at this point in the history
  • Loading branch information
BALAVIGNESHDOSTRIX committed May 25, 2024
1 parent 7702397 commit b7f5d1f
Show file tree
Hide file tree
Showing 7 changed files with 2,145 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# heart_doc
# heart_doc

# Data is extracted from Kaggle
58 changes: 58 additions & 0 deletions backend/main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
from fastapi import FastAPI
import onnxruntime as ort
import numpy as np
from pydantic import BaseModel
import uvicorn
from fastapi.middleware.cors import CORSMiddleware

class HeartStrokeBase(BaseModel):
ST_Slope: float
ChestPainType: float
ExerciseAngina: float
Cholesterol: float
MaxHR: float
Oldpeak: float
Sex: int
FastingBS: float
Age: int
RestingBP: float

origins = ["*"]

app = FastAPI()

app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)

@app.post("/predict")
async def heart_stroke_inference(data: HeartStrokeBase = None):

print(data.dict())
def sigmoid(x):
return 1 / (1 + np.exp(-x))

try:
data = data.dict().values()
data = [x for x in data]
data = np.array(data).astype(np.float32)
data = [list(data)]
model_path = 'HeartNet.onnx'
session = ort.InferenceSession(model_path)
input_name = session.get_inputs()[0].name
output_name = session.get_outputs()[0].name
output = session.run([output_name], {input_name: data})[0]

bin_data = sigmoid(output)
res = np.round(bin_data)
predict_ = "yes" if int(res[0][0]) == 1 else "no"
return {'type': "success", "value": predict_}
except Exception as e:
return {'type': 'error', 'value': str(e)}

if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=8000)
Loading

0 comments on commit b7f5d1f

Please sign in to comment.