aryanpareek07's picture
Update app.py
0c04601
raw
history blame
No virus
2.71 kB
import pandas as pd
import numpy as np
import gradio as gr
m = pd.read_pickle(r'Heart_Prediction.pkl')
# Creating Function for getting Predictions
def make_prediction(age,cp,slp,thalachh,O2):
preds = m.predict([[age,cp,slp,thalachh,O2]])
min_age = 29
max_age = 77
min_cp = 0
max_cp = 3
min_slp = 0
max_slp = 2
min_thalachh = 71
max_thalachh = 202
min_O2 = 96.50
max_O2 = 98.60
try:
age = float(age)
cp = float(cp)
slp = float(slp)
thalachh = float(thalachh)
O2 = float(O2)
if min_age <= age <= max_age and min_cp <= cp <= max_cp and min_slp <= slp <= max_slp and min_thalachh <= thalachh <= max_thalachh and min_O2 <= O2 <= max_O2:
if preds == 1:
return '''You have chances 100 % chances of getting an Heart Attack, Consult your doctor immedetly!!'''
return '''Less chances of Heart Attack!!'''
else:
return f"Invalid Parameters.\nEnter valid values only."
except ValueError:
return "Invalid input.\nEnter valid inputs for all the parameters."
#Create the input component for Gradio since we are expecting 5 inputs
age_input = gr.Number(label = "Enter Your Age " , step = None)
cp_input = gr.Number(label = "Enter the cp " , step = None, info= "Chest pain type, 0 = typical type 1, 1 = typical type angina 2 = non-angina pain 3 = asymptomatic")
slp_input = gr.Number(label = "Enter the slp ", step = None, info= "Speech-language pathologists (SLPs)")
thalachh_input = gr.Number(label = "Enter the thalachh ", step = None, info= "The Maximum heart rate achieved by your Heart")
o2_input = gr.Number(label = "Enter the O2 Saturation ", step = None, info= 'This is the blood oxygen level in your report')
# We create the output
output = gr.Textbox(label='Result')
app = gr.Interface(fn = make_prediction,
inputs=[age_input, cp_input, slp_input, thalachh_input, o2_input],
outputs=output,
description= '''Enter all the details asked below and get the predictions of Heart Attack \n\nAnd in case you find any bug related to the app or model please use the button named 'Flag' \n\n\nYou can find Examples below \n\n\n\nwhich are the minimum and maximum values of all parameteres respectivly ''',
# theme=gr.themes.Monochrome(),
theme= gr.themes.Base(),
# theme= gr.themes.Soft(),
title='Heart Attack Predictor ❤️',
examples=[[29,0,0,71,96.50],[77,3,2,202,98.60]],
)
app.launch(auth = ['admin','password'],auth_message='Enter the Username and Password!!')