Spaces:
Runtime error
Runtime error
Upload 4 files
Browse files- .gitattributes +1 -0
- app.py +127 -0
- requirements.txt +4 -0
- rf.pkl +3 -0
- rtv.csv +3 -0
.gitattributes
CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
36 |
+
rtv.csv filter=lfs diff=lfs merge=lfs -text
|
app.py
ADDED
@@ -0,0 +1,127 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# import libraries
|
2 |
+
import streamlit as st
|
3 |
+
import pandas as pd
|
4 |
+
import numpy as np
|
5 |
+
import pickle
|
6 |
+
from sklearn.ensemble import RandomForestRegressor
|
7 |
+
import matplotlib.pyplot as plt
|
8 |
+
|
9 |
+
|
10 |
+
df = pd.read_csv("rtv.csv", low_memory=False)
|
11 |
+
|
12 |
+
# load model from pickle file
|
13 |
+
with open("rf.pkl", "rb") as f:
|
14 |
+
rf = pickle.load(f)
|
15 |
+
|
16 |
+
st.set_page_config(
|
17 |
+
page_title = 'Real-Time Data Science Dashboard',
|
18 |
+
page_icon = '✅',
|
19 |
+
layout = 'wide'
|
20 |
+
)
|
21 |
+
|
22 |
+
# create sidebar title
|
23 |
+
st.title("Raising the :green[Village] :desert:")
|
24 |
+
st.image("https://ngosjob.b-cdn.net/wp-content/uploads/2023/03/Raising-The-Village.png")
|
25 |
+
|
26 |
+
|
27 |
+
|
28 |
+
# creating a single-element container.
|
29 |
+
placeholder = st.empty()
|
30 |
+
|
31 |
+
duration = df['duration'].mean()
|
32 |
+
|
33 |
+
mean = pd.to_numeric(df['HH Income (UGX)'], errors='coerce').mean()
|
34 |
+
|
35 |
+
maxi = pd.to_numeric(df['HH Income (UGX)'], errors='coerce').max()
|
36 |
+
|
37 |
+
with placeholder.container():
|
38 |
+
# create three columns
|
39 |
+
kpi1, kpi2, kpi3 = st.columns(3)
|
40 |
+
|
41 |
+
# fill in those three columns with respective metrics or KPIs
|
42 |
+
kpi1.metric(label="Average Income ⏳", value=round(mean))
|
43 |
+
kpi2.metric(label="Mean Time(minutes) 💍", value= int(duration))
|
44 |
+
kpi3.metric(label="Max income$", value= f"$ {round(maxi,2)} ")
|
45 |
+
|
46 |
+
|
47 |
+
# create title
|
48 |
+
st.title("Income Prediction")
|
49 |
+
|
50 |
+
# create input fields for each feature
|
51 |
+
inputs = []
|
52 |
+
X_columns = ['Season 2 Agriculture Value (Ugx)',
|
53 |
+
'Casual Labour (Ugx)',
|
54 |
+
'Season 1 Agriculture Value (Ugx)',
|
55 |
+
'Perenial Crops Income (Ugx)',
|
56 |
+
'Personal Business & Self Employment (Ugx)',
|
57 |
+
'Agriculture Income (UGX) ',
|
58 |
+
'Perennial Agriculture Value (Ugx)',
|
59 |
+
'HH Income + Consumption + Residues (UGX)']
|
60 |
+
for col in X_columns:
|
61 |
+
value = st.number_input(f"Enter value for {col}", value=0.0)
|
62 |
+
inputs.append(value)
|
63 |
+
|
64 |
+
# create button for prediction
|
65 |
+
predict = st.button("Predict Income")
|
66 |
+
|
67 |
+
if predict:
|
68 |
+
# convert inputs to numpy array and reshape to match model input shape
|
69 |
+
inputs = np.array(inputs).reshape(1, -1)
|
70 |
+
# make prediction using loaded model
|
71 |
+
y_pred = rf.predict(inputs)
|
72 |
+
# display prediction result
|
73 |
+
st.write(f"The predicted income value is {y_pred[0]:.2f}")
|
74 |
+
|
75 |
+
st.markdown("============================================================================================================================")
|
76 |
+
|
77 |
+
# make prediction and display result if button is clicked and data is uploaded
|
78 |
+
# display file upload option
|
79 |
+
st.title("Get predictions of the whole dataset")
|
80 |
+
st.write("Upload your csv or excel file here:")
|
81 |
+
st.write("The dashboard supports only csv files at the moment")
|
82 |
+
uploaded_file = st.file_uploader("Choose a file", type=["csv", "xlsx"])
|
83 |
+
|
84 |
+
def preproc(df):
|
85 |
+
df = df[['Season 2 Agriculture Value (Ugx)',
|
86 |
+
'Casual Labour (Ugx)',
|
87 |
+
'Season 1 Agriculture Value (Ugx)',
|
88 |
+
'Perenial Crops Income (Ugx)',
|
89 |
+
'Personal Business & Self Employment (Ugx)',
|
90 |
+
'Agriculture Income (UGX) ',
|
91 |
+
'Perennial Agriculture Value (Ugx)',
|
92 |
+
'HH Income + Consumption + Residues (UGX)']]
|
93 |
+
df.fillna(df.mean(), inplace=True)
|
94 |
+
return df
|
95 |
+
|
96 |
+
# load and display data if uploaded
|
97 |
+
if uploaded_file is not None:
|
98 |
+
if uploaded_file.type == "text/csv":
|
99 |
+
df = pd.read_csv(uploaded_file)
|
100 |
+
elif uploaded_file.type == "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet":
|
101 |
+
df = pd.read_excel(uploaded_file)
|
102 |
+
X_new = preproc(df)
|
103 |
+
else:
|
104 |
+
st.write("No file uploaded yet.")
|
105 |
+
|
106 |
+
# create button for prediction
|
107 |
+
predict = st.button("Predict")
|
108 |
+
|
109 |
+
# make prediction and display result if button is clicked and data is uploaded
|
110 |
+
if uploaded_file is not None and predict:
|
111 |
+
# make prediction using loaded model
|
112 |
+
y_pred = rf.predict(X_new)
|
113 |
+
# display prediction result as dataframe
|
114 |
+
df["prediction"] = y_pred.round(2)
|
115 |
+
st.dataframe(df[["Surveyor_Name", "prediction"]])
|
116 |
+
|
117 |
+
job_filter = st.selectbox("Select the Quartile", pd.unique(df['Quartile']))
|
118 |
+
|
119 |
+
|
120 |
+
|
121 |
+
# dataframe filter
|
122 |
+
|
123 |
+
df1 = df[df['Quartile']==job_filter]
|
124 |
+
|
125 |
+
|
126 |
+
|
127 |
+
st.dataframe(df1)
|
requirements.txt
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
streamlit
|
2 |
+
pandas
|
3 |
+
numpy
|
4 |
+
pickle
|
rf.pkl
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:32c8e318af92fe4e3af97ff8b22dfa69a031cfb8303f1ebf7999fe6074eca640
|
3 |
+
size 36759795
|
rtv.csv
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
version https://git-lfs.github.com/spec/v1
|
2 |
+
oid sha256:78f9eae8cadea44db9b35480b0d879bc37a5b3791d854b19119a20eec0c81f5c
|
3 |
+
size 11814212
|