Spaces:
Runtime error
Runtime error
Commit
·
791be40
1
Parent(s):
610e9bc
App and Requirements
Browse files- app.py +93 -0
- requirements.txt +6 -0
app.py
ADDED
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import numpy
|
2 |
+
import gradio as gr
|
3 |
+
import pandas as pd
|
4 |
+
from sklearn.preprocessing import LabelEncoder
|
5 |
+
from sklearn.model_selection import train_test_split
|
6 |
+
from sklearn.preprocessing import StandardScaler
|
7 |
+
from sklearn.metrics import accuracy_score
|
8 |
+
from sklearn.svm import SVC
|
9 |
+
from sklearn.preprocessing import MinMaxScaler
|
10 |
+
def heart(Age,Sex,ChestPainType,RestingBP,Cholesterol,FastingBS,RestingECG,MaxHR,ExerciseAngina,Oldpeak,ST_Slope):
|
11 |
+
d=pd.read_csv("https://raw.githubusercontent.com/akarshsnair/Dataset-cart/main/heart.csv")
|
12 |
+
for col in d.columns:
|
13 |
+
if d[col].dtype == 'object':
|
14 |
+
d[col] = LabelEncoder().fit_transform(d[col])
|
15 |
+
svm=SVC(probability=True)
|
16 |
+
xdf=d.drop("HeartDisease",axis=1)
|
17 |
+
ydf=d["HeartDisease"]
|
18 |
+
x_train,x_test,y_train,y_test=train_test_split(xdf,ydf,test_size=0.35,random_state=20)
|
19 |
+
mms=MinMaxScaler(feature_range=(0,1))
|
20 |
+
x_train=mms.fit_transform(x_train)
|
21 |
+
x_test=mms.fit_transform(x_test)
|
22 |
+
x_train=pd.DataFrame(x_train)
|
23 |
+
x_test=pd.DataFrame(x_test)
|
24 |
+
svm=SVC(probability=True)
|
25 |
+
svm.fit(x_train,y_train)
|
26 |
+
predictions=svm.predict(x_test)
|
27 |
+
data = {'Age':Age,'Sex':Sex,'Chest Pain Type':ChestPainType,'Resting Blood Pressure':RestingBP,'Cholesterol level ':Cholesterol,'Fasting Blood Sugar':FastingBS,'Resting E.C.G':RestingECG,'Maximum Heart Rate achieved ':MaxHR,'Exercise induced Angina ':ExerciseAngina,'Old peak':Oldpeak,'ST_Slope':ST_Slope}
|
28 |
+
index = [0]
|
29 |
+
cust_df = pd.DataFrame(data, index)
|
30 |
+
costpredLog = svm.predict(cust_df)
|
31 |
+
if costpredLog ==0:
|
32 |
+
Prediction = "There is less chance for the patient to catch with heart disease"
|
33 |
+
else:
|
34 |
+
Prediction = "There is more of a chance for the patient to catch heart disease."
|
35 |
+
return Prediction
|
36 |
+
|
37 |
+
|
38 |
+
iface = gr.Interface(fn = heart,
|
39 |
+
|
40 |
+
inputs =['number','number','number','number','number','number','number','number','number','number','number'],
|
41 |
+
|
42 |
+
outputs =['text'],
|
43 |
+
|
44 |
+
title="Onset of heart disease failure prediction",
|
45 |
+
|
46 |
+
description =''' Description
|
47 |
+
Cardiovascular diseases (CVDs) are the number 1 cause of death globally, taking an estimated 17.9 million lives each year, which accounts for 31% of all deaths worlwide.
|
48 |
+
Heart failure is a common event caused by CVDs and this dataset contains 12 features that can be used to predict mortality by heart failure.
|
49 |
+
Most cardiovascular diseases can be prevented by addressing behavioural risk factors such as tobacco use, unhealthy diet and obesity,
|
50 |
+
physical inactivity and harmful use of alcohol using population-wide strategies. People with cardiovascular disease or who are at high cardiovascular risk
|
51 |
+
(due to the presence of one or more risk factors such as hypertension, diabetes, hyperlipidaemia or already established disease)
|
52 |
+
need early detection and management wherein a machine learning model can be of great help.
|
53 |
+
|
54 |
+
More details about the Inputs taken and how they needed to be taken are given below:
|
55 |
+
|
56 |
+
* Age (Your Age)
|
57 |
+
* Sex (Male (1) or Female (0))
|
58 |
+
* Chest pain
|
59 |
+
1) ASY - 0
|
60 |
+
2) ATA - 1
|
61 |
+
3) NAP - 2
|
62 |
+
4) TA - 3
|
63 |
+
* RestingBP - Resting Blood pressure
|
64 |
+
* Cholesterol - Cholesterol level as of now
|
65 |
+
* FastingBS - Fasting blood sugar
|
66 |
+
1) Above 120,Type 1
|
67 |
+
2) Below 120,Type 0
|
68 |
+
* RestingECG
|
69 |
+
1) LVH - 0
|
70 |
+
2) NORMAL - 1
|
71 |
+
3) ST - 2
|
72 |
+
* MaxHR - Is the maximum heart rate recorded
|
73 |
+
* ExerciseAngina - Do you have Angine while you exercise
|
74 |
+
1) No - 0
|
75 |
+
2) Yes - 1
|
76 |
+
* Oldpeak - ST depression induced by exercise relative to rest.
|
77 |
+
* ST_Slope - The ST segment shift relative to exercise-induced increments in heart rate
|
78 |
+
1) Down - 0
|
79 |
+
2) Flat - 1
|
80 |
+
3) UP - 2
|
81 |
+
|
82 |
+
''',
|
83 |
+
|
84 |
+
article=''' This application is made for Hackathon'22
|
85 |
+
|
86 |
+
Through this project, we are looking forward to providing insight into the health of each and every person.
|
87 |
+
The dataset is taken from Kaggle and the link for the dataset is provided here:
|
88 |
+
|
89 |
+
Dataset link as Raw form: https://raw.githubusercontent.com/ADITHYASNAIR2021/Dataset-cart/main/heart.csv
|
90 |
+
|
91 |
+
''')
|
92 |
+
|
93 |
+
iface.launch(debug = True)
|
requirements.txt
ADDED
@@ -0,0 +1,6 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
gradio
|
2 |
+
numpy
|
3 |
+
pandas
|
4 |
+
scikit-learn
|
5 |
+
matplotlib
|
6 |
+
seaborn
|