kmrmanish commited on
Commit
739086d
·
1 Parent(s): 11b4fbc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Diabetes Prediction Web App
4
+ """
5
+
6
+ import numpy as np
7
+ import pickle
8
+ import streamlit as st
9
+
10
+
11
+ # loading the saved model
12
+ loaded_model = pickle.load(open('LogisticRegression_model.pkl', 'rb'))
13
+
14
+
15
+ # creating a function for Prediction
16
+
17
+ def diabetes_prediction(input_data):
18
+
19
+
20
+ # changing the input_data to numpy array
21
+ input_data_as_numpy_array = np.asarray(input_data)
22
+
23
+ # reshape the array as we are predicting for one instance
24
+ input_data_reshaped = input_data_as_numpy_array.reshape(1,-1)
25
+
26
+ prediction = loaded_model.predict(input_data_reshaped)
27
+ print(prediction)
28
+
29
+ if (prediction[0] == 0):
30
+ return 'The person is not diabetic'
31
+ else:
32
+ return 'The person is diabetic'
33
+
34
+
35
+
36
+ def main():
37
+
38
+ # giving a title
39
+ st.title('Diabetes Prediction Web App')
40
+
41
+
42
+ # getting the input data from the user
43
+
44
+ Pregnancies = st.text_input('Number of Pregnancies')
45
+ Glucose = st.text_input('Glucose Level')
46
+ BloodPressure = st.text_input('Blood Pressure Value')
47
+ SkinThickness = st.text_input('Skin Thickness Value')
48
+ Insulin = st.text_input('Insulin Level')
49
+ BMI = st.text_input('BMI Value')
50
+ DiabetesPedigreeFunction = st.text_input('Diabetes Pedigree Function Value')
51
+ Age = st.text_input('Age of the Person')
52
+
53
+
54
+ # code for Prediction
55
+ diagnosis = ''
56
+
57
+ # creating a button for Prediction
58
+
59
+ if st.button('Diabetes Test Result'):
60
+ try:
61
+ # Convert input data to floating-point numbers with error handling
62
+ input_data = [
63
+ float(Pregnancies),
64
+ float(Glucose),
65
+ float(BloodPressure),
66
+ float(SkinThickness),
67
+ float(Insulin),
68
+ float(BMI),
69
+ float(DiabetesPedigreeFunction),
70
+ float(Age)
71
+ ]
72
+ diagnosis = diabetes_prediction(input_data)
73
+ except ValueError as e:
74
+ diagnosis = "Invalid input. Please enter numeric values for all fields."
75
+
76
+ st.success(diagnosis)
77
+
78
+ if __name__ == '__main__':
79
+ main()