File size: 1,665 Bytes
ecb454b
 
 
 
 
 
 
d1c397b
ecb454b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import pandas as pd
import numpy as np
from xgboost import XGBRegressor
import gradio as gr

# πŸ”½ Load dataset

df = pd.read_csv("Nigeria Economy Dataset_1990-2022.csv")

# 🎯 Define input features and target variable

features = ['Agriculture to GDP', 'Industry to GDP', 'Services to GDP', 'Inflation rate', 'Government debt']
target = 'Real GDP' # Assuming 'Real GDP' is the target based on previous cells

# 🧠 Train model (consider pre-saving the model as a .pkl for large datasets)
X = df[features]
y = df[target]
model = XGBRegressor()
model.fit(X, y)

# πŸ” Prediction function for Gradio
def simulate_gdp(agri, indus, service, inflation, debt):
    input_df = pd.DataFrame([[agri, indus, service, inflation, debt]], columns=features)
    prediction = model.predict(input_df)[0]
    return f"πŸ’° Estimated GDP: ${prediction:,.2f} Billion USD"

# 🎨 Gradio interface
iface = gr.Interface(
    fn=simulate_gdp,
    inputs=[
        gr.Slider(0, 100, value=20, label="Agriculture Contribution (%)"),
        gr.Slider(0, 100, value=25, label="Industry Contribution (%)"),
        gr.Slider(0, 100, value=50, label="Services Contribution (%)"),
        gr.Slider(0, 50, value=10, label="Inflation Rate (%)"),
        gr.Slider(0, 200, value=50, label="Government Debt (Billion USD)")
    ],
    outputs="text",
    title="πŸ‡³πŸ‡¬ Nigeria GDP Forecasting & Policy Simulator",
    description="""
This tool uses AI to predict Nigeria's GDP based on key economic inputs.
Adjust the sliders to simulate policy scenarios and their likely economic outcomes.
Powered by XGBoost and real historical data (1990–2022).
"""
)

# πŸš€ Launch app
iface.launch()