File size: 2,976 Bytes
15e1622
276e698
15e1622
 
 
 
 
 
 
276e698
15e1622
 
 
 
 
1b7a975
15e1622
276e698
15e1622
276e698
15e1622
 
 
a3efc2b
 
15e1622
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97bbd3a
15e1622
 
97bbd3a
 
15e1622
 
 
97bbd3a
15e1622
97bbd3a
 
15e1622
97bbd3a
15e1622
 
97bbd3a
15e1622
97bbd3a
 
 
 
 
 
15e1622
 
97bbd3a
15e1622
97bbd3a
15e1622
 
 
 
 
 
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# app.py

import pandas as pd
import numpy as np
import streamlit as st
from xgboost import XGBRegressor
from sklearn.model_selection import train_test_split
from sklearn.metrics import r2_score
from io import BytesIO

# -------------------------
# ๐Ÿ”ƒ Load Dataset
# -------------------------
@st.cache_data
def load_data():
    df = pd.read_csv("Nigeria Economy Dataset_1990-2022.csv")
    return df

df = load_data()

# -------------------------
# โš™๏ธ Model Training
# -------------------------
features = ['Agriculture to GDP', 'Industry to GDP', 'Services to GDP', 'Inflation rate', 'Government debt']
target = 'Real GDP'

X = df[features]
y = df[target]

X_train, X_test, y_train, y_test = train_test_split(X, y, test_size=0.2, random_state=42)

model = XGBRegressor()
model.fit(X_train, y_train)
y_pred = model.predict(X_test)
score = r2_score(y_test, y_pred)

# -------------------------
# ๐ŸŽจ Streamlit UI
# -------------------------
st.set_page_config(page_title="Nigeria GDP Predictor", layout="wide")
st.title("๐Ÿ‡ณ๐Ÿ‡ฌ Nigeria GDP Forecasting App")
st.markdown("Use the controls to simulate policy changes and forecast **GDP** using AI.")

st.sidebar.header("๐Ÿ“Š Economic Inputs")
agri = st.sidebar.slider("Agriculture Contribution (%)", 0.0, 100.0, 25.0)
indus = st.sidebar.slider("Industry Contribution (%)", 0.0, 100.0, 30.0)
service = st.sidebar.slider("Services Contribution (%)", 0.0, 100.0, 40.0)
inflation = st.sidebar.slider("Inflation Rate (%)", 0.0, 100.0, 15.0)
debt = st.sidebar.slider("Govt Debt (Billion USD)", 0.0, 200.0, 60.0)

# -------------------------
# ๐Ÿงฎ Make Prediction
# -------------------------
input_data = pd.DataFrame([[agri, indus, service, inflation, debt]], columns=features)
gdp_prediction = model.predict(input_data)[0]

st.subheader("๐Ÿง  Predicted GDP Result")
st.metric(label="Predicted GDP", value=f"${gdp_prediction:,.2f} Billion USD")
st.caption(f"Model Accuracy (Rยฒ): {score:.4f}")

# -------------------------
# ๐Ÿ“ˆ GDP Trend Line Chart
# -------------------------
st.subheader("๐Ÿ“‰ Historical GDP Trend (Nigeria)")
gdp_df = df[['Year', 'Real GDP']].dropna()
gdp_df = gdp_df.sort_values("Year")
st.line_chart(gdp_df.set_index("Year"))

# -------------------------
# ๐Ÿ“ฅ Download Prediction
# -------------------------
def convert_df_to_csv(data):
    return data.to_csv(index=False).encode('utf-8')

st.subheader("โฌ‡๏ธ Export Prediction")
output_df = input_data.copy()
output_df['Predicted_GDP'] = gdp_prediction
csv_data = convert_df_to_csv(output_df)

st.download_button(
    label="Download Prediction as CSV",
    data=csv_data,
    file_name="gdp_prediction.csv",
    mime='text/csv'
)

# -------------------------
# ๐ŸŒ Gradio Integration (optional)
# -------------------------
st.subheader("๐Ÿค– Gradio AI Simulator (Embed)")
st.markdown(
    """
    <iframe src="https://your-huggingface-username.hf.space" width="100%" height="600" frameborder="0"></iframe>
    """,
    unsafe_allow_html=True
)