Mummia-99 commited on
Commit
9f51c3f
·
verified ·
1 Parent(s): 4555357

Upload 5 files

Browse files
Fetal_helath_notebook.ipynb ADDED
The diff for this file is too large to render. See raw diff
 
app.py ADDED
@@ -0,0 +1,117 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, 256)
18
+ self.relu = nn.ReLU()
19
+ self.dropout = nn.Dropout(0.2)
20
+ self.fc2 = nn.Linear(256,128)
21
+ self.fc3 = nn.Linear(128, 64)
22
+ self.fc4 = nn.Linear(64, 64)
23
+ self.fc5 = nn.Linear(64, 32)
24
+ self.fc6 = nn.Linear(32 , 16)
25
+ self.fc7 = nn.Linear(16, 8)
26
+ self.fc8 = nn.Linear(8, 2) # 2 outputs for binary classification
27
+
28
+ def forward(self, x):
29
+ x = f.relu(self.fc1(x))
30
+ x = f.relu(self.fc2(x))
31
+ x = f.relu(self.fc3(x))
32
+ x = f.relu(self.fc4(x))
33
+ x = f.relu(self.fc5(x))
34
+ x = f.relu(self.fc6(x))
35
+ x = f.relu(self.fc7(x))
36
+ x = self.fc8(x) # No softmax, since CrossEntropyLoss applies it
37
+ return x
38
+
39
+ torch.manual_seed(42)
40
+ model=ClassificationModel(input_dim=11)
41
+ ## loading the models
42
+
43
+ scaler_x=joblib.load('x_sacaler_model.joblib')
44
+
45
+ # Load the entire model
46
+
47
+ model.load_state_dict(torch.load( "fetal_health_model.pth", map_location=torch.device("cpu")))
48
+ model.eval()
49
+
50
+ ## inputs
51
+ col1,col2 =st.columns(2)
52
+
53
+ with col1:
54
+ # Age
55
+ age = st.slider("Slide the age of Patient in date wise",min_value=10798,max_value=23713,value=1500)
56
+
57
+ with col2:
58
+ # gender
59
+ gender_option =["MALE","Female"]
60
+ gender=st.selectbox("Select the Gender of the Patient ",gender_option)
61
+ gender_value = gender_option.index(gender)
62
+ with col1:
63
+ # height
64
+ height = st.slider("Slide Height of the Patient in cm's ",min_value=55,max_value=250,value=75)
65
+ with col2:
66
+ # Weight
67
+ weight = st.slider("Slide the Weight of the Patient in Kg's ",min_value=10.0,max_value=200.0,value=50.0)
68
+ col1,col2=st.columns(2)
69
+ with col1:
70
+ # ap_hi
71
+ ap_hi =st.slider("Slide the ap high of the Patient ",min_value=-150,max_value=16020,value=15)
72
+ with col2:
73
+ # ap_lo
74
+ ap_lo=st.slider("Slide the ap Low of the Patient ",min_value=-70,max_value=11000,value=200)
75
+ col1,col2=st.columns(2)
76
+ with col1:
77
+ # cholesterol
78
+ chol_option =["Normal","Above Normal","Well"]
79
+ chol=st.selectbox("Select the Gender of the Patient",chol_option)
80
+ chol_value=chol_option.index(chol)
81
+
82
+ with col2:
83
+ glue_option =["Normal","Above Normal","Well"]
84
+ glue=st.selectbox("Select the Glue of the Patient",glue_option)
85
+ glue_value=glue_option.index(glue)
86
+ col1,col2=st.columns(2)
87
+ with col1:
88
+ smoke_option =["NO","Yes"]
89
+ smoke=st.selectbox("Are YOU smoker ",smoke_option)
90
+ smoke_value=smoke_option.index(smoke)
91
+ with col2:
92
+ aclo_option =["NO","Yes"]
93
+ aclo=st.selectbox(" Are you Alcholic ",aclo_option)
94
+ aclo_value=aclo_option.index(aclo)
95
+
96
+ active_option =["NO","Yes"]
97
+ active=st.selectbox("Are you ",active_option)
98
+ active_value=active_option.index(active)
99
+
100
+ if st.button("Enter"):
101
+ # st.write(age,gender_value,height,weight,ap_hi,ap_lo,chol_value,
102
+ # glue_value,smoke_value,aclo_value,active_value)
103
+
104
+ values=scaler_x.transform([[age,gender_value,height,weight,ap_hi,ap_lo,chol_value,
105
+ glue_value,smoke_value,aclo_value,active_value]])
106
+
107
+ # st.write(values)
108
+ values_tensor=torch.tensor(values,dtype=torch.float32)
109
+
110
+ with torch.no_grad(): # Disable gradient calculation (faster inference)
111
+ output = model(values_tensor)
112
+ st.write(output.argmax(dim=1))
113
+ out_value=output.argmax(dim=1)
114
+ if out_value ==0:
115
+ st.write("The Patient is Healthy")
116
+ else :
117
+ 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:c103d9f3f6b4d0c4774d7bebfb14abb7739ee9840df814f05d4c187c729a2940
3
+ size 210050
requirements.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ joblib==1.2.0
2
+ matplotlib==3.7.1
3
+ matplotlib-inline==0.1.6
4
+ numpy==1.26.4
5
+ pandas==1.5.3
6
+ scikit-learn==1.6.1
7
+ streamlit==1.41.1
8
+ torch==2.6.0
9
+ dill==0.3.6
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