RustX commited on
Commit
f943728
1 Parent(s): c85b155

Create predict_page.py

Browse files
Files changed (1) hide show
  1. predict_page.py +59 -0
predict_page.py ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import joblib
3
+ import numpy as np
4
+
5
+ def load_model():
6
+ with open('saved_steps.pkl', 'rb') as file:
7
+ data = joblib.load(file)
8
+ return data
9
+
10
+ data = load_model()
11
+
12
+ regressor = data["model"]
13
+ le_country = data["le_country"]
14
+ le_education = data["le_education"]
15
+
16
+ def show_predict_page():
17
+ st.title("Software Developer Salary Prediction")
18
+
19
+ st.write("""### We need some information to predict the salary""")
20
+
21
+ countries = (
22
+ "United States of America",
23
+ "Germany",
24
+ "United Kingdom of Great Britain and Northern Ireland",
25
+ "India",
26
+ "Canada",
27
+ "France",
28
+ "Brazil",
29
+ "Spain",
30
+ "Netherlands",
31
+ "Australia",
32
+ "Italy",
33
+ "Poland",
34
+ "Sweden",
35
+ "Russian Federation",
36
+ "Switzerland",
37
+ )
38
+
39
+ education = (
40
+ "Less than a Bachelors",
41
+ "Bachelor’s degree",
42
+ "Master’s degree",
43
+ "Post grad",
44
+ )
45
+
46
+ country = st.selectbox("Country", countries)
47
+ education = st.selectbox("Education Level", education)
48
+
49
+ experience = st.slider("Years of Experience", 0, 50, 3)
50
+
51
+ ok = st.button("Calculate Salary")
52
+ if ok:
53
+ X = np.array([[country, education, experience ]])
54
+ X[:, 0] = le_country.transform(X[:,0])
55
+ X[:, 1] = le_education.transform(X[:,1])
56
+ X = X.astype(float)
57
+
58
+ salary = regressor.predict(X)
59
+ st.subheader(f"The estimated salary is ${salary[0]:.2f}")