import streamlit as st import torch import torch.nn.functional as f import torch.nn as nn import joblib html_temp = """

Fetal Health App

""" st.markdown(html_temp, unsafe_allow_html=True) st.markdown(f""" """, unsafe_allow_html=True) ## model development class ClassificationModel(nn.Module): def __init__(self, input_dim): super(ClassificationModel, self).__init__() self.fc1 = nn.Linear(input_dim, 16) self.relu = nn.ReLU() self.dropout = nn.Dropout(0.2) self.fc2 = nn.Linear(16,8) self.fc3 = nn.Linear(8, 4) self.fc4 = nn.Linear(4, 2) # 2 outputs for binary classification def forward(self, x): x = f.relu(self.fc1(x)) x = f.relu(self.fc2(x)) x = f.relu(self.fc3(x)) x = self.fc4(x) # No softmax, since CrossEntropyLoss applies it return x torch.manual_seed(42) model=ClassificationModel(input_dim=11) ## loading the models scaler_x=joblib.load('x_sacaler_model.joblib') # Load the entire model model.load_state_dict(torch.load( "fetal_health_model.pth", map_location=torch.device("cpu"))) model.eval() ## inputs col1,col2 =st.columns(2) with col1: # Age age = st.slider("Slide the age of Patient in date wise",min_value=10798,max_value=23713,value=1500) with col2: # gender gender_option =["MALE","Female"] gender=st.selectbox("Select the Gender of the Patient ",gender_option) gender_value = gender_option.index(gender) with col1: # height height = st.slider("Slide Height of the Patient in cm's ",min_value=55,max_value=250,value=75) with col2: # Weight weight = st.slider("Slide the Weight of the Patient in Kg's ",min_value=10.0,max_value=200.0,value=50.0) col1,col2=st.columns(2) with col1: # ap_hi ap_hi =st.slider("Slide the ap high of the Patient ",min_value=-150,max_value=16020,value=15) with col2: # ap_lo ap_lo=st.slider("Slide the ap Low of the Patient ",min_value=-70,max_value=11000,value=200) col1,col2=st.columns(2) with col1: # cholesterol chol_option =["Normal","Above Normal","Well"] chol=st.selectbox("Select the condition of the Patient",chol_option) chol_value=chol_option.index(chol) with col2: glue_option =["Normal","Above Normal","Well"] glue=st.selectbox("Select the Glue of the Patient",glue_option) glue_value=glue_option.index(glue) col1,col2=st.columns(2) with col1: smoke_option =["NO","Yes"] smoke=st.selectbox("Are YOU smoker ",smoke_option) smoke_value=smoke_option.index(smoke) with col2: aclo_option =["NO","Yes"] aclo=st.selectbox(" Are you Alcholic ",aclo_option) aclo_value=aclo_option.index(aclo) active_option =["NO","Yes"] active=st.selectbox("Are you active person ",active_option) active_value=active_option.index(active) if st.button("Enter"): # st.write(age,gender_value,height,weight,ap_hi,ap_lo,chol_value, # glue_value,smoke_value,aclo_value,active_value) values=scaler_x.transform([[age,gender_value,height,weight,ap_hi,ap_lo,chol_value, glue_value,smoke_value,aclo_value,active_value]]) # st.write(values) values_tensor=torch.tensor(values,dtype=torch.float32) with torch.no_grad(): # Disable gradient calculation (faster inference) output = model(values_tensor) # st.write(output.argmax(dim=1)) out_value=output.argmax(dim=1) if out_value ==0: st.write("The Patient is Healthy") else : st.write("The Patient is UN Healthy")