-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
112 lines (69 loc) · 2.71 KB
/
app.py
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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# -*- coding: utf-8 -*-
"""
Created on Sat Mar 30 22:08:00 2024
@author: aman0
"""
import numpy as np
import pickle
import streamlit as st
from streamlit_option_menu import option_menu
# creating a function for Prediction
def diabetes_prediction(input_data):
# changing the input_data to numpy array
input_data_as_numpy_array = np.asarray(input_data)
# reshape the array as we are predicting for one instance
input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
prediction = loaded_model.predict(input_data_reshaped)
print(prediction)
if (prediction[0] == 0):
return 'The person is not diabetic'
else:
return 'The person is diabetic'
# Set page configuration
st.set_page_config(page_title="Health Assistant",
layout="wide",
page_icon="🧑⚕️")
# loading the saved model
loaded_model = pickle.load(open('trained_model.sav', 'rb'))
# sidebar for navigation
with st.sidebar:
selected = option_menu('Multiple Disease Prediction System',
['Diabetes Prediction'],
menu_icon='hospital-fill',
icons=['activity'],
default_index=0)
# Diabetes Prediction Page
if selected == 'Diabetes Prediction':
# page title
st.title('Diabetes Prediction using ML')
# getting the input data from the user
col1, col2, col3 = st.columns(3)
with col1:
Pregnancies = st.text_input('Number of Pregnancies')
with col2:
Glucose = st.text_input('Glucose Level')
with col3:
BloodPressure = st.text_input('Blood Pressure value')
with col1:
SkinThickness = st.text_input('Skin Thickness value')
with col2:
Insulin = st.text_input('Insulin Level')
with col3:
BMI = st.text_input('BMI value')
with col1:
DiabetesPedigreeFunction = st.text_input('Diabetes Pedigree Function value')
with col2:
Age = st.text_input('Age of the Person')
# code for Prediction
diab_diagnosis = ''
# creating a button for Prediction
if st.button('Diabetes Test Result'):
user_input = [Pregnancies, Glucose, BloodPressure, SkinThickness, Insulin,
BMI, DiabetesPedigreeFunction, Age]
user_input = [float(x) for x in user_input]
diab_prediction = loaded_model.predict([user_input])
if diab_prediction[0] == 1:
diab_diagnosis = 'The person is diabetic'
else:
diab_diagnosis = 'The person is not diabetic'
st.success(diab_diagnosis)