File size: 2,757 Bytes
72ca364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
63c1eb8
72ca364
 
63c1eb8
72ca364
 
63c1eb8
72ca364
 
63c1eb8
72ca364
 
63c1eb8
72ca364
 
63c1eb8
72ca364
 
63c1eb8
72ca364
 
63c1eb8
72ca364
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
import streamlit as st 
import pandas as pd 
import numpy as np 
import pickle
from PIL import Image

def run():

    # membuat title
    st.title('Heart Disease Prediction')

    # membuat subheader
    st.subheader('Data Form Input Heart Disease Classification')

    # menambahkan gambar 
    image = Image.open('heart_disease_1.jpeg')
    st.image(image, caption = 'Heart Disease')

    with st.form('Form Heart Disease Prediction'):
    
        # field age
        age = st.number_input('Age', min_value=18, max_value=90, help='Usia')

        # field gender
        gender = st.number_input('Gender', min_value=0, max_value=1, help='Jenis kelamin(1:Laki-laki, 2:Perempuan)')

        # field impluse
        impluse = st.number_input('Impluse', min_value=50 , max_value=200, help='Detak jantung')

        # field pressurehight
        pressurehight = st.number_input('pressurehight', min_value=60 , max_value=250, help='Sistolik (Tekanan darah saat jantung berkontraksi/berdetak)')

        # field pressurelow
        pressurelow = st.number_input('pressurelow', min_value=60, max_value=250, help='Diastolik (tekanan darah saat jantung beristirahat/diantara detak)')

        # field glucose
        glucose = st.number_input('glucose', min_value=50, max_value=370, help='Kadar gula darah')

        # field kcm
        kcm = st.number_input('kcm', min_value=24, max_value=500, help='Test CK-MB (test pendeteksi enzim kreatin kinase)')

        # field troponin
        troponin = st.number_input('troponin', min_value=1, max_value=500, help='Test troponin (test kadar troponin/protein yang dilepaskan jika terjadi kerusakan jantung)')

        # submit button
        submitted = st.form_submit_button('Predict')


    # inference
    # load all files
    
    with open('scaler.pkl', 'rb') as file_1:
        scaler = pickle.load(file_1)
    with open('model.pkl', 'rb') as file_2:
        model = pickle.load(file_2)

    
    data_inf = {
        'age' : age,
        'gender' : gender,
        'impluse' : impluse,
        'pressurehight' : pressurehight,
        'pressurelow' : pressurelow,
        'glucose' : glucose,
        'kcm' : kcm,
        'troponin' : troponin
    }

    # memasukkan data inference ke dataframe

    data_inf = pd.DataFrame([data_inf])
    st.dataframe(data_inf)

    # logic ketika predict button ditekan
    if submitted:
        data_inf_drop = data_inf.drop(['gender', 'impluse', 'pressurehight', 'pressurelow', 'glucose'], axis=1)

        data_inf_scaled = scaler.transform(data_inf_drop)

    # predict
        y_pred_inf = model.predict(data_inf_scaled)
        st.write('## Heart Disease :', str(int(y_pred_inf)))
        st.write('### Positive : 1, Negative : 2')

if __name__ == '__main__':
    run()