Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +209 -0
- final_rf_model.pkl +3 -0
app.py
ADDED
@@ -0,0 +1,209 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import numpy as np
|
3 |
+
import joblib
|
4 |
+
from sklearn.preprocessing import StandardScaler
|
5 |
+
|
6 |
+
|
7 |
+
model = joblib.load("final_rf_model.pkl")
|
8 |
+
scaler = StandardScaler()
|
9 |
+
|
10 |
+
class_labels = {
|
11 |
+
0: 'Insufficient Weight',
|
12 |
+
1: 'Normal Weight',
|
13 |
+
2: 'Overweight Level I',
|
14 |
+
3: 'Overweight Level II',
|
15 |
+
4: 'Obesity Type I',
|
16 |
+
5: 'Obesity Type II',
|
17 |
+
6: 'Obesity Type III'
|
18 |
+
}
|
19 |
+
|
20 |
+
# Function to make predictions
|
21 |
+
def predict_obesity(weight, height, age, fcvc, gender, ncp, ch2o, faf, tue, fhwow,
|
22 |
+
caec_sometimes, calc_no, calc_sometimes, caec_frequently,
|
23 |
+
alcohol_choice, mtrans_choice, favc):
|
24 |
+
|
25 |
+
# Prepare input data for prediction
|
26 |
+
input_data = np.array([[weight, height, age, fcvc, 1 if gender == "Male" else 0, ncp, ch2o, faf, tue, fhwow,
|
27 |
+
1 if caec_sometimes else 0, 1 if calc_no else 0, 1 if calc_sometimes else 0,
|
28 |
+
1 if caec_frequently else 0, 1 if alcohol_choice == "Yes" else 0,
|
29 |
+
1 if favc else 0, 1 if mtrans_choice == "Automobile" else 0]])
|
30 |
+
|
31 |
+
# Scale the appropriate input values
|
32 |
+
input_data[:, 0:4] = scaler.fit_transform(input_data[:, 0:4])
|
33 |
+
input_data[:, 5:10] = scaler.fit_transform(input_data[:, 5:10])
|
34 |
+
|
35 |
+
# Make prediction
|
36 |
+
prediction = model.predict(input_data)
|
37 |
+
|
38 |
+
# Map the numeric prediction to the corresponding label
|
39 |
+
predicted_label = class_labels.get(prediction[0], "Unknown Class")
|
40 |
+
return predicted_label
|
41 |
+
|
42 |
+
# Custom CSS for better styling
|
43 |
+
custom_css = """
|
44 |
+
<style>
|
45 |
+
.gradio-container {
|
46 |
+
background-color: #0a0a2c;
|
47 |
+
background-image:
|
48 |
+
linear-gradient(45deg, #0a0a2c 25%, #12124a 25%, #12124a 50%, #0a0a2c 50%, #0a0a2c 75%, #12124a 75%, #12124a 100%);
|
49 |
+
background-size: 56.57px 56.57px;
|
50 |
+
border-radius: 15px;
|
51 |
+
padding: 30px;
|
52 |
+
box-shadow: 0 0 20px rgba(66, 220, 219, 0.3),
|
53 |
+
0 0 40px rgba(233, 30, 99, 0.2);
|
54 |
+
border: 1px solid rgba(66, 220, 219, 0.3);
|
55 |
+
}
|
56 |
+
|
57 |
+
.title {
|
58 |
+
font-family: 'Orbitron', sans-serif;
|
59 |
+
font-size: 36px;
|
60 |
+
font-weight: bold;
|
61 |
+
color: #00fff2;
|
62 |
+
text-align: center;
|
63 |
+
margin-bottom: 30px;
|
64 |
+
text-transform: uppercase;
|
65 |
+
letter-spacing: 3px;
|
66 |
+
text-shadow: 0 0 10px rgba(0, 255, 242, 0.5),
|
67 |
+
0 0 20px rgba(0, 255, 242, 0.3),
|
68 |
+
0 0 30px rgba(0, 255, 242, 0.1);
|
69 |
+
}
|
70 |
+
|
71 |
+
.description {
|
72 |
+
font-family: 'Rajdhani', sans-serif;
|
73 |
+
font-size: 18px;
|
74 |
+
color: #b4f8fc;
|
75 |
+
text-align: center;
|
76 |
+
margin-bottom: 30px;
|
77 |
+
line-height: 1.6;
|
78 |
+
text-shadow: 0 0 5px rgba(180, 248, 252, 0.3);
|
79 |
+
}
|
80 |
+
|
81 |
+
/* Input fields styling */
|
82 |
+
input[type="number"] {
|
83 |
+
background-color: rgba(16, 16, 44, 0.9);
|
84 |
+
border: 2px solid #00fff2;
|
85 |
+
border-radius: 8px;
|
86 |
+
padding: 12px;
|
87 |
+
color: #fff;
|
88 |
+
font-family: 'Rajdhani', sans-serif;
|
89 |
+
transition: all 0.3s ease;
|
90 |
+
box-shadow: 0 0 10px rgba(0, 255, 242, 0.2);
|
91 |
+
}
|
92 |
+
|
93 |
+
input[type="number"]:focus {
|
94 |
+
border-color: #ff2e63;
|
95 |
+
box-shadow: 0 0 15px rgba(255, 46, 99, 0.4);
|
96 |
+
outline: none;
|
97 |
+
}
|
98 |
+
|
99 |
+
/* Radio and Checkbox styling */
|
100 |
+
input[type="radio"],
|
101 |
+
input[type="checkbox"] {
|
102 |
+
accent-color: #ff2e63;
|
103 |
+
}
|
104 |
+
|
105 |
+
.input-container label {
|
106 |
+
color: #b4f8fc;
|
107 |
+
font-family: 'Rajdhani', sans-serif;
|
108 |
+
font-size: 16px;
|
109 |
+
margin-bottom: 8px;
|
110 |
+
display: block;
|
111 |
+
}
|
112 |
+
|
113 |
+
/* Button styling */
|
114 |
+
button {
|
115 |
+
background: linear-gradient(45deg, #ff2e63, #00fff2);
|
116 |
+
color: #fff;
|
117 |
+
border: none;
|
118 |
+
padding: 15px 30px;
|
119 |
+
border-radius: 8px;
|
120 |
+
cursor: pointer;
|
121 |
+
font-family: 'Orbitron', sans-serif;
|
122 |
+
font-size: 18px;
|
123 |
+
text-transform: uppercase;
|
124 |
+
letter-spacing: 2px;
|
125 |
+
transition: all 0.3s ease;
|
126 |
+
box-shadow: 0 0 15px rgba(255, 46, 99, 0.3),
|
127 |
+
0 0 30px rgba(0, 255, 242, 0.2);
|
128 |
+
}
|
129 |
+
|
130 |
+
button:hover {
|
131 |
+
transform: translateY(-2px);
|
132 |
+
box-shadow: 0 0 20px rgba(255, 46, 99, 0.5),
|
133 |
+
0 0 40px rgba(0, 255, 242, 0.3);
|
134 |
+
}
|
135 |
+
|
136 |
+
/* Output label styling */
|
137 |
+
.output-label {
|
138 |
+
background: rgba(16, 16, 44, 0.9);
|
139 |
+
border: 2px solid #ff2e63;
|
140 |
+
border-radius: 8px;
|
141 |
+
padding: 20px;
|
142 |
+
color: #00fff2;
|
143 |
+
font-family: 'Orbitron', sans-serif;
|
144 |
+
font-size: 24px;
|
145 |
+
text-align: center;
|
146 |
+
margin-top: 20px;
|
147 |
+
box-shadow: 0 0 15px rgba(255, 46, 99, 0.3);
|
148 |
+
}
|
149 |
+
|
150 |
+
/* Add cyberpunk grid lines to the background */
|
151 |
+
.gradio-container::before {
|
152 |
+
content: '';
|
153 |
+
position: absolute;
|
154 |
+
top: 0;
|
155 |
+
left: 0;
|
156 |
+
right: 0;
|
157 |
+
bottom: 0;
|
158 |
+
background:
|
159 |
+
linear-gradient(90deg, rgba(66, 220, 219, 0.1) 1px, transparent 1px),
|
160 |
+
linear-gradient(0deg, rgba(66, 220, 219, 0.1) 1px, transparent 1px);
|
161 |
+
background-size: 20px 20px;
|
162 |
+
pointer-events: none;
|
163 |
+
}
|
164 |
+
|
165 |
+
/* Add some hover effects to input containers */
|
166 |
+
.input-container:hover {
|
167 |
+
transform: translateX(5px);
|
168 |
+
transition: transform 0.3s ease;
|
169 |
+
}
|
170 |
+
|
171 |
+
/* Scrollbar styling */
|
172 |
+
::-webkit-scrollbar {
|
173 |
+
width: 10px;
|
174 |
+
background: #0a0a2c;
|
175 |
+
}
|
176 |
+
|
177 |
+
::-webkit-scrollbar-thumb {
|
178 |
+
background: linear-gradient(45deg, #ff2e63, #00fff2);
|
179 |
+
border-radius: 5px;
|
180 |
+
}
|
181 |
+
</style>
|
182 |
+
"""
|
183 |
+
|
184 |
+
# Gradio interface
|
185 |
+
iface = gr.Interface(
|
186 |
+
fn=predict_obesity,
|
187 |
+
inputs=[
|
188 |
+
gr.Number(label="Weight (40-160 kg)"),
|
189 |
+
gr.Number(label="Height (1-2 m)"),
|
190 |
+
gr.Number(label="Age (10-60 years)"),
|
191 |
+
gr.Number(label="FCVC (Frequency of Vegetable Consumption 1-4)"),
|
192 |
+
gr.Radio(choices=["Male", "Female"], label="Gender"),
|
193 |
+
gr.Number(label="NCP (Number of meals per day 1-3)"),
|
194 |
+
gr.Number(label="CH2O (Water Consumption 1-3)"),
|
195 |
+
gr.Number(label="FAF (Physical Activity Frequency 1-4)"),
|
196 |
+
gr.Number(label="TUE (Time Spent on Exercise 1-4)"),
|
197 |
+
gr.Number(label="FHWOW (Family History with OverWeight)"),
|
198 |
+
gr.Radio(choices=["No", "Sometimes", "Frequently"], label="Alcohol Consumption"),
|
199 |
+
gr.Radio(choices=["Public Transportation", "Automobile"], label="Transportation Method"),
|
200 |
+
gr.Checkbox(label="FAVC (Frequent Consumption of High-Calorie Foods)"),
|
201 |
+
],
|
202 |
+
outputs=gr.Label(label="Predicted Obesity Level"),
|
203 |
+
title="Obesity Level Estimator",
|
204 |
+
description="Enter the features related to eating habits and physical condition to estimate obesity levels.",
|
205 |
+
css=custom_css
|
206 |
+
)
|
207 |
+
|
208 |
+
# Launch the interface
|
209 |
+
iface.launch(share=True)
|
final_rf_model.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:21365aae2145e53e3f6221b77d8812f40895c5cf418a90f35519e20b12e83bd9
|
3 |
+
size 1303443
|