Spaces:
Running on Zero
Running on Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,8 +1,8 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
|
| 4 |
-
# Africa Science AI Demo β
|
| 5 |
-
# AutoScientist Challenge 2026, Part 2
|
| 6 |
# Author: Hussein Adeiza (mabera) β Licensed Environmental Health Officer, Abuja Nigeria
|
| 7 |
|
| 8 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -10,127 +10,57 @@ import spaces
|
|
| 10 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 11 |
HIV_EXAMPLES = {
|
| 12 |
"Regional donor dependency split (West/Central vs East/Southern Africa)": {
|
| 13 |
-
"stats": "Donors cover approximately 90 percent of antiretroviral (ARV) drug costs in West and Central Africa, compared to approximately 38 percent in East and Southern Africa. Several high-burden East and Southern African countries are almost entirely dependent on PEPFAR specifically for HIV prevention programs: Malawi at 88.5 percent, Zimbabwe at 82.7 percent, and Mozambique at 81.8 percent.
|
| 14 |
-
"interpretation": "The regional split matters more than the continental average suggests: West and Central Africa's near-total donor dependency for treatment costs
|
| 15 |
},
|
| 16 |
"The 2025 PrEP collapse and Nigeria's disproportionate hit": {
|
| 17 |
-
"stats": "PrEP use across 62 reporting countries fell from 3.3 million people in 2024 to 2.1 million in 2025, a 38 percent decline
|
| 18 |
-
"interpretation": "The gap between the 38 percent multi-country
|
| 19 |
-
},
|
| 20 |
-
"Mozambique: a real, measured case study": {
|
| 21 |
-
"stats": "In Mozambique, where PEPFAR has funded roughly two-thirds of the national HIV program for over a decade, comparing February to May 2025 against the same period in 2024 shows more than 15,000 fewer people started antiretroviral treatment, a 14 percent reduction. Viral load testing fell 38 percent in adults and 44 percent in children, while viral suppression rates among those tested fell 33 percent in adults and 43 percent in children.",
|
| 22 |
-
"interpretation": "The consistent pattern of children being harder hit than adults across both viral load testing and viral suppression suggests pediatric HIV services in Mozambique were more concentrated in the disrupted funding stream than adult services. This four-month snapshot from a single country provides a concrete, measured example of what larger continental modeling projections describe in the abstract."
|
| 23 |
-
},
|
| 24 |
-
"2030 modeling: why treatment funding matters as much as prevention": {
|
| 25 |
-
"stats": "Modeling presented at the 2025 International AIDS Society Conference projected two scenarios through 2030. A moderate scenario, with prevention and testing funding cut by 24 percent by 2026 but treatment sustained by domestic funding, would result in 71,500 to 1.7 million additional new HIV infections. A severe scenario, adding full PEPFAR discontinuation, would result in 4.4 million to 10.8 million additional new infections.",
|
| 26 |
-
"interpretation": "The roughly 6-fold jump in the upper-bound infection estimate between the moderate and severe scenarios is not proportional to the funding change, since the severe scenario only adds full PEPFAR discontinuation on top of the same prevention cuts. This indicates that treatment funding, not just prevention funding, plays an outsized protective role against new infections."
|
| 27 |
-
},
|
| 28 |
-
"The resilience counter-narrative: treatment held, prevention didn't": {
|
| 29 |
-
"stats": "Despite the 2025 funding disruptions, the number of people on antiretroviral treatment globally rose 2.7 percent year-on-year to 32.1 million by December 2025, though below the roughly 4 percent historical average. Domestic funding's share of total HIV resources in low and middle-income countries rose to approximately 52 percent in 2024, up from 28 percent in 2010.",
|
| 30 |
-
"interpretation": "The continued growth in treatment numbers despite the funding shock indicates the treatment system had more built-in resilience than the prevention system. Domestic funding growth, while a genuine long-term positive trend, is not currently happening at a scale capable of substituting for the 2025 funding shock."
|
| 31 |
},
|
| 32 |
}
|
| 33 |
|
| 34 |
@spaces.GPU
|
| 35 |
def interpret_hiv_stats(selected_example, custom_stats):
|
| 36 |
if custom_stats and custom_stats.strip():
|
| 37 |
-
return f""
|
| 38 |
-
## π HIV Funding & Response Interpretation
|
| 39 |
-
**Input stats:** {custom_stats}
|
| 40 |
-
**Note:** This is a demo using pre-built reference interpretations. Try a dropdown example for a real cited interpretation.
|
| 41 |
-
---
|
| 42 |
-
*Africa HIV Funding Analysis Model β Fine-tuned Llama 4 Scout 17B-16E | AutoScientist 2026 Part 2*
|
| 43 |
-
"""
|
| 44 |
example = HIV_EXAMPLES.get(selected_example, list(HIV_EXAMPLES.values())[0])
|
| 45 |
return f"""
|
| 46 |
## π HIV Funding & Response Interpretation
|
| 47 |
-
|
|
|
|
| 48 |
{example['stats']}
|
| 49 |
-
|
|
|
|
| 50 |
{example['interpretation']}
|
|
|
|
| 51 |
---
|
| 52 |
-
|
| 53 |
-
This dataset was intended for Science but the platform's classifier tagged it News/Governance, routing training to Llama 4 Scout 17B-16E rather than Llama 3.3 70B. Reported to Adaption before publishing. Win rate 71% on dataset, 60% General Win Rate (News-domain benchmark). Full disclosure in the model card.
|
| 54 |
|
| 55 |
-
*Africa HIV Funding Analysis Model
|
| 56 |
-
*Powered by Adaptive Data β Adaption Labs*
|
| 57 |
"""
|
| 58 |
|
| 59 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 60 |
# ββ AMR Closed-Label Classifier ββββββββββββββββββββββββββββββ
|
| 61 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 62 |
-
BREAKPOINTS = {
|
| 63 |
-
"Enterobacterales / Ampicillin": {"s_max": 8, "i_val": 16, "r_min": 32},
|
| 64 |
-
"Enterobacterales / Ceftriaxone": {"s_max": 1, "i_val": 2, "r_min": 4},
|
| 65 |
-
"Enterobacterales / Ciprofloxacin": {"s_max": 0.25, "i_val": 0.5, "r_min": 1},
|
| 66 |
-
"Enterobacterales / Meropenem": {"s_max": 1, "i_val": 2, "r_min": 4},
|
| 67 |
-
"Enterobacterales / Gentamicin": {"s_max": 4, "i_val": 8, "r_min": 16},
|
| 68 |
-
"Staphylococcus aureus / Oxacillin (MRSA screen)": {"s_max": 2, "i_val": None, "r_min": 4},
|
| 69 |
-
"Enterobacterales / Colistin (no S category)": {"s_max": None, "i_val": 2, "r_min": 4},
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
@spaces.GPU
|
| 73 |
-
def classify_mic(organism_antibiotic, mic_value):
|
| 74 |
-
bp = BREAKPOINTS.get(organism_antibiotic)
|
| 75 |
-
if bp is None or mic_value is None:
|
| 76 |
-
return "Please select a valid organism/antibiotic combination and enter a MIC value."
|
| 77 |
-
|
| 78 |
-
mic = float(mic_value)
|
| 79 |
-
if bp["s_max"] is not None and mic <= bp["s_max"]:
|
| 80 |
-
result, color = "Susceptible", "π’"
|
| 81 |
-
elif bp["r_min"] is not None and mic >= bp["r_min"]:
|
| 82 |
-
result, color = "Resistant", "π΄"
|
| 83 |
-
else:
|
| 84 |
-
result, color = "Intermediate", "π‘"
|
| 85 |
-
|
| 86 |
-
s_str = f"β€{bp['s_max']}" if bp["s_max"] is not None else "none (no S category)"
|
| 87 |
-
i_str = f"{bp['i_val']}" if bp["i_val"] is not None else "none (no I category)"
|
| 88 |
-
r_str = f"β₯{bp['r_min']}" if bp["r_min"] is not None else "n/a"
|
| 89 |
-
|
| 90 |
-
return f"""
|
| 91 |
-
## {color} Classification: {result}
|
| 92 |
-
|
| 93 |
-
**Your input:** {organism_antibiotic}, MIC = {mic} ug/mL
|
| 94 |
-
|
| 95 |
-
**CLSI M100 (2025) breakpoints applied:**
|
| 96 |
-
- Susceptible: {s_str}
|
| 97 |
-
- Intermediate: {i_str}
|
| 98 |
-
- Resistant: {r_str}
|
| 99 |
-
|
| 100 |
-
This classification was computed live from your input against the real CLSI breakpoint registry, the same deterministic logic used to build and verify every row in the training dataset.
|
| 101 |
-
|
| 102 |
-
---
|
| 103 |
-
*Nigeria AMR Classifier v2 β Fine-tuned Llama 3.3 70B | AutoScientist 2026 | Science Category*
|
| 104 |
-
"""
|
| 105 |
-
|
| 106 |
@spaces.GPU
|
| 107 |
def classify_rate(n_tested, n_nonsusceptible):
|
| 108 |
if not n_tested or n_tested <= 0:
|
| 109 |
-
return "Please enter a valid number of isolates tested
|
| 110 |
-
if n_nonsusceptible is None or n_nonsusceptible < 0:
|
| 111 |
-
return "Please enter a valid
|
| 112 |
-
if n_nonsusceptible > n_tested:
|
| 113 |
-
return "Non-susceptible count cannot exceed the number tested."
|
| 114 |
|
| 115 |
rate = round((n_nonsusceptible / n_tested) * 100, 1)
|
| 116 |
-
if rate < 20
|
| 117 |
-
level, color = "Low", "π’"
|
| 118 |
-
elif rate <= 50:
|
| 119 |
-
level, color = "Moderate", "π‘"
|
| 120 |
-
else:
|
| 121 |
-
level, color = "High", "π΄"
|
| 122 |
|
| 123 |
return f"""
|
| 124 |
## {color} Resistance Rate: {rate}% β {level} Resistance
|
| 125 |
|
| 126 |
-
**Calculation:** {int(n_nonsusceptible)} / {int(n_tested)}
|
| 127 |
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
This is the exact calculation method used to build and verify all 28 national surveillance rows in the training dataset, each independently recomputed against Nigeria's real MAAP/Fleming Fund surveillance report.
|
| 131 |
|
| 132 |
---
|
| 133 |
-
*Nigeria AMR Classifier v2
|
| 134 |
"""
|
| 135 |
|
| 136 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
@@ -139,156 +69,179 @@ This is the exact calculation method used to build and verify all 28 national su
|
|
| 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
|
| 143 |
-
|
| 144 |
days = int(days)
|
| 145 |
if days <= 89:
|
| 146 |
-
|
| 147 |
elif days <= 179:
|
| 148 |
-
|
| 149 |
elif days <= 359:
|
| 150 |
-
|
| 151 |
else:
|
| 152 |
-
|
| 153 |
|
| 154 |
return f"""
|
| 155 |
-
## {color} Classification: {
|
| 156 |
|
| 157 |
-
**
|
| 158 |
|
| 159 |
-
**
|
| 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
|
| 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
|
| 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 |
-
**
|
| 182 |
|
| 183 |
-
|
| 184 |
|
| 185 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 186 |
|
| 187 |
-
|
|
|
|
| 188 |
|
| 189 |
---
|
| 190 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 191 |
"""
|
| 192 |
|
| 193 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 194 |
# ββ Build Interface βββββββββββββββββββββββββββββββββββββββββ
|
| 195 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 196 |
-
with gr.Blocks(title="Africa Science AI") as demo:
|
| 197 |
gr.Markdown("""
|
| 198 |
-
# ππ§«π¦ Africa Science &
|
| 199 |
## AutoScientist Challenge 2026, Part 2
|
| 200 |
**Author:** Hussein Adeiza (mabera) β Licensed Environmental Health Officer, Abuja Nigeria
|
| 201 |
-
**
|
| 202 |
**Powered by Adaptive Data β Adaption Labs**
|
| 203 |
""")
|
| 204 |
|
| 205 |
with gr.Tabs():
|
| 206 |
-
with gr.Tab("π HIV Funding & Response
|
| 207 |
-
gr.Markdown("### Raw HIV funding
|
| 208 |
-
gr.Markdown("β οΈ Built on real, cited UNAIDS, IAS 2025, Health Policy Watch, and CNBC Africa reporting.")
|
| 209 |
with gr.Row():
|
| 210 |
with gr.Column():
|
| 211 |
-
hiv_example = gr.Dropdown(
|
| 212 |
-
|
| 213 |
-
|
| 214 |
-
label="Select a real cited finding"
|
| 215 |
-
)
|
| 216 |
-
hiv_custom = gr.Textbox(
|
| 217 |
-
label="Or paste your own HIV funding/epidemiological stats (demo mode)",
|
| 218 |
-
placeholder="e.g. PrEP use fell from N to N between year and year...",
|
| 219 |
-
lines=2
|
| 220 |
-
)
|
| 221 |
-
hiv_btn = gr.Button("π Interpret HIV Funding Data", variant="primary")
|
| 222 |
with gr.Column():
|
| 223 |
hiv_output = gr.Markdown()
|
| 224 |
hiv_btn.click(interpret_hiv_stats, inputs=[hiv_example, hiv_custom], outputs=hiv_output)
|
| 225 |
|
| 226 |
-
with gr.Tab("π§ͺ AMR:
|
| 227 |
-
gr.Markdown("### Enter
|
| 228 |
-
gr.Markdown("β οΈ Closed-label classification: results are deterministically computed, not generated.")
|
| 229 |
-
with gr.Row():
|
| 230 |
-
with gr.Column():
|
| 231 |
-
mic_organism = gr.Dropdown(
|
| 232 |
-
choices=list(BREAKPOINTS.keys()),
|
| 233 |
-
value=list(BREAKPOINTS.keys())[0],
|
| 234 |
-
label="Organism / Antibiotic"
|
| 235 |
-
)
|
| 236 |
-
mic_value = gr.Number(label="Measured MIC (ug/mL)", value=0.5, precision=3)
|
| 237 |
-
mic_btn = gr.Button("π§ͺ Classify", variant="primary")
|
| 238 |
-
with gr.Column():
|
| 239 |
-
mic_output = gr.Markdown()
|
| 240 |
-
mic_btn.click(classify_mic, inputs=[mic_organism, mic_value], outputs=mic_output)
|
| 241 |
-
|
| 242 |
-
with gr.Tab("π AMR: Surveillance Rate Classification"):
|
| 243 |
-
gr.Markdown("### Enter isolate counts and see the resistance rate computed live")
|
| 244 |
with gr.Row():
|
| 245 |
with gr.Column():
|
| 246 |
n_tested = gr.Number(label="Isolates tested (N)", value=2528, precision=0)
|
| 247 |
-
n_nonsusceptible = gr.Number(label="Non-susceptible
|
| 248 |
-
rate_btn = gr.Button("
|
| 249 |
with gr.Column():
|
| 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
|
| 254 |
-
gr.Markdown("### Enter
|
| 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
|
| 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
|
| 265 |
-
gr.Markdown("### Enter
|
| 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
|
| 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
|
| 277 |
| Model | Category | Win Rate | Quality | Note |
|
| 278 |
|-------|----------|----------|---------|------|
|
| 279 |
-
| HIV Funding Analysis
|
| 280 |
-
| AMR Classifier v2
|
| 281 |
-
| Loan Classifier v2
|
|
|
|
| 282 |
|
| 283 |
-
π€ [HIV
|
| 284 |
-
π€ [AMR
|
| 285 |
-
π€ [Loan
|
| 286 |
-
π€ [
|
| 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
|
| 292 |
- Part 2 Agriculture: [nigeria-agriculture-ai](https://huggingface.co/spaces/mabera/nigeria-agriculture-ai)
|
| 293 |
""")
|
| 294 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import spaces
|
| 3 |
|
| 4 |
+
# Africa Science & Finance AI Demo β Full Portfolio
|
| 5 |
+
# AutoScientist Challenge 2026, Part 2
|
| 6 |
# Author: Hussein Adeiza (mabera) β Licensed Environmental Health Officer, Abuja Nigeria
|
| 7 |
|
| 8 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 10 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 11 |
HIV_EXAMPLES = {
|
| 12 |
"Regional donor dependency split (West/Central vs East/Southern Africa)": {
|
| 13 |
+
"stats": "Donors cover approximately 90 percent of antiretroviral (ARV) drug costs in West and Central Africa, compared to approximately 38 percent in East and Southern Africa. Several high-burden East and Southern African countries are almost entirely dependent on PEPFAR specifically for HIV prevention programs: Malawi at 88.5 percent, Zimbabwe at 82.7 percent, and Mozambique at 81.8 percent.",
|
| 14 |
+
"interpretation": "The regional split matters more than the continental average suggests: West and Central Africa's near-total donor dependency for treatment costs means any disruption there would affect ongoing ARV supply directly, while East and Southern Africa's lower regional average masks enormous country-level variance specifically in prevention funding."
|
| 15 |
},
|
| 16 |
"The 2025 PrEP collapse and Nigeria's disproportionate hit": {
|
| 17 |
+
"stats": "PrEP use across 62 reporting countries fell from 3.3 million people in 2024 to 2.1 million in 2025, a 38 percent decline. In Nigeria specifically, monthly PrEP initiations fell from approximately 40,000 to approximately 6,000 following budget cuts, an 85 percent reduction.",
|
| 18 |
+
"interpretation": "The gap between the 38 percent multi-country decline and Nigeria's 85 percent collapse suggests Nigeria's prevention infrastructure was disproportionately exposed, likely reflecting how concentrated Nigeria's PrEP delivery was within externally funded programs rather than blended with domestic health system capacity."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 19 |
},
|
| 20 |
}
|
| 21 |
|
| 22 |
@spaces.GPU
|
| 23 |
def interpret_hiv_stats(selected_example, custom_stats):
|
| 24 |
if custom_stats and custom_stats.strip():
|
| 25 |
+
return f"## π HIV Funding Interpretation\n\n**Input:** {custom_stats}\n\n*Demo mode, select a dropdown example for a cited interpretation.*"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
example = HIV_EXAMPLES.get(selected_example, list(HIV_EXAMPLES.values())[0])
|
| 27 |
return f"""
|
| 28 |
## π HIV Funding & Response Interpretation
|
| 29 |
+
|
| 30 |
+
**Raw cited statistics:**
|
| 31 |
{example['stats']}
|
| 32 |
+
|
| 33 |
+
**Structured interpretation:**
|
| 34 |
{example['interpretation']}
|
| 35 |
+
|
| 36 |
---
|
| 37 |
+
β οΈ Domain classification issue disclosed: trained on Llama 4 Scout (News-domain routing), not Llama 3.3 70B. Win rate 71% on dataset, 60% General Win Rate.
|
|
|
|
| 38 |
|
| 39 |
+
*Africa HIV Funding Analysis Model | AutoScientist 2026 Part 2*
|
|
|
|
| 40 |
"""
|
| 41 |
|
| 42 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 43 |
# ββ AMR Closed-Label Classifier ββββββββββββββββββββββββββββββ
|
| 44 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
@spaces.GPU
|
| 46 |
def classify_rate(n_tested, n_nonsusceptible):
|
| 47 |
if not n_tested or n_tested <= 0:
|
| 48 |
+
return "Please enter a valid number of isolates tested."
|
| 49 |
+
if n_nonsusceptible is None or n_nonsusceptible < 0 or n_nonsusceptible > n_tested:
|
| 50 |
+
return "Please enter a valid non-susceptible count (0 to N)."
|
|
|
|
|
|
|
| 51 |
|
| 52 |
rate = round((n_nonsusceptible / n_tested) * 100, 1)
|
| 53 |
+
level, color = ("Low", "π’") if rate < 20 else ("Moderate", "π‘") if rate <= 50 else ("High", "π΄")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 54 |
|
| 55 |
return f"""
|
| 56 |
## {color} Resistance Rate: {rate}% β {level} Resistance
|
| 57 |
|
| 58 |
+
**Calculation:** {int(n_nonsusceptible)} / {int(n_tested)} Γ 100 = {rate}%
|
| 59 |
|
| 60 |
+
Same calculation method used to build and verify all 28 national surveillance rows against Nigeria's real MAAP/Fleming Fund report.
|
|
|
|
|
|
|
| 61 |
|
| 62 |
---
|
| 63 |
+
*Nigeria AMR Classifier v2 | Win rate 58% (71% general) | AutoScientist 2026*
|
| 64 |
"""
|
| 65 |
|
| 66 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 69 |
@spaces.GPU
|
| 70 |
def classify_loan_days(days):
|
| 71 |
if days is None or days < 0:
|
| 72 |
+
return "Please enter a valid number of days past due."
|
|
|
|
| 73 |
days = int(days)
|
| 74 |
if days <= 89:
|
| 75 |
+
c, p, color = "Performing", "1%", "π’"
|
| 76 |
elif days <= 179:
|
| 77 |
+
c, p, color = "Substandard", "10%", "π‘"
|
| 78 |
elif days <= 359:
|
| 79 |
+
c, p, color = "Doubtful", "50%", "π "
|
| 80 |
else:
|
| 81 |
+
c, p, color = "Lost", "100%", "π΄"
|
| 82 |
|
| 83 |
return f"""
|
| 84 |
+
## {color} Classification: {c}
|
| 85 |
|
| 86 |
+
**Input:** {days} days past due | **Required provisioning:** {p}
|
| 87 |
|
| 88 |
+
**CBN thresholds:** Performing (0-89), Substandard (90-179), Doubtful (180-359), Lost (360+)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 89 |
|
| 90 |
---
|
| 91 |
+
*Nigeria Loan Classifier v2 | Win rate 40% (45% general), honestly disclosed | AutoScientist 2026*
|
| 92 |
"""
|
| 93 |
|
| 94 |
@spaces.GPU
|
| 95 |
def classify_npl_ratio(npl_ratio):
|
| 96 |
if npl_ratio is None or npl_ratio < 0:
|
| 97 |
+
return "Please enter a valid NPL ratio."
|
|
|
|
| 98 |
ratio = float(npl_ratio)
|
| 99 |
+
status, color = ("Compliant", "π’") if ratio < 5.0 else ("Breach", "π΄")
|
|
|
|
| 100 |
|
| 101 |
return f"""
|
| 102 |
## {color} Classification: {status}
|
| 103 |
|
| 104 |
+
**Input:** {ratio}% NPL ratio | **CBN threshold:** 5.0%
|
| 105 |
|
| 106 |
+
Same method used to verify all 9 bank/industry rows, including a real near-miss case at 4.99%.
|
| 107 |
|
| 108 |
+
---
|
| 109 |
+
*Nigeria Loan Classifier v2 | AutoScientist 2026*
|
| 110 |
+
"""
|
| 111 |
+
|
| 112 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 113 |
+
# ββ Nigeria Energy Access Interpreter (strongest result) βββββ
|
| 114 |
+
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 115 |
+
ENERGY_EXAMPLES = {
|
| 116 |
+
"2024β2025 gas-to-hydro shift": {
|
| 117 |
+
"stats": "Nigeria's generation mix, from Our World in Data: 2024, gas share 75.0%, hydro share 24.494%. 2025, gas share 68.681%, hydro share 30.862%.",
|
| 118 |
+
"interpretation": "Gas share fell by 6.3 percentage points while hydro share rose by 6.4 points between 2024 and 2025. This is a real, measurable one-year shift toward renewable generation, though gas remains dominant at over two-thirds of total generation. A single year of hydro gains could reflect improved rainfall rather than new capacity, this would need checking against rainfall data to confirm the driver."
|
| 119 |
+
},
|
| 120 |
+
"Nigeria vs World: the 22x per-capita gap": {
|
| 121 |
+
"stats": "Per-capita electricity access, 2025, from Our World in Data: Nigeria 174.9 kWh/person, World average 3,859.8 kWh/person.",
|
| 122 |
+
"interpretation": "The world average is 22.1 times higher than Nigeria's figure. With a population of over 237 million, this is not a small-country anomaly but a genuine national-scale electricity access gap. A gap this large reflects a fundamental shortfall in installed generation capacity and grid infrastructure relative to population size."
|
| 123 |
+
},
|
| 124 |
+
"Nigeria vs South Africa: same continent, vastly different access": {
|
| 125 |
+
"stats": "2025 comparison: Nigeria per-capita electricity 174.9 kWh (fossil share 68.7%), South Africa per-capita electricity 3,749.3 kWh (fossil share 82.2%).",
|
| 126 |
+
"interpretation": "South Africa's per-capita access is roughly 21.4 times higher than Nigeria's, despite South Africa having a far smaller population (65 million vs 237 million). Both countries rely heavily on fossil fuels, so the gap isn't about fuel choice, it's about the scale of generation capacity relative to population."
|
| 127 |
+
},
|
| 128 |
+
"25-year trend: the long game vs the recent uptick": {
|
| 129 |
+
"stats": "Nigeria's generation mix: 2000, gas share 61.7%, hydro share 38.2%. 2025, gas share 68.7%, hydro share 30.9%.",
|
| 130 |
+
"interpretation": "Over 25 years, gas share rose 6.9 percentage points while hydro fell 7.3 points, the long-term trend is toward increasing gas dependency, not away from it. A single recent year of hydro gains should not be read as reversing a 25-year structural trend without multiple years of confirmation."
|
| 131 |
+
},
|
| 132 |
+
"Solar's near-total absence despite equatorial advantage": {
|
| 133 |
+
"stats": "Solar share of generation, 2025: Nigeria 0.313%, World average 8.745%.",
|
| 134 |
+
"interpretation": "Nigeria's solar share sits at roughly 3.6% of the world average, despite Nigeria's equatorial location giving it higher and more consistent solar irradiance than most solar-adopting nations at higher latitudes. This gap points toward solar as a large, underexploited opportunity, though it wouldn't resolve underlying grid constraints alone."
|
| 135 |
+
},
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
@spaces.GPU
|
| 139 |
+
def interpret_energy_stats(selected_example, custom_stats):
|
| 140 |
+
if custom_stats and custom_stats.strip():
|
| 141 |
+
return f"## β‘ Energy Interpretation\n\n**Input:** {custom_stats}\n\n*Demo mode, select a dropdown example for a cited interpretation computed from the real downloaded data.*"
|
| 142 |
+
example = ENERGY_EXAMPLES.get(selected_example, list(ENERGY_EXAMPLES.values())[0])
|
| 143 |
+
return f"""
|
| 144 |
+
## β‘ Nigeria Energy Interpretation
|
| 145 |
+
|
| 146 |
+
**Raw statistics (from Our World in Data, downloaded directly):**
|
| 147 |
+
{example['stats']}
|
| 148 |
|
| 149 |
+
**Structured interpretation:**
|
| 150 |
+
{example['interpretation']}
|
| 151 |
|
| 152 |
---
|
| 153 |
+
### π Strongest result in this portfolio
|
| 154 |
+
**Win rate: 88% adapted vs 12% base | General Win Rate: 81% adapted vs 19% base**
|
| 155 |
+
|
| 156 |
+
Every number above traces directly to the raw, unmodified source file (owid_energy_full.csv), downloaded from github.com/owid/energy-data, not hand-typed. All claims independently re-verified.
|
| 157 |
+
|
| 158 |
+
*Nigeria Energy Access Interpreter β Fine-tuned Llama 3.3 70B | AutoScientist 2026 | Data Visualization Category*
|
| 159 |
"""
|
| 160 |
|
| 161 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 162 |
# ββ Build Interface βββββββββββββββββββββββββββββββββββββββββ
|
| 163 |
# ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
|
| 164 |
+
with gr.Blocks(title="Africa Science, Finance & Energy AI") as demo:
|
| 165 |
gr.Markdown("""
|
| 166 |
+
# ππ§«π¦β‘ Africa Science, Finance & Energy AI Demo
|
| 167 |
## AutoScientist Challenge 2026, Part 2
|
| 168 |
**Author:** Hussein Adeiza (mabera) β Licensed Environmental Health Officer, Abuja Nigeria
|
| 169 |
+
**Four models:** HIV Funding + AMR Classifier v2 + Loan Classifier v2 + Energy Access Interpreter
|
| 170 |
**Powered by Adaptive Data β Adaption Labs**
|
| 171 |
""")
|
| 172 |
|
| 173 |
with gr.Tabs():
|
| 174 |
+
with gr.Tab("π HIV Funding & Response"):
|
| 175 |
+
gr.Markdown("### Raw HIV funding stats in, structured interpretation out")
|
|
|
|
| 176 |
with gr.Row():
|
| 177 |
with gr.Column():
|
| 178 |
+
hiv_example = gr.Dropdown(choices=list(HIV_EXAMPLES.keys()), value=list(HIV_EXAMPLES.keys())[0], label="Select a cited finding")
|
| 179 |
+
hiv_custom = gr.Textbox(label="Or paste your own stats (demo mode)", lines=2)
|
| 180 |
+
hiv_btn = gr.Button("π Interpret", variant="primary")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 181 |
with gr.Column():
|
| 182 |
hiv_output = gr.Markdown()
|
| 183 |
hiv_btn.click(interpret_hiv_stats, inputs=[hiv_example, hiv_custom], outputs=hiv_output)
|
| 184 |
|
| 185 |
+
with gr.Tab("π§ͺ AMR: Surveillance Rate"):
|
| 186 |
+
gr.Markdown("### Enter isolate counts, see resistance rate computed live")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 187 |
with gr.Row():
|
| 188 |
with gr.Column():
|
| 189 |
n_tested = gr.Number(label="Isolates tested (N)", value=2528, precision=0)
|
| 190 |
+
n_nonsusceptible = gr.Number(label="Non-susceptible (n)", value=1766, precision=0)
|
| 191 |
+
rate_btn = gr.Button("π§ͺ Calculate", variant="primary")
|
| 192 |
with gr.Column():
|
| 193 |
rate_output = gr.Markdown()
|
| 194 |
rate_btn.click(classify_rate, inputs=[n_tested, n_nonsusceptible], outputs=rate_output)
|
| 195 |
|
| 196 |
+
with gr.Tab("π¦ Loan: Days Past Due"):
|
| 197 |
+
gr.Markdown("### Enter days past due, see CBN classification computed live")
|
|
|
|
| 198 |
with gr.Row():
|
| 199 |
with gr.Column():
|
| 200 |
loan_days = gr.Number(label="Days past due", value=45, precision=0)
|
| 201 |
+
loan_days_btn = gr.Button("π¦ Classify", variant="primary")
|
| 202 |
with gr.Column():
|
| 203 |
loan_days_output = gr.Markdown()
|
| 204 |
loan_days_btn.click(classify_loan_days, inputs=[loan_days], outputs=loan_days_output)
|
| 205 |
|
| 206 |
+
with gr.Tab("π¦ Loan: NPL Ratio"):
|
| 207 |
+
gr.Markdown("### Enter an NPL ratio, see CBN compliance computed live")
|
| 208 |
with gr.Row():
|
| 209 |
with gr.Column():
|
| 210 |
npl_input = gr.Number(label="NPL ratio (%)", value=4.99, precision=2)
|
| 211 |
+
npl_btn = gr.Button("π¦ Check", variant="primary")
|
| 212 |
with gr.Column():
|
| 213 |
npl_output = gr.Markdown()
|
| 214 |
npl_btn.click(classify_npl_ratio, inputs=[npl_input], outputs=npl_output)
|
| 215 |
|
| 216 |
+
with gr.Tab("β‘ Energy Access Interpreter π"):
|
| 217 |
+
gr.Markdown("### Real data downloaded directly from Our World in Data")
|
| 218 |
+
gr.Markdown("π **Strongest result in this portfolio: 88% win rate, 81% General Win Rate**")
|
| 219 |
+
with gr.Row():
|
| 220 |
+
with gr.Column():
|
| 221 |
+
energy_example = gr.Dropdown(choices=list(ENERGY_EXAMPLES.keys()), value=list(ENERGY_EXAMPLES.keys())[0], label="Select a real finding")
|
| 222 |
+
energy_custom = gr.Textbox(label="Or paste your own stats (demo mode)", lines=2)
|
| 223 |
+
energy_btn = gr.Button("β‘ Interpret", variant="primary")
|
| 224 |
+
with gr.Column():
|
| 225 |
+
energy_output = gr.Markdown()
|
| 226 |
+
energy_btn.click(interpret_energy_stats, inputs=[energy_example, energy_custom], outputs=energy_output)
|
| 227 |
+
|
| 228 |
gr.Markdown("""
|
| 229 |
---
|
| 230 |
### Models β Open Source
|
| 231 |
| Model | Category | Win Rate | Quality | Note |
|
| 232 |
|-------|----------|----------|---------|------|
|
| 233 |
+
| HIV Funding Analysis | Science | 71% (60% general) | Grade C | Domain issue disclosed |
|
| 234 |
+
| AMR Classifier v2 | Science | 58% (71% general) | Grade B | 34/34 verified |
|
| 235 |
+
| Loan Classifier v2 | Personal Finance | 40% (45% general) | Grade B | 20/20 verified, honest disclosure |
|
| 236 |
+
| **Energy Access Interpreter** | **Data Visualization** | **88% (81% general)** | **Grade B** | **Strongest result, real downloaded data** |
|
| 237 |
|
| 238 |
+
π€ [HIV](https://huggingface.co/mabera/africa-hiv-funding-analysis-model) |
|
| 239 |
+
π€ [AMR](https://huggingface.co/mabera/nigeria-amr-classifier-v2) |
|
| 240 |
+
π€ [Loan](https://huggingface.co/mabera/nigeria-loan-classifier-v2) |
|
| 241 |
+
π€ [Energy](https://huggingface.co/mabera/nigeria-energy-access-interpreter)
|
|
|
|
|
|
|
| 242 |
|
| 243 |
### Other Portfolio Demos
|
| 244 |
+
- Part 1: [nigeria-health-ai-demo](https://huggingface.co/spaces/mabera/nigeria-health-ai-demo)
|
| 245 |
- Part 2 Agriculture: [nigeria-agriculture-ai](https://huggingface.co/spaces/mabera/nigeria-agriculture-ai)
|
| 246 |
""")
|
| 247 |
|