Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- app_gradio.py +93 -0
- flagged/log.csv +6 -0
- gradio_cached_examples/20/log.csv +3 -0
- gradio_cached_examples/39/log.csv +3 -0
- gradio_cached_examples/60/log.csv +3 -0
- gradio_cached_examples/81/log.csv +3 -0
- model.pkl +3 -0
app_gradio.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# -*- coding: utf-8 -*-
|
2 |
+
"""
|
3 |
+
Created on Tue Jan 3 18:57:20 2023
|
4 |
+
|
5 |
+
@author: pauli
|
6 |
+
"""
|
7 |
+
|
8 |
+
import pandas as pd
|
9 |
+
import pickle
|
10 |
+
from sklearn.model_selection import train_test_split
|
11 |
+
#from sklearn.metrics import accuracy_score, precision_score,recall_score
|
12 |
+
from sklearn.svm import SVC
|
13 |
+
from imblearn.over_sampling import SMOTE
|
14 |
+
import gradio as gr
|
15 |
+
|
16 |
+
|
17 |
+
data = pd.read_csv("C:/Users/pauli/Downloads/heart_failure_clinical_records_dataset.csv")
|
18 |
+
|
19 |
+
Features = list(('age', 'serum_creatinine','ejection_fraction'))
|
20 |
+
|
21 |
+
x = data[Features]
|
22 |
+
y = data["DEATH_EVENT"]
|
23 |
+
|
24 |
+
x_train,x_test,y_train,y_test = train_test_split(x,y, test_size=0.2,shuffle=False)
|
25 |
+
|
26 |
+
smote = SMOTE(sampling_strategy = 'minority', random_state = 2)
|
27 |
+
x_SMOTE, y_SMOTE = smote.fit_resample(x_train,y_train)
|
28 |
+
|
29 |
+
svc = SVC()
|
30 |
+
|
31 |
+
svc.fit(x_SMOTE, y_SMOTE)
|
32 |
+
|
33 |
+
with open("model.pkl", "wb") as f:
|
34 |
+
pickle.dump(svc, f)
|
35 |
+
|
36 |
+
|
37 |
+
def make_prediction(age,serum_creatinine,ejection_fraction):
|
38 |
+
with open("model.pkl", "rb") as f:
|
39 |
+
svc = pickle.load(f)
|
40 |
+
preds = svc.predict([[age,serum_creatinine,ejection_fraction]])
|
41 |
+
if preds == 1:
|
42 |
+
return "Patient is at high risk of dying from heart failure"
|
43 |
+
return "Patient is at low risk of dying from heart failure"
|
44 |
+
|
45 |
+
|
46 |
+
age_input = gr.Number(label = "Enter the age of the patient")
|
47 |
+
#anaemia_input = gr.Radio(["No Anaemia","Anaemia is Present"], type = "index", label ="Does patient have Anaemia?")
|
48 |
+
#dm_input = gr.Radio(["No DM","DM is Present"], type = "index",label = "Does patient have Diabetes Mellitus (DM)?")
|
49 |
+
#cpk_input = gr.Number (label = "Enter level of CPK enzyme (mcg)")
|
50 |
+
cr_input = gr.Number(label = "Enter level of serum creatinine (mg)")
|
51 |
+
ef_input = gr.Number(label = "Enter ejection fraction (%)")
|
52 |
+
|
53 |
+
|
54 |
+
output = gr.Textbox(label= "Heart Failure Risk:", lines= 3)
|
55 |
+
output.style(height='30', rounded= True)
|
56 |
+
|
57 |
+
|
58 |
+
|
59 |
+
with gr.Blocks(css = ".gradio-container {background-color: #10217d} #md {width: 150%} ") as demo:
|
60 |
+
|
61 |
+
gr.Markdown(value= """
|
62 |
+
|
63 |
+
# **<span style="color:white">Heart Failure Predictor</span>**
|
64 |
+
|
65 |
+
""", elem_id="md")
|
66 |
+
|
67 |
+
gr.Interface(make_prediction, inputs=[age_input,cr_input,ef_input],
|
68 |
+
outputs=output, flagging_options=["clinical suspicion is high for heart failure but model says otherwise",
|
69 |
+
"clinical suspicion is low for heart failure but model says otherwise"])
|
70 |
+
#css = " div {background-color: red}",
|
71 |
+
#title = "Heart Failure Predictor")
|
72 |
+
gr.Markdown("""
|
73 |
+
## <span style="color:#d7baad">Input Examples</span>
|
74 |
+
<span style="color:#d7baad">Click on the examples below for a demo of how the app runs.</span>
|
75 |
+
""")
|
76 |
+
gr.Examples(
|
77 |
+
[[49, 1, 30], [65,2.7,30]],
|
78 |
+
[age_input,cr_input,ef_input], output,
|
79 |
+
make_prediction,
|
80 |
+
cache_examples=True)
|
81 |
+
|
82 |
+
|
83 |
+
demo.launch()
|
84 |
+
|
85 |
+
#
|
86 |
+
|
87 |
+
# app = gr.Interface(make_prediction, inputs=[age_input,anaemia_input,cpk_input, dm_input,
|
88 |
+
# cr_input,ef_input],
|
89 |
+
# outputs=output, flagging_options=["clinical suspicion is high for heart failure but model says otherwise",
|
90 |
+
# "clinical suspicion is low for heart failure but model says otherwise"],
|
91 |
+
# title = "Heart Failure Predictor",
|
92 |
+
# css="div {background-color: red}")
|
93 |
+
# app.launch()
|
flagged/log.csv
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Enter the age of the patient,Does patient have Anaemia?,Enter level of CPK enzyme (mcg),Does patient have Diabetes Mellitus (DM),Enter level of serum creatinine (mg),Enter ejection fraction (%),Heart Failure Risk:,flag,username,timestamp
|
2 |
+
40,No Anaemia,23,No DM,0.5,80,Patient is at high risk of dying from heart failure,clinical suspicion is low for heart failure but model says otherwise,,2023-01-04 01:05:23.669526
|
3 |
+
40,No Anaemia,23,No DM,0.5,80,Patient is at high risk of dying from heart failure,clinical suspicion is low for heart failure but model says otherwise,,2023-01-04 01:05:26.293978
|
4 |
+
40,No Anaemia,23,No DM,0.5,80,Patient is at high risk of dying from heart failure,clinical suspicion is low for heart failure but model says otherwise,,2023-01-04 01:05:29.574623
|
5 |
+
40,No Anaemia,23,No DM,0.5,80,Patient is at high risk of dying from heart failure,clinical suspicion is low for heart failure but model says otherwise,,2023-01-04 01:05:31.546521
|
6 |
+
,,,,,,,clinical suspicion is low for heart failure but model says otherwise,,2023-01-04 01:05:36.083167
|
gradio_cached_examples/20/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Heart Failure Risk:,flag,username,timestamp
|
2 |
+
Patient is at low risk of dying from heart failure,,,2023-01-04 13:48:27.880651
|
3 |
+
Patient is at high risk of dying from heart failure,,,2023-01-04 13:48:27.884651
|
gradio_cached_examples/39/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Heart Failure Risk:,flag,username,timestamp
|
2 |
+
Patient is at high risk of dying from heart failure,,,2023-01-04 13:34:35.851691
|
3 |
+
Patient is at high risk of dying from heart failure,,,2023-01-04 13:34:35.859691
|
gradio_cached_examples/60/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Heart Failure Risk:,flag,username,timestamp
|
2 |
+
Patient is at high risk of dying from heart failure,,,2023-01-04 13:38:40.425607
|
3 |
+
Patient is at high risk of dying from heart failure,,,2023-01-04 13:38:40.430606
|
gradio_cached_examples/81/log.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
Heart Failure Risk:,flag,username,timestamp
|
2 |
+
Patient is at low risk of dying from heart failure,,,2023-01-04 13:42:46.476890
|
3 |
+
Patient is at high risk of dying from heart failure,,,2023-01-04 13:42:46.481893
|
model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:499139aa7f03f060bc8d3a7f89a010a862364794fde294968307f99d08571258
|
3 |
+
size 10809
|