File size: 26,331 Bytes
0e73bb7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
import streamlit as st
import pandas as pd
import joblib
from sklearn.linear_model import LogisticRegression
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import DecisionTreeClassifier
import time
import numpy as np

import streamlit as st

# Using Markdown with custom styles to center the title and add style
st.markdown("""
    <style>
    .title {
        font-size: 40px;
        font-weight: bold;
        color: #FF4B4B;
        text-align: center;
        margin-bottom: -20px;  # Adjusts the spacing below the title
    }
    </style>
    <div class="title">🎓 STUDENT DROPOUT PREDICTION APP 🎓</div>
    """, unsafe_allow_html=True)

# Display a banner image
st.image("banner.webp", use_column_width=True)

# Main page description
st.markdown("""
This app predicts the likelihood of a student dropping out 🚪.
Enter the student's details on the left sidebar to see the prediction result.
The prediction helps in identifying students at risk early, allowing for timely intervention to improve retention rates.
""")

import joblib

# Load the models
decision_tree = joblib.load('age_aware_models/decision_tree_model.joblib')
logistic_regression = joblib.load('age_aware_models/logistic_regression_model.joblib')
random_forest = joblib.load('age_aware_models/random_forest_model.joblib')

# Define a dictionary of models with their names, actual models, and types
models = {
    'Decision Tree': {'model': decision_tree, 'type': 'Decision Tree'},
    'Logistic Regression': {'model': logistic_regression, 'type': 'Logistic Regression'},
    'Random Forest': {'model': random_forest, 'type': 'Random Forest'}
}

with st.sidebar:
    # Streamlit UI to select a model
    # Add some design to the header
    st.write("<h2 style='color: #ff5733; text-align: center;'>Select Model</h2>", unsafe_allow_html=True)

    st.header('')
    # Ensure that this is defined before you try to use `model_name`
    model_name = st.selectbox('Choose a model', list(models.keys()))

    # Retrieve the selected model and its type from the dictionary after it's been defined
    model = models[model_name]['model']
    model_type = models[model_name]['type']

    # Additional Streamlit code to display selected model and type or other UI elements
    st.write(f"You have selected: {model_name}")


# Load trained model
@st.cache_resource
#def load_model():
#    return LogisticRegression()  # Load your trained model here

def preprocess_input(input_data, original_feature_names):
    # Create a DataFrame from the input data
    input_df = pd.DataFrame(input_data, index=[0])

    # Ensure the DataFrame has the correct column structure
    input_df = input_df.reindex(columns=original_feature_names, fill_value=0)

    return input_df

original_feature_names = ['Marital_Status', 'Application_Mode', 'Application_Order', 'Course',
       'Attendance', 'Previous_Qualification', 'Nationality',
       'Mother_Qualification', 'Father_Qualification', 'Mother_Occupation',
       'Father_Occupation', 'Displaced', 'Special_Needs', 'Debtor',
       'Fees_UpToDate', 'Gender', 'Scholarship_Holder', 'Age', 'International',
       '1st_Sem_Credits', '1st_Sem_Enrolled', '1st_Sem_Evaluations',
       '1st_Sem_Approved', '1st_Sem_Grade', '1st_Sem_No_Evaluations',
       '2nd_Sem_Credits', '2nd_Sem_Enrolled', '2nd_Sem_Evaluations',
       '2nd_Sem_Approved', '2nd_Sem_Grade', '2nd_Sem_No_Evaluations',
       'Unemployment_Rate', 'Inflation_Rate', 'GDP']

def map_and_select(label, mapping_or_value, min_value=None, max_value=None, step=None):
    if isinstance(mapping_or_value, dict):
        # Invert the mapping dictionary
        inverted_mapping = {v: k for k, v in mapping_or_value.items()}

        # Display the selectbox
        selected_option = st.sidebar.selectbox(label, options=list(inverted_mapping.keys()))

        # Retrieve numerical value based on the selected option
        selected_value = inverted_mapping[selected_option]
        st.sidebar.write(f"{label} Value:", selected_value)
        return selected_value
    else:
        # Determine the type of input and display accordingly
        if isinstance(mapping_or_value, float):
            # Handle as a slider for float values
            selected_value = st.sidebar.slider(label, min_value=min_value, max_value=max_value, value=mapping_or_value, step=step)
        elif isinstance(mapping_or_value, int):
            # Handle as a number input for int values
            selected_value = st.sidebar.number_input(label, min_value=min_value, max_value=max_value, value=mapping_or_value, step=step)
        else:
            # Display as a text input for non-numeric values
            selected_value = st.sidebar.text_input(label, value=str(mapping_or_value))

        st.sidebar.write(f"{label}:", selected_value)
        return selected_value

def predict_dropout(input_data, model, model_type):
    # Initialize variable to ensure it has a value in all code paths
    dropout_prediction = None

    # Check the model type to decide on the prediction method
    if model_type == "Logistic Regression" or model_type == "Decision Tree" or model_type == "Random Forest":
        # Use model.predict for predictions
        dropout_prediction = model.predict(input_data)
    else:
        raise ValueError("Unsupported model type.")

    return dropout_prediction

def map_dropout_prediction(prediction):
    if prediction == 1:
        return "Dropout", "🎓", "The model predicts that the student is likely to dropout."
    else:
        return "Not Dropout", "👩‍🎓", "The model predicts that the student is not likely to dropout."

marital_mapping = {
    1: 'Single',
    2: 'Married',
    3: 'Widower',
    4: 'Divorced',
    5: 'Facto union',
    6: 'Legally separated'
}


# Add some design to the header
st.sidebar.write("<h2 style='color: #ff5733; text-align: center;'>Enter Student Details</h2>", unsafe_allow_html=True)


# Use the map_and_select function to handle mapping and selection for Marital Status
marital_status = map_and_select('Marital Status', marital_mapping)

application_mode_mapping = {
    1: '1st phase—general contingent',
    2: 'Ordinance No. 612/93',
    3: '1st phase—special contingent (Azores Island)',
    4: 'Holders of other higher courses',
    5: 'Ordinance No. 854-B/99',
    6: 'International student (bachelor)',
    7: '1st phase—special contingent (Madeira Island)',
    8: '2nd phase—general contingent',
    9: '3rd phase—general contingent',
    10: 'Ordinance No. 533-A/99, item b2) (Different Plan)',
    11: 'Ordinance No. 533-A/99, item b3 (Other Institution)',
    12: 'Over 23 years old',
    13: 'Transfer',
    14: 'Change in course',
    15: 'Technological specialization diploma holders',
    16: 'Change in institution/course',
    17: 'Short cycle diploma holders',
    18: 'Change in institution/course (International)'
}


application_mode = map_and_select('Application Mode', application_mode_mapping)


#application_mode = st.sidebar.selectbox('Application Mode', options=range(1, 10))  # Assuming modes 1 through 9
#st.sidebar.write("application Mode:", application_mode)

application_order_mapping = {
    1: 'First',
    2: 'Second',
    3: 'Third',
    4: 'Fourth',
    5: 'Fifth',
    6: 'Sixth',
    9: 'Ninth',
    0: 'Zero'
}

application_order = map_and_select('Application Order', application_order_mapping)

#application_order = st.sidebar.number_input('Application Order', min_value=0, max_value=10, value=1)
#st.sidebar.write("application Order:", application_order)

courses_mapping = {
    1: 'Biofuel Production Technologies',
    2: 'Animation and Multimedia Design',
    3: 'Social Service (evening attendance)',
    4: 'Agronomy',
    5: 'Communication Design',
    6: 'Veterinary Nursing',
    7: 'Informatics Engineering',
    8: 'Equiniculture',
    9: 'Management',
    10: 'Social Service',
    11: 'Tourism',
    12: 'Nursing',
    13: 'Oral Hygiene',
    14: 'Advertising and Marketing Management',
    15: 'Journalism and Communication',
    16: 'Basic Education',
    17: 'Management (evening attendance)'
}

# Use the map_and_select function to handle mapping and selection for Courses
course = map_and_select('Course', courses_mapping)

#course = st.sidebar.selectbox('Course', options=range(1, 100))  # Update range based on actual course codes
#st.sidebar.write("course:", course)

attendance_mapping = {
    1: 'Daytime',
    2: 'Evening'
}

# Use the map_and_select function to handle mapping and selection for Daytime/Evening Attendance
daytime_evening_attendance = map_and_select('Daytime/Evening Attendance', attendance_mapping)

#daytime_evening_attendance = st.sidebar.radio('Daytime/Evening Attendance', options=[1, 2], format_func=lambda x: 'Daytime' if x == 1 else 'Evening')
#st.sidebar.write("Daytime Evening Attendance:", daytime_evening_attendance)

previous_qualification_mapping = {
    1: 'Secondary education',
    2: 'Higher education—bachelor’s degree',
    3: 'Higher education—degree',
    4: 'Higher education—master’s degree',
    5: 'Higher education—doctorate',
    6: 'Frequency of higher education',
    7: '12th year of schooling—not completed',
    8: '11th year of schooling—not completed',
    9: 'Other—11th year of schooling',
    10: '10th year of schooling',
    11: '10th year of schooling—not completed',
    12: 'Basic education 3rd cycle (9th/10th/11th year) or equivalent',
    13: 'Basic education 2nd cycle (6th/7th/8th year) or equivalent',
    14: 'Technological specialization course',
    15: 'Higher education—degree (1st cycle)',
    16: 'Professional higher technical course',
    17: 'Higher education—master’s degree (2nd cycle)'
}

# Use the map_and_select function to handle mapping and selection for Previous Qualification
previous_qualification = map_and_select('Previous Qualification', previous_qualification_mapping)

## Output the selected value using st.write
#st.sidebar.write("Previous Qualification:", selected_previous_qualification_label)

#previous_qualification = st.sidebar.selectbox('Previous Qualification', options=range(1, 20))  # Update range based on actual qualifications
#st.sidebar.write("Previous Qualification:", previous_qualification)

nationality_mapping = {
    1: 'Portuguese', 2: 'German', 3: 'Spanish', 4: 'Italian', 5: 'Dutch', 6: 'English',
    7: 'Lithuanian', 8: 'Angolan', 9: 'Cape Verdean', 10: 'Guinean', 11: 'Mozambican',
    12: 'Santomean', 13: 'Turkish', 14: 'Brazilian', 15: 'Romanian', 16: 'Moldova (Republic of)',
    17: 'Mexican', 18: 'Ukrainian', 19: 'Russian', 20: 'Cuban', 21: 'Colombian'
}

nationality = map_and_select('Nationality', nationality_mapping)

#nationality = st.sidebar.selectbox('Nationality', options=range(1, 200))  # Update range based on actual nationality codes
#st.sidebar.write("nationality:", nationality)

qualification_mapping = {
    1: 'Secondary Education',
    2: 'Higher Education - Undergraduate',
    3: 'Higher Education - Undergraduate',
    4: 'Higher Education - Graduate',
    5: 'Higher Education - Graduate',
    6: 'Higher Education - Undergraduate',
    7: 'Primary Education',
    8: 'Primary Education',
    9: 'Primary Education',
    10: 'Secondary Education',
    11: 'Secondary Education',
    12: 'Secondary Education',
    13: 'Secondary Education',
    14: 'Secondary Education',
    15: 'Secondary Education',
    16: 'Vocational/Technical',
    17: 'Secondary Education',
    18: 'Primary Education',
    19: 'Secondary Education',
    20: 'Primary Education',
    21: 'Primary Education',
    22: 'Secondary Education',
    23: 'Secondary Education',
    24: 'Unknown',
    25: 'Primary Education',
    26: 'Primary Education',
    27: 'Primary Education',
    28: 'Primary Education',
    29: 'Vocational/Technical',
    30: 'Higher Education - Undergraduate',
    31: 'Higher Education - Undergraduate',
    32: 'Higher Education - Undergraduate',
    33: 'Higher Education - Graduate',
    34: 'Higher Education - Graduate'
}

mother_qualification = map_and_select('Mother\'s Qualification', qualification_mapping)

#mother_qualification = st.sidebar.selectbox('Mother\'s Qualification', options=range(1, 20))
#st.sidebar.write("Mother Qualification:", mother_qualification)

father_qualification = map_and_select('Father\'s Qualification', qualification_mapping)

#father_qualification = st.sidebar.selectbox('Father\'s Qualification', options=range(1, 20))
#st.sidebar.write("Father Qualification:", father_qualification)

occupation_mapping = {
    1: 'Student',
    2: 'Representatives of the Legislative Power and Executive Bodies, Directors, Directors and Executive Managers',
    3: 'Specialists in Intellectual and Scientific Activities',
    4: 'Intermediate Level Technicians and Professions',
    5: 'Administrative staff',
    6: 'Personal Services, Security and Safety Workers, and Sellers',
    7: 'Farmers and Skilled Workers in Agriculture, Fisheries, and Forestry',
    8: 'Skilled Workers in Industry, Construction, and Craftsmen',
    9: 'Installation and Machine Operators and Assembly Workers',
    10: 'Unskilled Workers',
    11: 'Armed Forces Professions',
    12: 'Other Situation',
    13: '(blank)',
    14: 'Armed Forces Officers',
    15: 'Armed Forces Sergeants',
    16: 'Other Armed Forces personnel',
    17: 'Directors of administrative and commercial services',
    18: 'Hotel, catering, trade, and other services directors',
    19: 'Specialists in the physical sciences, mathematics, engineering, and related techniques',
    20: 'Health professionals',
    21: 'Teachers',
    22: 'Specialists in finance, accounting, administrative organization, and public and commercial relations',
    23: 'Intermediate level science and engineering technicians and professions',
    24: 'Technicians and professionals of intermediate level of health',
    25: 'Intermediate level technicians from legal, social, sports, cultural, and similar services',
    26: 'Information and communication technology technicians',
    27: 'Office workers, secretaries in general, and data processing operators',
    28: 'Data, accounting, statistical, financial services, and registry-related operators',
    29: 'Other administrative support staff',
    30: 'Personal service workers',
    31: 'Sellers',
    32: 'Personal care workers and the like',
    33: 'Protection and security services personnel',
    34: 'Market-oriented farmers and skilled agricultural and animal production workers',
    35: 'Farmers, livestock keepers, fishermen, hunters and gatherers, and subsistence',
    36: 'Skilled construction workers and the like, except electricians',
    37: 'Skilled workers in metallurgy, metalworking, and similar',
    38: 'Skilled workers in electricity and electronics',
    39: 'Workers in food processing, woodworking, and clothing and other industries and crafts',
    40: 'Fixed plant and machine operators',
    41: 'Assembly workers',
    42: 'Vehicle drivers and mobile equipment operators',
    43: 'Unskilled workers in agriculture, animal production, and fisheries and forestry',
    44: 'Unskilled workers in extractive industry, construction, manufacturing, and transport',
    45: 'Meal preparation assistants',
    46: 'Street vendors (except food) and street service providers'
}

mother_occupation = map_and_select('Mother\'s Occupation', occupation_mapping)

#mother_occupation = st.sidebar.selectbox('Mother\'s Occupation', options=range(1, 50))  # Update range based on actual occupations
#st.sidebar.write("Mother Occupation:", mother_occupation)

father_occupation = map_and_select('Father\'s Occupation', occupation_mapping)

#father_occupation = st.sidebar.selectbox('Father\'s Occupation', options=range(1, 50))
#st.sidebar.write("Father Occupation:", father_occupation)


displaced_mapping = {
    1: 'Yes',
    0: 'No'
}

displaced = map_and_select('Displaced', displaced_mapping)

#displaced = st.sidebar.radio('Displaced', options=[0, 1], format_func=lambda x: 'No' if x == 0 else 'Yes')
#st.sidebar.write("Displaced:", displaced)

educational_special_needs_mapping = {
    1: 'Yes',
    0: 'No'
}

debtor_mapping = {
    1: 'Yes',
    0: 'No'
}

educational_special_needs = map_and_select('Educational Special Needs', educational_special_needs_mapping)
#st.sidebar.write("Educational Special Needs:", educational_special_needs_mapping[educational_special_needs])

debtor = map_and_select('Debtor', debtor_mapping)
#st.sidebar.write("Debtor:", debtor_mapping[debtor])


#educational_special_needs = st.sidebar.radio('Educational Special Needs', options=[0, 1], format_func=lambda x: 'No' if x == 0 else 'Yes')
#st.sidebar.write("Educational Special Needs:", educational_special_needs)

#debtor = st.sidebar.radio('Debtor', options=[0, 1], format_func=lambda x: 'No' if x == 0 else 'Yes')
#st.sidebar.write("Debtor:", debtor)

# Example usage for single input

tuition_fees_up_to_date = map_and_select('Tuition Fees Up to Date', 5000, min_value=0, max_value=10000)


#tuition_fees_up_to_date = st.sidebar.number_input('Tuition Fees Up to Date', min_value=0, max_value=10000, value=5000)
#st.sidebar.write("tuition_fees_up_to_date:", tuition_fees_up_to_date)

# Gender replacement
gender_mapping = {
    1: 'male',
    0: 'female'
}

gender = map_and_select('Gender', gender_mapping)

#gender = st.sidebar.radio('Gender', options=[1, 2], format_func=lambda x: 'Male' if x == 1 else 'Female')
#st.sidebar.write("gender:", gender)

scholarship_mapping = {
    1: 'Yes',
    0: 'No'
}

scholarship_holder = map_and_select('Scholarship Holder', scholarship_mapping)
#st.sidebar.write("Scholarship holder:", scholarship_mapping[scholarship_holder])

#scholarship_holder = st.sidebar.radio('Scholarship Holder', options=[0, 1], format_func=lambda x: 'No' if x == 0 else 'Yes')
#st.sidebar.write("Scholarship holder:", scholarship_holder)

# Example usage for single input
age_at_enrollment = map_and_select('Age at Enrollment', 16, min_value=6, max_value=18)

#age_at_enrollment = st.sidebar.number_input('Age at Enrollment', min_value=16, max_value=60, value=18)
#st.sidebar.write("Age at Enrollment:", age_at_enrollment)

international_mapping = {
    1: 'Yes',
    0: 'No'
}

international = map_and_select('International', international_mapping)
#st.sidebar.write("International:", international_mapping[international])

#international = st.sidebar.radio('International', options=[0, 1], format_func=lambda x: 'No' if x == 0 else 'Yes')
#st.sidebar.write("International:", international)


unemployment_rate = map_and_select('Unemployment Rate', 10.8, min_value=0.0, max_value=100.0 )
#st.sidebar.write("unemployment_rate:", unemployment_rate)


#unemployment_rate = st.sidebar.slider('Unemployment Rate', min_value=0.0, max_value=100.0, value=10.8)
#st.sidebar.write("Unemployment Rate:", unemployment_rate)

inflation_rate = map_and_select('Inflation Rate', 1.4, min_value=-10.0, max_value=30.0)
#st.sidebar.write("inflation_rate:", inflation_rate)

# Use map_and_select for the inflation_rate
#inflation_rate = map_and_select(1, 'Inflation Rate', 1.4)
#st.sidebar.write("Inflation Rate:", inflation_rate)

#inflation_rate = st.sidebar.slider('Inflation Rate', min_value=-10.0, max_value=30.0, value=1.4)
#st.sidebar.write("Inflation Rate:", inflation_rate)

#gdp = st.sidebar.number_input('GDP', min_value=0.0, max_value=100.0, value=1.74)
#st.sidebar.write("GDP:", gdp)

# Use map_and_select for the inflation_rate
gdp = map_and_select('GDP', 1.74, min_value=0.0, max_value=100.0)
#st.sidebar.write("Inflation Rate:", gdp)

#st.header('Curricular Units 1st Semester')
#credited_1st_sem = st.sidebar.number_input('Credited Units 1st Semester', min_value=0, step=1)
#st.sidebar.write("Credited Units 1st Semester:", credited_1st_sem)
#enrolled_1st_sem = st.sidebar.number_input('Enrolled Units 1st Semester', min_value=0, step=1)
#st.sidebar.write("Enrolled Units 1st Semester:", enrolled_1st_sem)
#evaluations_1st_sem = st.sidebar.number_input('Evaluations 1st Semester', min_value=0, step=1)
#st.sidebar.write("Evaluations 1st Semester:", evaluations_1st_sem)
#approved_1st_sem = st.sidebar.number_input('Approved Units 1st Semester', min_value=0, step=1)
#st.sidebar.write("Approved Units 1st Semester:", approved_1st_sem)
#grade_1st_sem = st.sidebar.number_input('Grade 1st Semester', min_value=0.0, max_value=10.0, step=0.1)
#st.sidebar.write("Grade 1st Semester:", grade_1st_sem)
#without_evaluations_1st_sem = st.sidebar.number_input('Units without Evaluations 1st Semester', min_value=0, step=1)
#st.sidebar.write("GDP:", without_evaluations_1st_sem)

# Use map_and_select for the various inputs
credited_1st_sem = map_and_select('Credited Units 1st Semester', 0, min_value=0, step=1)
#st.sidebar.write("Credited Units 1st Semester:", credited_1st_sem)

enrolled_1st_sem = map_and_select('Enrolled Units 1st Semester', 0, min_value=0, step=1)
#st.sidebar.write("Enrolled Units 1st Semester:", enrolled_1st_sem)

evaluations_1st_sem = map_and_select('Evaluations 1st Semester', 0, min_value=0, step=1)
#st.sidebar.write("Evaluations 1st Semester:", evaluations_1st_sem)

approved_1st_sem = map_and_select('Approved Units 1st Semester', 0, min_value=0, step=1)
#st.sidebar.write("Approved Units 1st Semester:", approved_1st_sem)

grade_1st_sem = map_and_select('Grade 1st Semester', 0.0, min_value=0.0, max_value=10.0, step=0.1)
#st.sidebar.write("Grade 1st Semester:", grade_1st_sem)

without_evaluations_1st_sem = map_and_select('Units without Evaluations 1st Semester', 0, min_value=0, step=1)
#st.sidebar.write("Units without Evaluations 1st Semester:", without_evaluations_1st_sem)


#st.sidebar.header('Curricular Units 2nd Semester')
#credited_2nd_sem = st.sidebar.number_input('Credited Units 2nd Semester', min_value=0, step=1)
#st.sidebar.write("Credited Units 2nd Semester:", credited_2nd_sem)
#enrolled_2nd_sem = st.sidebar.number_input('Enrolled Units 2nd Semester', min_value=0, step=1)
#st.sidebar.write("Enrolled Units 2nd Semester:", enrolled_2nd_sem)
#evaluations_2nd_sem = st.sidebar.number_input('Evaluations 2nd Semester', min_value=0, step=1)
#st.sidebar.write("Evaluations 2nd Semester:", evaluations_2nd_sem)
#approved_2nd_sem = st.sidebar.number_input('Approved Units 2nd Semester', min_value=0, step=1)
#st.sidebar.write("Approved Units 2nd Semester:", approved_2nd_sem)
#grade_2nd_sem = st.sidebar.number_input('Grade 2nd Semester', min_value=0.0, max_value=10.0, step=0.1)
#st.sidebar.write("Grade 2nd Semester:", grade_2nd_sem)
#without_evaluations_2nd_sem = st.sidebar.number_input('Units without Evaluations 2nd Semester', min_value=0, step=1)
#st.sidebar.write("Units without Evaluations 2nd Semester:", without_evaluations_2nd_sem)

# Use map_and_select for the various inputs for the 2nd semester
credited_2nd_sem = map_and_select('Credited Units 2nd Semester', 0, min_value=0, step=1)
#st.sidebar.write("Credited Units 2nd Semester:", credited_2nd_sem)

enrolled_2nd_sem = map_and_select('Enrolled Units 2nd Semester', 0, min_value=0, step=1)
#st.sidebar.write("Enrolled Units 2nd Semester:", enrolled_2nd_sem)

evaluations_2nd_sem = map_and_select('Evaluations 2nd Semester', 0, min_value=0, step=1)
#st.sidebar.write("Evaluations 2nd Semester:", evaluations_2nd_sem)

approved_2nd_sem = map_and_select('Approved Units 2nd Semester', 0, min_value=0, step=1)
#st.sidebar.write("Approved Units 2nd Semester:", approved_2nd_sem)

grade_2nd_sem = map_and_select('Grade 2nd Semester', 0.0, min_value=0.0, max_value=10.0, step=0.1)
#st.sidebar.write("Grade 2nd Semester:", grade_2nd_sem)

without_evaluations_2nd_sem = map_and_select('Units without Evaluations 2nd Semester', 0, min_value=0, step=1)
#st.sidebar.write("Units without Evaluations 2nd Semester:", without_evaluations_2nd_sem)

input_data = {
'Marital_Status': marital_status,
'Application_Mode' : application_mode,
'Application_Order': application_order,
'Course': course,
'Attendance': daytime_evening_attendance,
'Previous_Qualification': previous_qualification,
'Nationality': nationality,
'Mother_Qualification': mother_qualification,
'Father_Qualification': father_qualification,
'Mother_Occupation': mother_occupation,
'Father_Occupation': father_occupation,
'Displaced': displaced,
'Special_Needs': educational_special_needs,
'Debtor': debtor,
'Fees_UpToDate':tuition_fees_up_to_date,
'Gender': gender,
'Scholarship_Holder': scholarship_holder,
'Age': age_at_enrollment,
'International': international,
'1st_Sem_Credits': credited_1st_sem,
'1st_Sem_Enrolled': enrolled_1st_sem,
'1st_Sem_Evaluations': evaluations_1st_sem,
'1st_Sem_Approved': approved_1st_sem,
'1st_Sem_Grade': grade_1st_sem,
'1st_Sem_No_Evaluations': without_evaluations_1st_sem,
'2nd_Sem_Credits': credited_2nd_sem,
'2nd_Sem_Enrolled': enrolled_2nd_sem,
'2nd_Sem_Evaluations': evaluations_2nd_sem,
'2nd_Sem_Approved': approved_2nd_sem,
'2nd_Sem_Grade': grade_2nd_sem,
'2nd_Sem_No_Evaluations': without_evaluations_2nd_sem,
'Unemployment_Rate': unemployment_rate,
'Inflation_Rate': inflation_rate,
'GDP':gdp
}

if st.sidebar.button('Predict Dropout'):
    try:
        with st.spinner("Predicting..."):
            # Simulate a long-running prediction process
            progress_bar = st.progress(0)
            for i in range(5):  # Simulate progress
                time.sleep(0.1)  # Sleep for a short period to simulate work
                progress_bar.progress((i + 1) * 20)

            # Convert input dictionary to a 2D array
            input_array = np.array(list(input_data.values())).reshape(1, -1)

            # Perform prediction
            dropout_label = predict_dropout(input_array, model, model_type)
            dropout_label, emoji, explanation = map_dropout_prediction(dropout_label)

            # Display the prediction result
            st.success("Prediction complete!")
            st.write(f"Prediction: {dropout_label} {emoji}")
            st.write(explanation)

            # Display images
            if dropout_label == "Dropout":
                st.image("dropout_image.webp", caption="Image representing a dropout student", use_column_width=True)
            else:
                st.image("not_dropout_image.webp", caption="Image representing a non-dropout student", use_column_width=True)

    except Exception as e:
        st.error(f"An error occurred: {str(e)}")