Spaces:
Sleeping
Sleeping
File size: 2,932 Bytes
fe306a7 02ebf73 fe306a7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# -*- coding: utf-8 -*-
"""
Created on Tue Jan 3 18:57:20 2023
@author: pauli
"""
import pandas as pd
import pickle
from sklearn.model_selection import train_test_split
from sklearn.svm import SVC
from imblearn.over_sampling import SMOTE
import gradio as gr
import datasets
def make_prediction(age,serum_creatinine,ejection_fraction):
with open("model.pkl", "rb") as f:
svc = pickle.load(f)
preds = svc.predict([[age,serum_creatinine,ejection_fraction]])
if preds == 1:
return "Patient is at high risk of dying from heart failure"
return "Patient is at low risk of dying from heart failure"
age_input = gr.Number(label = "Enter the age of the patient")
#anaemia_input = gr.Radio(["No Anaemia","Anaemia is Present"], type = "index", label ="Does patient have Anaemia?")
#dm_input = gr.Radio(["No DM","DM is Present"], type = "index",label = "Does patient have Diabetes Mellitus (DM)?")
#cpk_input = gr.Number (label = "Enter level of CPK enzyme (mcg)")
cr_input = gr.Number(label = "Enter level of serum creatinine (mg)")
ef_input = gr.Number(label = "Enter ejection fraction (%)")
output = gr.Textbox(label= "Heart Failure Risk:", lines= 3)
with gr.Blocks(css = ".gradio-container {background-color: #10217d} #md {width: 150%} ") as demo:
gr.Markdown(value= """
# **<span style="color:white">Heart Failure Predictor</span>**
""", elem_id="md")
gr.Interface(make_prediction, inputs=[age_input,cr_input,ef_input],
outputs=output, flagging_options=["clinical suspicion is high for heart failure but model says otherwise",
"clinical suspicion is low for heart failure but model says otherwise"])
#css = " div {background-color: red}",
#title = "Heart Failure Predictor")
gr.Markdown("""
## <span style="color:#d7baad">Input Examples</span>
<span style="color:#d7baad">Click on the examples below for a demo of how the app runs.</span>
""")
gr.Examples(
[[49, 1, 30], [65,2.7,30]],
[age_input,cr_input,ef_input], output,
make_prediction,
cache_examples=True)
demo.launch()
#
# app = gr.Interface(make_prediction, inputs=[age_input,anaemia_input,cpk_input, dm_input,
# cr_input,ef_input],
# outputs=output, flagging_options=["clinical suspicion is high for heart failure but model says otherwise",
# "clinical suspicion is low for heart failure but model says otherwise"],
# title = "Heart Failure Predictor",
# css="div {background-color: red}")
# app.launch() |