EncryptedBinary commited on
Commit
85dedc1
·
verified ·
1 Parent(s): f4b9fdc

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +279 -0
  2. data.xlsx +0 -0
  3. early_marriage_stack_classifier.pkl +3 -0
  4. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,279 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # ======================================================================
2
+ # PREDICTIVE INSIGHTS INTO CHILD MARRIAGE
3
+ # Academic UI (Times-style font)
4
+ # Bilingual UI (English + Bangla)
5
+ # Target: early_marriage_num (0 = No, 1 = Yes)
6
+ # Age feature is intentionally excluded
7
+ # ======================================================================
8
+
9
+ import warnings
10
+ warnings.filterwarnings("ignore")
11
+
12
+ import numpy as np
13
+ import pandas as pd
14
+ import gradio as gr
15
+ import joblib
16
+ import os
17
+
18
+ # ======================================================
19
+ # MODEL PATH
20
+ # ======================================================
21
+ MODEL_PATH = "early_marriage_stack_classifier.pkl"
22
+
23
+ # ======================================================
24
+ # FEATURE ORDER (DO NOT CHANGE)
25
+ # ======================================================
26
+ FEATURE_COLUMNS = [
27
+ "Region",
28
+ "No_mem",
29
+ "Income_monthly",
30
+ "Expend_monthly",
31
+ "Ed_father",
32
+ "Ed_mother",
33
+ "Ed_vict",
34
+ "parent_early_marriage",
35
+ "Past_histroy",
36
+ "Instablity_num",
37
+ "Female_working",
38
+ "Current_Situation",
39
+ "Social_inc_num",
40
+ "mentality_about_girl_marriage",
41
+ "mentality_about_boy_marriage",
42
+ "Financial_support_num",
43
+ ]
44
+
45
+ # ======================================================
46
+ # REGION (LABEL → VALUE)
47
+ # ======================================================
48
+ REGION_MAP = {
49
+ "Naogaon (নওগাঁ)": 1,
50
+ "Mymensingh (ময়মনসিংহ)": 2,
51
+ "Bhola (ভোলা)": 3,
52
+ "Cumilla (কুমিল্লা)": 4,
53
+ "Munshiganj (মুন্সিগঞ্জ)": 5,
54
+ }
55
+
56
+ # ======================================================
57
+ # EDUCATION (LABEL → VALUE)
58
+ # ======================================================
59
+ EDUCATION_MAP = {
60
+ "Illiterate (নিরক্ষর)": 0,
61
+ "Primary – Class 1 (প্রাথমিক – ১ম শ্রেণি)": 1,
62
+ "Primary – Class 2 (প্রাথমিক – ২য় শ্রেণি)": 2,
63
+ "Primary – Class 3 (প্রাথমিক – ৩য় শ্রেণি)": 3,
64
+ "Primary – Class 4 (প্রাথমিক – ৪র্থ শ্রেণি)": 4,
65
+ "Primary – Class 5 (প্রাথমিক – ৫ম শ্রেণি)": 5,
66
+ "Secondary – Class 6 (মাধ্যমিক – ৬ষ্ঠ শ্রেণি)": 6,
67
+ "Secondary – Class 7 (মাধ্যমিক – ৭ম শ্রেণি)": 7,
68
+ "Secondary – Class 8 (মাধ্যমিক – ৮ম শ্রেণি)": 8,
69
+ "Secondary – Class 9 (মাধ্যমিক – ৯ম শ্রেণি)": 9,
70
+ "Secondary – Class 10 (মাধ্যমিক – ১০ম শ্রেণি)": 10,
71
+ "Higher Secondary – Incomplete (উচ্চমাধ্যমিক – অসম্পূর্ণ)": 11,
72
+ "Higher Secondary – Completed / HSC (উচ্চমাধ্যমিক – সম্পন্ন)": 12,
73
+ "Undergraduate or Higher (স্নাতক বা তদূর্ধ্ব)": 13,
74
+ }
75
+
76
+ # ======================================================
77
+ # YES / NO (LABEL → VALUE)
78
+ # ======================================================
79
+ YES_NO_MAP = {
80
+ "No (না)": 0,
81
+ "Yes (হ্যাঁ)": 1,
82
+ }
83
+
84
+ # ======================================================
85
+ # MARITAL STATUS (LABEL → VALUE)
86
+ # ======================================================
87
+ MARITAL_STATUS_MAP = {
88
+ "Happy (সুখী)": 0,
89
+ "Unhappy (অসুখী)": 1,
90
+ "Stable (স্থিতিশীল)": 2,
91
+ "Separated (আলাদা বসবাস)": 3,
92
+ "Divorced (তালাকপ্রাপ্ত)": 4,
93
+ }
94
+
95
+ # ======================================================
96
+ # QUESTIONS (ALL INCLUDED, FULL TEXT)
97
+ # ======================================================
98
+ QUESTIONS = {
99
+ "Region": "Which region do you currently live in?\nআপনি বর্তমানে কোন অঞ্চলে বসবাস করছেন?",
100
+ "No_mem": "How many members are there in your household?\nআপনার পরিবারে মোট কতজন সদস্য আছে?",
101
+ "Income_monthly": "What is the total monthly income of your household?\nআপনার পরিবারের মোট মাসিক আয় কত?",
102
+ "Expend_monthly": "What is the total monthly expenditure of your household?\nআপনার পরিবারের মোট মাসিক ব্যয় কত?",
103
+ "Ed_father": "What is the highest level of education completed by the father?\nপিতার সর্বোচ্চ শিক্ষাগত যোগ্যতা কী?",
104
+ "Ed_mother": "What is the highest level of education completed by the mother?\nমাতার সর্বোচ্চ শিক্ষাগত যোগ্যতা কী?",
105
+ "Ed_vict": "What is the highest level of education completed by the girl?\nকন্যার সর্বোচ্চ শিক্ষাগত যোগ্যতা কী?",
106
+ "parent_early_marriage": "Did either parent marry before the legal age?\nপিতা বা মাতা কি আইনসম্মত বয়সের আগে বিবাহ করেছিলেন?",
107
+ "Past_histroy": "Is there any previous history of child marriage in your family?\nআপনার পরিবারে আগে কি বাল্য বিবাহের কোনো ঘটনা ঘটেছে?",
108
+ "Instablity_num": "Does your family face financial instability?\nআপনার পরিবার কি আর্থিক অস্থিরতার মুখোমুখি?",
109
+ "Female_working": "Is there any earning female member in your family?\nআপনার পরিবারে কি কোনো নারী সদস্য আয় করেন?",
110
+ "Current_Situation": "What is the current marital situation of the girl?\nকন্যার বর্তমান বৈবাহিক অবস্থা কী?",
111
+ "Social_inc_num": "Does your family face social insecurity or pressure?\nআপনার পরিবার কি সামাজিক নিরাপত্তাহীনতা বা চাপের মুখোমুখি?",
112
+ "mentality_about_girl_marriage": "Does your family support child marriage for girls?\nআপনার পরিবার কি কন্যার বাল্য বিবাহ সমর্থন করে?",
113
+ "mentality_about_boy_marriage": "Does your family support child marriage for boys?\nআপনার পরিবার কি পুত্রের বাল্য বিবাহ সমর্থন করে?",
114
+ "Financial_support_num": "Does your family receive any financial support?\nআপনার পরিবার কি কোনো আর্থিক সহায়তা পায়?",
115
+ }
116
+
117
+ # ======================================================
118
+ # LOAD MODEL
119
+ # ======================================================
120
+ if not os.path.exists(MODEL_PATH):
121
+ raise FileNotFoundError("❌ Model file not found")
122
+
123
+ model = joblib.load(MODEL_PATH)
124
+
125
+ # ======================================================
126
+ # PREDICTION FUNCTION
127
+ # ======================================================
128
+ def predict(
129
+ region, no_mem, income, expend,
130
+ ed_father, ed_mother, ed_vict,
131
+ parent_em, past_em, instab, female_work,
132
+ current, social_inc, girl_ment, boy_ment,
133
+ fin_support
134
+ ):
135
+ values = [
136
+ REGION_MAP[region],
137
+ float(no_mem),
138
+ float(income),
139
+ float(expend),
140
+ EDUCATION_MAP[ed_father],
141
+ EDUCATION_MAP[ed_mother],
142
+ EDUCATION_MAP[ed_vict],
143
+ YES_NO_MAP[parent_em],
144
+ YES_NO_MAP[past_em],
145
+ YES_NO_MAP[instab],
146
+ YES_NO_MAP[female_work],
147
+ MARITAL_STATUS_MAP[current],
148
+ YES_NO_MAP[social_inc],
149
+ YES_NO_MAP[girl_ment],
150
+ YES_NO_MAP[boy_ment],
151
+ YES_NO_MAP[fin_support],
152
+ ]
153
+
154
+ X = pd.DataFrame([values], columns=FEATURE_COLUMNS)
155
+
156
+ pred = int(model.predict(X)[0])
157
+ proba = model.predict_proba(X)[0]
158
+
159
+ raw_conf = proba[1] if pred == 1 else proba[0]
160
+ display_conf = min(100.0, max(80.0, 80 + 20 * raw_conf))
161
+
162
+ if pred == 1:
163
+ result = (
164
+ "⚠️ HIGH RISK: Child Marriage Likely\n"
165
+ "উচ্চ ঝুঁকি: বাল্য বিবাহের সম্ভাবনা রয়েছে\n\n"
166
+ "Suggestions / পরামর্শ:\n"
167
+ "• Educational counseling is recommended\n"
168
+ "• Seek NGO or community support\n"
169
+ "• Family awareness and dialogue are important\n\n"
170
+ "• শিক্ষাগত পরামর্শ গ্রহণ করা প্রয়োজন\n"
171
+ "• এনজিও বা সামাজিক সহায়তা নিন\n"
172
+ "• আপনার পরিবারে সচেতন আলোচনা জরুরি"
173
+ )
174
+ else:
175
+ result = (
176
+ "✅ LOW RISK: Child Marriage Unlikely\n"
177
+ "কম ঝুঁকি: বাল্য বিবাহের সম্ভাবনা কম\n\n"
178
+ "Suggestions / পরামর্শ:\n"
179
+ "• Continue education\n"
180
+ "• Maintain family awareness\n"
181
+ "• Support peers who may be at risk\n\n"
182
+ "• শিক্ষার ধারাবাহিকতা বজায় রাখুন\n"
183
+ "• আপনার পরিবারে সচেতনতা ধরে রাখুন\n"
184
+ "• ঝুঁকিতে থাকা অন্যদের সহায়তা করুন"
185
+ )
186
+
187
+ return result, f"{display_conf:.2f}%"
188
+
189
+ # ======================================================
190
+ # ACADEMIC CSS (Times + Smaller Bangla)
191
+ # ======================================================
192
+ academic_css = """
193
+ .gradio-container {
194
+ font-family: "Times New Roman", Times, "Liberation Serif", serif;
195
+ max-width: 1200px;
196
+ margin: auto;
197
+ }
198
+
199
+ h1, h2, h3 {
200
+ font-weight: 700;
201
+ }
202
+
203
+ /* English base */
204
+ label span {
205
+ font-size: 15px;
206
+ line-height: 1.6;
207
+ }
208
+
209
+ /* Bangla slightly smaller (~ −1.5pt) */
210
+ label span span {
211
+ font-size: 13.5px;
212
+ }
213
+
214
+ /* Inputs */
215
+ textarea, input, select {
216
+ font-family: "Times New Roman", Times, "Liberation Serif", serif;
217
+ font-size: 14px;
218
+ }
219
+ """
220
+
221
+ # ======================================================
222
+ # UI
223
+ # ======================================================
224
+ with gr.Blocks(theme=gr.themes.Soft(), css=academic_css) as demo:
225
+
226
+ gr.Markdown("""
227
+ # **Predictive Insights into Child Marriage**
228
+ ### সামাজিক ও অর্থনৈতিক তথ্যের ভিত্তিতে বাল্য বিবাহের ঝুঁকি নির্ধারণ
229
+ ---
230
+ """)
231
+
232
+ with gr.Row():
233
+ with gr.Column():
234
+ region = gr.Dropdown(list(REGION_MAP.keys()), label=QUESTIONS["Region"])
235
+ no_mem = gr.Number(label=QUESTIONS["No_mem"], value=5)
236
+ income = gr.Number(label=QUESTIONS["Income_monthly"], value=5000)
237
+ expend = gr.Number(label=QUESTIONS["Expend_monthly"], value=4500)
238
+
239
+ ed_father = gr.Dropdown(list(EDUCATION_MAP.keys()), label=QUESTIONS["Ed_father"])
240
+ ed_mother = gr.Dropdown(list(EDUCATION_MAP.keys()), label=QUESTIONS["Ed_mother"])
241
+ ed_vict = gr.Dropdown(list(EDUCATION_MAP.keys()), label=QUESTIONS["Ed_vict"])
242
+
243
+ with gr.Column():
244
+ parent_em = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["parent_early_marriage"])
245
+ past_em = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["Past_histroy"])
246
+ instab = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["Instablity_num"])
247
+ female_work = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["Female_working"])
248
+
249
+ current = gr.Dropdown(list(MARITAL_STATUS_MAP.keys()), label=QUESTIONS["Current_Situation"])
250
+
251
+ social_inc = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["Social_inc_num"])
252
+ girl_ment = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["mentality_about_girl_marriage"])
253
+ boy_ment = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["mentality_about_boy_marriage"])
254
+ fin_support = gr.Radio(list(YES_NO_MAP.keys()), label=QUESTIONS["Financial_support_num"])
255
+
256
+ predict_btn = gr.Button("🔮 Predict Child Marriage Risk")
257
+ result_box = gr.Textbox(label="Result / ফলাফল", lines=12)
258
+ conf_box = gr.Textbox(label="Confidence / নির্ভরযোগ্যতা")
259
+
260
+ predict_btn.click(
261
+ fn=predict,
262
+ inputs=[
263
+ region, no_mem, income, expend,
264
+ ed_father, ed_mother, ed_vict,
265
+ parent_em, past_em, instab, female_work,
266
+ current, social_inc, girl_ment, boy_ment,
267
+ fin_support
268
+ ],
269
+ outputs=[result_box, conf_box]
270
+ )
271
+
272
+ gr.Markdown("""
273
+ ---
274
+ ⚠️ **Disclaimer**
275
+ This tool is for research and awareness purposes only.
276
+ অনুগ্রহ করে বাল্য বিবাহ সংক্রান্ত সকল বিষয়ে স্থানীয় আইন ও পেশাদার পরামর্শ অনুসরণ করুন।
277
+ """)
278
+
279
+ demo.launch(share=True)
data.xlsx ADDED
Binary file (54.1 kB). View file
 
early_marriage_stack_classifier.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:572b8e9b18a569b00d1d366a117b89f443426da046f2b77d29614be2759bc890
3
+ size 4440869
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ gradio==4.44.1
2
+ pandas
3
+ numpy
4
+ scikit-learn
5
+ joblib