Frederick001's picture
Update app.py
d1c397b verified
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()