mabera commited on
Commit
06ee743
Β·
verified Β·
1 Parent(s): 01903b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +85 -4
app.py CHANGED
@@ -133,15 +133,72 @@ This is the exact calculation method used to build and verify all 28 national su
133
  *Nigeria AMR Classifier v2 β€” Fine-tuned Llama 3.3 70B | AutoScientist 2026 | Science Category*
134
  """
135
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
136
  # ══════════════════════════════════════════════════════════
137
  # ── Build Interface ─────────────────────────────────────────
138
  # ══════════════════════════════════════════════════════════
139
  with gr.Blocks(title="Africa Science AI") as demo:
140
  gr.Markdown("""
141
- # 🌍🧫 Africa Science AI Demo
142
- ## AutoScientist Challenge 2026, Part 2 | Science Category
143
  **Author:** Hussein Adeiza (mabera) β€” Licensed Environmental Health Officer, Abuja Nigeria
144
- **Two models:** HIV Funding Analysis (Llama 4 Scout) + AMR Classifier v2 (Llama 3.3 70B)
145
  **Powered by Adaptive Data β€” Adaption Labs**
146
  """)
147
 
@@ -193,6 +250,27 @@ with gr.Blocks(title="Africa Science AI") as demo:
193
  rate_output = gr.Markdown()
194
  rate_btn.click(classify_rate, inputs=[n_tested, n_nonsusceptible], outputs=rate_output)
195
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  gr.Markdown("""
197
  ---
198
  ### Models β€” Open Source
@@ -200,11 +278,14 @@ with gr.Blocks(title="Africa Science AI") as demo:
200
  |-------|----------|----------|---------|------|
201
  | HIV Funding Analysis (Llama 4 Scout) | Science | 71% (60% general) | 6.0β†’6.5, Grade C | Domain classification issue disclosed |
202
  | AMR Classifier v2 (Llama 3.3 70B) | Science | 58% (71% general) | 8.0β†’8.7, Grade B | 34/34 rows verified |
 
203
 
204
  πŸ€— [HIV Model](https://huggingface.co/mabera/africa-hiv-funding-analysis-model) |
205
  πŸ€— [AMR Model](https://huggingface.co/mabera/nigeria-amr-classifier-v2) |
 
206
  πŸ€— [HIV Dataset](https://huggingface.co/datasets/mabera/africa-hiv-funding-dataset) |
207
- πŸ€— [AMR Dataset](https://huggingface.co/datasets/mabera/nigeria-amr-classifier-v2-dataset)
 
208
 
209
  ### Other Portfolio Demos
210
  - Part 1 (Healthcare, Legal, Marketing, Finance, Language): [nigeria-health-ai-demo](https://huggingface.co/spaces/mabera/nigeria-health-ai-demo)
 
133
  *Nigeria AMR Classifier v2 β€” Fine-tuned Llama 3.3 70B | AutoScientist 2026 | Science Category*
134
  """
135
 
136
+ # ══════════════════════════════════════════════════════════
137
+ # ── Loan Classification Closed-Label Classifier ──────────────
138
+ # ══════════════════════════════════════════════════════════
139
+ @spaces.GPU
140
+ def classify_loan_days(days):
141
+ if days is None or days < 0:
142
+ return "Please enter a valid number of days past due (0 or greater)."
143
+
144
+ days = int(days)
145
+ if days <= 89:
146
+ classification, provision, color = "Performing", "1% (general provision)", "🟒"
147
+ elif days <= 179:
148
+ classification, provision, color = "Substandard", "10%", "🟑"
149
+ elif days <= 359:
150
+ classification, provision, color = "Doubtful", "50%", "🟠"
151
+ else:
152
+ classification, provision, color = "Lost", "100% (full provision, written off)", "πŸ”΄"
153
+
154
+ return f"""
155
+ ## {color} Classification: {classification}
156
+
157
+ **Your input:** {days} days past due
158
+
159
+ **Required provisioning:** {provision}
160
+
161
+ **CBN Prudential Guidelines thresholds:** Performing (0-89 days), Substandard (90-179 days), Doubtful (180-359 days), Lost (360+ days)
162
+
163
+ This classification was computed live from your input against the real CBN Prudential Guidelines registry, the same deterministic logic used to build and verify all 20 rows in the training dataset.
164
+
165
+ ---
166
+ *Nigeria Loan Classifier v2 β€” Fine-tuned Llama 4 Scout 17B-16E | AutoScientist 2026 | Personal Finance Category*
167
+ """
168
+
169
+ @spaces.GPU
170
+ def classify_npl_ratio(npl_ratio):
171
+ if npl_ratio is None or npl_ratio < 0:
172
+ return "Please enter a valid NPL ratio percentage."
173
+
174
+ ratio = float(npl_ratio)
175
+ status = "Compliant" if ratio < 5.0 else "Breach"
176
+ color = "🟒" if status == "Compliant" else "πŸ”΄"
177
+
178
+ return f"""
179
+ ## {color} Classification: {status}
180
+
181
+ **Your input:** {ratio}% NPL ratio
182
+
183
+ **CBN regulatory threshold:** 5.0%
184
+
185
+ **Result:** {ratio}% {'is below' if status == 'Compliant' else 'exceeds'} the 5% threshold
186
+
187
+ This is the exact classification method used to verify all 9 bank/industry-level rows in the training dataset, including a real near-miss case at 4.99%.
188
+
189
+ ---
190
+ *Nigeria Loan Classifier v2 β€” Fine-tuned Llama 4 Scout 17B-16E | AutoScientist 2026 | Personal Finance Category*
191
+ """
192
+
193
  # ══════════════════════════════════════════════════════════
194
  # ── Build Interface ─────────────────────────────────────────
195
  # ══════════════════════════════════════════════════════════
196
  with gr.Blocks(title="Africa Science AI") as demo:
197
  gr.Markdown("""
198
+ # 🌍🧫🏦 Africa Science & Finance AI Demo
199
+ ## AutoScientist Challenge 2026, Part 2
200
  **Author:** Hussein Adeiza (mabera) β€” Licensed Environmental Health Officer, Abuja Nigeria
201
+ **Three models:** HIV Funding Analysis + AMR Classifier v2 + Nigeria Loan Classifier v2
202
  **Powered by Adaptive Data β€” Adaption Labs**
203
  """)
204
 
 
250
  rate_output = gr.Markdown()
251
  rate_btn.click(classify_rate, inputs=[n_tested, n_nonsusceptible], outputs=rate_output)
252
 
253
+ with gr.Tab("🏦 Loan: Days Past Due Classification"):
254
+ gr.Markdown("### Enter a loan's days past due and see the CBN classification computed live")
255
+ gr.Markdown("⚠️ Closed-label classification: results are deterministically computed, not generated. Honest note: this model's win rate was below 50% (base model outperformed adapted); full disclosure in the model card.")
256
+ with gr.Row():
257
+ with gr.Column():
258
+ loan_days = gr.Number(label="Days past due", value=45, precision=0)
259
+ loan_days_btn = gr.Button("🏦 Classify Loan", variant="primary")
260
+ with gr.Column():
261
+ loan_days_output = gr.Markdown()
262
+ loan_days_btn.click(classify_loan_days, inputs=[loan_days], outputs=loan_days_output)
263
+
264
+ with gr.Tab("🏦 Loan: NPL Ratio Compliance"):
265
+ gr.Markdown("### Enter a bank or industry NPL ratio and see CBN compliance computed live")
266
+ with gr.Row():
267
+ with gr.Column():
268
+ npl_input = gr.Number(label="NPL ratio (%)", value=4.99, precision=2)
269
+ npl_btn = gr.Button("🏦 Check Compliance", variant="primary")
270
+ with gr.Column():
271
+ npl_output = gr.Markdown()
272
+ npl_btn.click(classify_npl_ratio, inputs=[npl_input], outputs=npl_output)
273
+
274
  gr.Markdown("""
275
  ---
276
  ### Models β€” Open Source
 
278
  |-------|----------|----------|---------|------|
279
  | HIV Funding Analysis (Llama 4 Scout) | Science | 71% (60% general) | 6.0β†’6.5, Grade C | Domain classification issue disclosed |
280
  | AMR Classifier v2 (Llama 3.3 70B) | Science | 58% (71% general) | 8.0β†’8.7, Grade B | 34/34 rows verified |
281
+ | Loan Classifier v2 (Llama 4 Scout) | Personal Finance | 40% (45% general) | 8.0β†’8.4, Grade B | 20/20 rows verified; win rate honestly disclosed |
282
 
283
  πŸ€— [HIV Model](https://huggingface.co/mabera/africa-hiv-funding-analysis-model) |
284
  πŸ€— [AMR Model](https://huggingface.co/mabera/nigeria-amr-classifier-v2) |
285
+ πŸ€— [Loan Model](https://huggingface.co/mabera/nigeria-loan-classifier-v2) |
286
  πŸ€— [HIV Dataset](https://huggingface.co/datasets/mabera/africa-hiv-funding-dataset) |
287
+ πŸ€— [AMR Dataset](https://huggingface.co/datasets/mabera/nigeria-amr-classifier-v2-dataset) |
288
+ πŸ€— [Loan Dataset](https://huggingface.co/datasets/mabera/nigeria-loan-classifier-v2-dataset)
289
 
290
  ### Other Portfolio Demos
291
  - Part 1 (Healthcare, Legal, Marketing, Finance, Language): [nigeria-health-ai-demo](https://huggingface.co/spaces/mabera/nigeria-health-ai-demo)