shubham680 commited on
Commit
5a0e16a
·
verified ·
1 Parent(s): 6acd76e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +146 -0
app.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import pickle
3
+ import sklearn
4
+ from sklearn.preprocessing import RobustScaler, OneHotEncoder, LabelEncoder
5
+ from sklearn.neighbors import KNeighborsClassifier
6
+ import pandas as pd
7
+ import numpy as np
8
+ import matplotlib.pyplot as plt
9
+
10
+
11
+
12
+ # st.markdown("""
13
+ # <style>
14
+ # .stApp {
15
+ # background-image: url('https://huggingface.co/spaces/shubham680/DiabetesPrediction/resolve/main/bg.jpg');
16
+ # background-size: cover;
17
+ # background-repeat: no-repeat;
18
+ # background-attachment: fixed;
19
+ # }
20
+ # .stTitle {
21
+ # color: #ffffff;
22
+ # font-size: 36px;
23
+ # font-weight: bold;
24
+ # text-align: center;
25
+ # }
26
+ # </style>
27
+ # """, unsafe_allow_html=True)
28
+
29
+ st.title("Introvert/Extrovert Prediction App")
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+
38
+
39
+ #with st.sidebar:
40
+ #st.header("Patient Information")
41
+ time_spent = st.number_input("Enter Time_spent_Alone:",min_value=0,max_value=11,step=0.5)
42
+ stage_fear = st.selectbox("Stage Fear:",["Yes","No"])
43
+ social_event = st.number_input("Enter Social Event Frequency:",min_value=0,max_value=10,step=1)
44
+ going_outside = st.number_input("Enter Going Frequency:",min_value=0,max_value=7,step=1)
45
+ drained = st.selectbox("Drained After Socializing:",["Yes","No"])
46
+ friends = st.number_input("Enter Friend Circle Size:",min_value=0,max_value=15,step=1)
47
+ post_frequency = st.number_input("Enter Post Frequency:",min_value=0,max_value=10,step=1)
48
+
49
+
50
+
51
+ # def plot_health_metrics(inputs):
52
+ # labels = ["Age", "BMI", "Urea", "Creatinine", "HbA1c", "Cholesterol", "Triglycerides", "HDL", "LDL", "VLDL"]
53
+ # standard_ranges = [
54
+ # (20, 80), (18.5, 24.9), (2.3, 7.0), (0.6, 1.2), (4.0, 5.6), (125, 200), (40, 150), (40, 60), (50, 100), (5, 40)
55
+ # ]
56
+ # fig, ax = plt.subplots(figsize=(10, 6))
57
+ # ax.barh(labels, [inputs[i] for i in range(10)], color='skyblue')
58
+ # for i, (low, high) in enumerate(standard_ranges):
59
+ # ax.plot([low, high], [i, i], color='red', linewidth=2)
60
+ # ax.set_xlabel("Value")
61
+ # ax.set_title("Health Metrics vs Standard Ranges")
62
+ # st.pyplot(fig)
63
+
64
+ # plot_health_metrics([age, bmi, urea, cr, HbA1c, chol, tg, hdl, ldl, vldl])
65
+
66
+
67
+ with open("rs.pkl", "rb") as f:
68
+ rs = pickle.load(f)
69
+
70
+ with open("ohe_drain.pkl", "rb") as f:
71
+ ohe_drain = pickle.load(f)
72
+
73
+ with open("ohe_stage.pkl", "rb") as f:
74
+ ohe_drain = pickle.load(f)
75
+
76
+ with open("le.pkl", "rb") as f:
77
+ le = pickle.load(f)
78
+
79
+ with open("knn.pkl", "rb") as f:
80
+ knn = pickle.load(f)
81
+
82
+ stage_encoded = ohe.transform([[stage_fear]])[0][0] # gender encoded using one hot encoding
83
+ drain_encoded = ohe.transform([[drained]])[0][0]
84
+
85
+
86
+ numeric_features = np.array([[time_spent, social_event, going_outside, friends, post_frequency]])
87
+ scaled_features = rs.transform(numeric_features)
88
+
89
+
90
+ final_input = np.concatenate(([gender_encoded], scaled_features[0])).reshape(1, -1)
91
+
92
+
93
+ #input_data = np.array([[gender_encoded, age, urea, cr, HbA1c, chol, tg, hdl, ldl, vldl, bmi]])
94
+
95
+
96
+
97
+
98
+ prediction_labels = {
99
+ 0: "Non-Diabetic",
100
+ 1: "Diabetic",
101
+ 2: "Pre-Diabetic"
102
+ }
103
+
104
+ # if st.button("Predict"):
105
+ # prediction = knn.predict(final_input)[0]
106
+ # result_label = prediction_labels.get(prediction, "Unknown")
107
+ # st.success(f"Predicted Result: {result_label}")
108
+ # if result_label == "Pre-Diabetic":
109
+ # st.warning("You are in the pre-diabetic range. It's advisable to consult a healthcare professional for further evaluation.")
110
+ # elif result_label == "Diabetic":
111
+ # st.error("You are classified as diabetic. Please seek medical advice for appropriate management.")
112
+
113
+
114
+
115
+ if st.button("Predict"):
116
+ prediction = knn.predict(final_input)[0]
117
+ result_label = prediction_labels.get(prediction, "Unknown")
118
+
119
+ # Custom result display
120
+ st.markdown(
121
+ f"""
122
+ <div style='background-color: #1f77b4; padding: 15px; border-radius: 10px;'>
123
+ <h4 style='color: white;'>Predicted Result: {result_label}</h4>
124
+ </div>
125
+ """,
126
+ unsafe_allow_html=True
127
+ )
128
+
129
+ # Message based on result
130
+ if result_label == "Pre-Diabetic":
131
+ st.warning("You are in the pre-diabetic range. It's advisable to consult a healthcare professional for further evaluation.")
132
+ elif result_label == "Diabetic":
133
+ st.error("You are classified as diabetic. Please seek medical advice for appropriate management.")
134
+
135
+
136
+
137
+
138
+
139
+ # if st.button("Predict"):
140
+ # prediction = knn.predict(final_input)[0]
141
+ # result_label = prediction_labels.get(prediction,"Unknown")
142
+ # st.success(f"Predicted Result: {result_label}")
143
+ # #st.write("Predicted Diabetes Status :",prediction[0])
144
+
145
+
146
+