Mummia-99 commited on
Commit
2a1f8c2
·
verified ·
1 Parent(s): 4f0dfc1

Upload 3 files

Browse files
Files changed (3) hide show
  1. app.py +109 -0
  2. fetal_health_model.pth +3 -0
  3. x_sacaler_model.joblib +3 -0
app.py ADDED
@@ -0,0 +1,109 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import torch
3
+ import torch.nn.functional as f
4
+ import torch.nn as nn
5
+ import joblib
6
+
7
+ html_temp = """
8
+ <div style="background-color:black;padding:10px">
9
+ <h2 style="color:white;text-align:center;"> Fetal Health App </h2>
10
+ </div>
11
+ """
12
+ st.markdown(html_temp, unsafe_allow_html=True)
13
+ ## model development
14
+ class ClassificationModel(nn.Module):
15
+ def __init__(self, input_dim):
16
+ super(ClassificationModel, self).__init__()
17
+ self.fc1 = nn.Linear(input_dim, 16)
18
+ self.relu = nn.ReLU()
19
+ self.dropout = nn.Dropout(0.2)
20
+ self.fc2 = nn.Linear(16,8)
21
+ self.fc3 = nn.Linear(8, 4)
22
+ self.fc4 = nn.Linear(4, 2) # 2 outputs for binary classification
23
+
24
+ def forward(self, x):
25
+ x = f.relu(self.fc1(x))
26
+ x = f.relu(self.fc2(x))
27
+ x = f.relu(self.fc3(x))
28
+ x = self.fc4(x) # No softmax, since CrossEntropyLoss applies it
29
+ return x
30
+
31
+ torch.manual_seed(42)
32
+ model=ClassificationModel(input_dim=11)
33
+ ## loading the models
34
+
35
+ scaler_x=joblib.load('x_sacaler_model.joblib')
36
+
37
+ # Load the entire model
38
+
39
+ model.load_state_dict(torch.load( "fetal_health_model.pth", map_location=torch.device("cpu")))
40
+ model.eval()
41
+
42
+ ## inputs
43
+ col1,col2 =st.columns(2)
44
+
45
+ with col1:
46
+ # Age
47
+ age = st.slider("Slide the age of Patient in date wise",min_value=10798,max_value=23713,value=1500)
48
+
49
+ with col2:
50
+ # gender
51
+ gender_option =["MALE","Female"]
52
+ gender=st.selectbox("Select the Gender of the Patient ",gender_option)
53
+ gender_value = gender_option.index(gender)
54
+ with col1:
55
+ # height
56
+ height = st.slider("Slide Height of the Patient in cm's ",min_value=55,max_value=250,value=75)
57
+ with col2:
58
+ # Weight
59
+ weight = st.slider("Slide the Weight of the Patient in Kg's ",min_value=10.0,max_value=200.0,value=50.0)
60
+ col1,col2=st.columns(2)
61
+ with col1:
62
+ # ap_hi
63
+ ap_hi =st.slider("Slide the ap high of the Patient ",min_value=-150,max_value=16020,value=15)
64
+ with col2:
65
+ # ap_lo
66
+ ap_lo=st.slider("Slide the ap Low of the Patient ",min_value=-70,max_value=11000,value=200)
67
+ col1,col2=st.columns(2)
68
+ with col1:
69
+ # cholesterol
70
+ chol_option =["Normal","Above Normal","Well"]
71
+ chol=st.selectbox("Select the Gender of the Patient",chol_option)
72
+ chol_value=chol_option.index(chol)
73
+
74
+ with col2:
75
+ glue_option =["Normal","Above Normal","Well"]
76
+ glue=st.selectbox("Select the Glue of the Patient",glue_option)
77
+ glue_value=glue_option.index(glue)
78
+ col1,col2=st.columns(2)
79
+ with col1:
80
+ smoke_option =["NO","Yes"]
81
+ smoke=st.selectbox("Are YOU smoker ",smoke_option)
82
+ smoke_value=smoke_option.index(smoke)
83
+ with col2:
84
+ aclo_option =["NO","Yes"]
85
+ aclo=st.selectbox(" Are you Alcholic ",aclo_option)
86
+ aclo_value=aclo_option.index(aclo)
87
+
88
+ active_option =["NO","Yes"]
89
+ active=st.selectbox("Are you ",active_option)
90
+ active_value=active_option.index(active)
91
+
92
+ if st.button("Enter"):
93
+ # st.write(age,gender_value,height,weight,ap_hi,ap_lo,chol_value,
94
+ # glue_value,smoke_value,aclo_value,active_value)
95
+
96
+ values=scaler_x.transform([[age,gender_value,height,weight,ap_hi,ap_lo,chol_value,
97
+ glue_value,smoke_value,aclo_value,active_value]])
98
+
99
+ # st.write(values)
100
+ values_tensor=torch.tensor(values,dtype=torch.float32)
101
+
102
+ with torch.no_grad(): # Disable gradient calculation (faster inference)
103
+ output = model(values_tensor)
104
+ st.write(output.argmax(dim=1))
105
+ out_value=output.argmax(dim=1)
106
+ if out_value ==0:
107
+ st.write("The Patient is Healthy")
108
+ else :
109
+ st.write("The Patient is UN Healthy")
fetal_health_model.pth ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ec94ef15d340f169173f4744df9d948d7bb5b7f2cd62bd6a623528bfc0569bac
3
+ size 4676
x_sacaler_model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:d9619ec7120481a07f6d94a5b74917da409eb79d493257c440786bad4a0c88e7
3
+ size 863