File size: 6,883 Bytes
72bdd36
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
import gradio as gr
import numpy as np
import joblib
from sklearn.preprocessing import StandardScaler 


model = joblib.load("final_rf_model.pkl")
scaler = StandardScaler()  

class_labels = {
    0: 'Insufficient Weight',
    1: 'Normal Weight',
    2: 'Overweight Level I',
    3: 'Overweight Level II',
    4: 'Obesity Type I',
    5: 'Obesity Type II',
    6: 'Obesity Type III'
}

# Function to make predictions
def predict_obesity(weight, height, age, fcvc, gender, ncp, ch2o, faf, tue, fhwow,

                    caec_sometimes, calc_no, calc_sometimes, caec_frequently,

                    alcohol_choice, mtrans_choice, favc):
    
    # Prepare input data for prediction
    input_data = np.array([[weight, height, age, fcvc, 1 if gender == "Male" else 0, ncp, ch2o, faf, tue, fhwow,
                             1 if caec_sometimes else 0, 1 if calc_no else 0, 1 if calc_sometimes else 0,
                             1 if caec_frequently else 0, 1 if alcohol_choice == "Yes" else 0,
                             1 if favc else 0, 1 if mtrans_choice == "Automobile" else 0]])

    # Scale the appropriate input values
    input_data[:, 0:4] = scaler.fit_transform(input_data[:, 0:4])  
    input_data[:, 5:10] = scaler.fit_transform(input_data[:, 5:10])  

    # Make prediction
    prediction = model.predict(input_data)

    # Map the numeric prediction to the corresponding label
    predicted_label = class_labels.get(prediction[0], "Unknown Class")
    return predicted_label

# Custom CSS for better styling
custom_css = """

<style>

    .gradio-container {

        background-color: #0a0a2c;

        background-image: 

            linear-gradient(45deg, #0a0a2c 25%, #12124a 25%, #12124a 50%, #0a0a2c 50%, #0a0a2c 75%, #12124a 75%, #12124a 100%);

        background-size: 56.57px 56.57px;

        border-radius: 15px;

        padding: 30px;

        box-shadow: 0 0 20px rgba(66, 220, 219, 0.3),

                    0 0 40px rgba(233, 30, 99, 0.2);

        border: 1px solid rgba(66, 220, 219, 0.3);

    }



    .title {

        font-family: 'Orbitron', sans-serif;

        font-size: 36px;

        font-weight: bold;

        color: #00fff2;

        text-align: center;

        margin-bottom: 30px;

        text-transform: uppercase;

        letter-spacing: 3px;

        text-shadow: 0 0 10px rgba(0, 255, 242, 0.5),

                     0 0 20px rgba(0, 255, 242, 0.3),

                     0 0 30px rgba(0, 255, 242, 0.1);

    }



    .description {

        font-family: 'Rajdhani', sans-serif;

        font-size: 18px;

        color: #b4f8fc;

        text-align: center;

        margin-bottom: 30px;

        line-height: 1.6;

        text-shadow: 0 0 5px rgba(180, 248, 252, 0.3);

    }



    /* Input fields styling */

    input[type="number"] {

        background-color: rgba(16, 16, 44, 0.9);

        border: 2px solid #00fff2;

        border-radius: 8px;

        padding: 12px;

        color: #fff;

        font-family: 'Rajdhani', sans-serif;

        transition: all 0.3s ease;

        box-shadow: 0 0 10px rgba(0, 255, 242, 0.2);

    }



    input[type="number"]:focus {

        border-color: #ff2e63;

        box-shadow: 0 0 15px rgba(255, 46, 99, 0.4);

        outline: none;

    }



    /* Radio and Checkbox styling */

    input[type="radio"],

    input[type="checkbox"] {

        accent-color: #ff2e63;

    }



    .input-container label {

        color: #b4f8fc;

        font-family: 'Rajdhani', sans-serif;

        font-size: 16px;

        margin-bottom: 8px;

        display: block;

    }



    /* Button styling */

    button {

        background: linear-gradient(45deg, #ff2e63, #00fff2);

        color: #fff;

        border: none;

        padding: 15px 30px;

        border-radius: 8px;

        cursor: pointer;

        font-family: 'Orbitron', sans-serif;

        font-size: 18px;

        text-transform: uppercase;

        letter-spacing: 2px;

        transition: all 0.3s ease;

        box-shadow: 0 0 15px rgba(255, 46, 99, 0.3),

                    0 0 30px rgba(0, 255, 242, 0.2);

    }



    button:hover {

        transform: translateY(-2px);

        box-shadow: 0 0 20px rgba(255, 46, 99, 0.5),

                    0 0 40px rgba(0, 255, 242, 0.3);

    }



    /* Output label styling */

    .output-label {

        background: rgba(16, 16, 44, 0.9);

        border: 2px solid #ff2e63;

        border-radius: 8px;

        padding: 20px;

        color: #00fff2;

        font-family: 'Orbitron', sans-serif;

        font-size: 24px;

        text-align: center;

        margin-top: 20px;

        box-shadow: 0 0 15px rgba(255, 46, 99, 0.3);

    }



    /* Add cyberpunk grid lines to the background */

    .gradio-container::before {

        content: '';

        position: absolute;

        top: 0;

        left: 0;

        right: 0;

        bottom: 0;

        background: 

            linear-gradient(90deg, rgba(66, 220, 219, 0.1) 1px, transparent 1px),

            linear-gradient(0deg, rgba(66, 220, 219, 0.1) 1px, transparent 1px);

        background-size: 20px 20px;

        pointer-events: none;

    }



    /* Add some hover effects to input containers */

    .input-container:hover {

        transform: translateX(5px);

        transition: transform 0.3s ease;

    }



    /* Scrollbar styling */

    ::-webkit-scrollbar {

        width: 10px;

        background: #0a0a2c;

    }



    ::-webkit-scrollbar-thumb {

        background: linear-gradient(45deg, #ff2e63, #00fff2);

        border-radius: 5px;

    }

</style>

"""

# Gradio interface
iface = gr.Interface(
    fn=predict_obesity,
    inputs=[
        gr.Number(label="Weight (40-160 kg)"),
        gr.Number(label="Height (1-2 m)"),
        gr.Number(label="Age (10-60 years)"),
        gr.Number(label="FCVC (Frequency of Vegetable Consumption 1-4)"),
        gr.Radio(choices=["Male", "Female"], label="Gender"),
        gr.Number(label="NCP (Number of meals per day 1-3)"),
        gr.Number(label="CH2O (Water Consumption 1-3)"),
        gr.Number(label="FAF (Physical Activity Frequency 1-4)"),
        gr.Number(label="TUE (Time Spent on Exercise 1-4)"),
        gr.Number(label="FHWOW (Family History with OverWeight)"),
        gr.Radio(choices=["No", "Sometimes", "Frequently"], label="Alcohol Consumption"),
        gr.Radio(choices=["Public Transportation", "Automobile"], label="Transportation Method"),
        gr.Checkbox(label="FAVC (Frequent Consumption of High-Calorie Foods)"),
    ],
    outputs=gr.Label(label="Predicted Obesity Level"),
    title="Obesity Level Estimator",
    description="Enter the features related to eating habits and physical condition to estimate obesity levels.",
    css=custom_css
)

# Launch the interface
iface.launch(share=True)