File size: 3,834 Bytes
73db760
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
# import libraries
import streamlit as st
import pandas as pd
import numpy as np
import pickle


df = pd.read_csv("rtv.csv", low_memory=False)

# load model from pickle file
with open("rf.pkl", "rb") as f:
    rf = pickle.load(f)
    
st.set_page_config(
    page_title = 'Real-Time Data Science Dashboard',
    page_icon = '✅',
    layout = 'wide'
)

# create sidebar title
st.title("Raising the :green[Village] :desert:")
st.image("https://ngosjob.b-cdn.net/wp-content/uploads/2023/03/Raising-The-Village.png")



# creating a single-element container.
placeholder = st.empty()

duration = df['duration'].mean()

mean = pd.to_numeric(df['HH Income (UGX)'], errors='coerce').mean()

maxi = pd.to_numeric(df['HH Income (UGX)'], errors='coerce').max()

with placeholder.container():
    # create three columns
    kpi1, kpi2, kpi3 = st.columns(3)

    # fill in those three columns with respective metrics or KPIs 
    kpi1.metric(label="Average Income ⏳", value=round(mean))
    kpi2.metric(label="Mean Time(minutes) 💍", value= int(duration))
    kpi3.metric(label="Max income$", value= f"$ {round(maxi,2)} ")
    
    
# create title
st.title("Income Prediction")

# create input fields for each feature
inputs = []
X_columns = ['Season 2 Agriculture Value (Ugx)',
 'Casual Labour (Ugx)',
 'Season 1 Agriculture Value (Ugx)',
 'Perenial Crops Income (Ugx)',
 'Personal Business & Self Employment (Ugx)',
 'Agriculture Income (UGX) ',
 'Perennial Agriculture Value (Ugx)',
 'HH Income + Consumption + Residues (UGX)']
for col in X_columns:
    value = st.number_input(f"Enter value for {col}", value=0.0)
    inputs.append(value)

# create button for prediction
predict = st.button("Predict Income")

if predict:
    # convert inputs to numpy array and reshape to match model input shape
    inputs = np.array(inputs).reshape(1, -1)
    # make prediction using loaded model
    y_pred = rf.predict(inputs)
    # display prediction result
    st.write(f"The predicted income value is {y_pred[0]:.2f}")

st.markdown("============================================================================================================================")

# make prediction and display result if button is clicked and data is uploaded
# display file upload option
st.title("Get predictions of the whole dataset")
st.write("Upload your csv or excel file here:")
st.write("The dashboard supports only csv files at the moment")
uploaded_file = st.file_uploader("Choose a file", type=["csv", "xlsx"])

def preproc(df):
    df = df[['Season 2 Agriculture Value (Ugx)',
         'Casual Labour (Ugx)',
         'Season 1 Agriculture Value (Ugx)',
         'Perenial Crops Income (Ugx)',
         'Personal Business & Self Employment (Ugx)',
         'Agriculture Income (UGX) ',
         'Perennial Agriculture Value (Ugx)',
         'HH Income + Consumption + Residues (UGX)']]
    df.fillna(df.mean(), inplace=True)
    return df

# load and display data if uploaded
if uploaded_file is not None:
    if uploaded_file.type == "text/csv":
        df = pd.read_csv(uploaded_file)
    elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
        df = pd.read_excel(uploaded_file)
    X_new = preproc(df)
else:
    st.write("No file uploaded yet.")

# create button for prediction
predict = st.button("Predict")

# make prediction and display result if button is clicked and data is uploaded
if uploaded_file is not None and predict:
    # make prediction using loaded model
    y_pred = rf.predict(X_new)
    # display prediction result as dataframe
    df["prediction"] = y_pred.round(2)
    st.dataframe(df[["Surveyor_Name", "prediction"]])

job_filter = st.selectbox("Select the Quartile", pd.unique(df['Quartile']))



# dataframe filter 

df1 = df[df['Quartile']==job_filter]



st.dataframe(df1)