Spaces:
Runtime error
Runtime error
aryanpareek07
commited on
Commit
•
9a943a1
1
Parent(s):
ff59dd4
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
m = pd.read_pickle(r'Heart_Prediction.pkl')
|
5 |
+
# Creating Function for getting Predictions
|
6 |
+
def make_prediction(age,cp,slp,thalachh,O2):
|
7 |
+
|
8 |
+
preds = m.predict([[age,cp,slp,thalachh,O2]])
|
9 |
+
min_age = 29
|
10 |
+
max_age = 77
|
11 |
+
min_cp = 0
|
12 |
+
max_cp = 3
|
13 |
+
min_slp = 0
|
14 |
+
max_slp = 2
|
15 |
+
min_thalachh = 71
|
16 |
+
max_thalachh = 202
|
17 |
+
min_O2 = 96.50
|
18 |
+
max_O2 = 98.60
|
19 |
+
|
20 |
+
try:
|
21 |
+
age = float(age)
|
22 |
+
cp = float(cp)
|
23 |
+
slp = float(slp)
|
24 |
+
thalachh = float(thalachh)
|
25 |
+
O2 = float(O2)
|
26 |
+
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:
|
27 |
+
if preds == 1:
|
28 |
+
return '''You have chances 100 % chances of getting an Heart Attack, Consult your doctor immedetly!!'''
|
29 |
+
return '''Less chances of Heart Attack!!'''
|
30 |
+
else:
|
31 |
+
return f"Invalid Parameters.\nEnter valid values only."
|
32 |
+
except ValueError:
|
33 |
+
return "Invalid input.\nEnter valid inputs for all the parameters."
|
34 |
+
|
35 |
+
|
36 |
+
#Create the input component for Gradio since we are expecting 5 inputs
|
37 |
+
|
38 |
+
age_input = gr.Number(label = "Enter Your Age " , step = None)
|
39 |
+
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")
|
40 |
+
slp_input = gr.Number(label = "Enter the slp ", step = None, info= "Speech-language pathologists (SLPs)")
|
41 |
+
thalachh_input = gr.Number(label = "Enter the thalachh ", step = None, info= "The Maximum heart rate achieved by your Heart")
|
42 |
+
o2_input = gr.Number(label = "Enter the O2 Saturation ", step = None, info= 'This is the blood oxygen level in your report')
|
43 |
+
|
44 |
+
# We create the output
|
45 |
+
output = gr.Textbox(label='Result')
|
46 |
+
|
47 |
+
app = gr.Interface(fn = make_prediction,
|
48 |
+
inputs=[age_input, cp_input, slp_input, thalachh_input, o2_input],
|
49 |
+
outputs=output,
|
50 |
+
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 ''',
|
51 |
+
# theme=gr.themes.Monochrome(),
|
52 |
+
theme= gr.themes.Base(),
|
53 |
+
# theme= gr.themes.Soft(),
|
54 |
+
title='Heart Attack Predictor ❤️',
|
55 |
+
examples=[[29,0,0,71,96.50],[77,3,2,202,98.60]],
|
56 |
+
)
|
57 |
+
app.launch(auth = ['admin','password'],auth_message='Enter the Username and Password!!',share= True)
|