jr98rh commited on
Commit
07f2c5b
·
verified ·
1 Parent(s): e855b76

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +72 -40
app.py CHANGED
@@ -1,43 +1,75 @@
1
- import requests
2
- import joblib
3
- import os
4
  import pandas as pd
5
- import gradio as gr
6
  import pickle
7
 
8
- countries = [
9
- "United States of America", "Other", "Germany",
10
- "United Kingdom of Great Britain and Northern Ireland",
11
- "India", "Canada", "France", "Brazil", "Spain",
12
- "Netherlands", "Australia", "Italy", "Poland",
13
- "Sweden", "Russian Federation", "Switzerland", "Turkey",
14
- "Israel", "Austria", "Norway", "Portugal", "Denmark",
15
- "Belgium", "Finland", "Mexico", "New Zealand", "Greece",
16
- "South Africa", "Pakistan", "Czech Republic",
17
- "Iran, Islamic Republic of"
18
- ]
19
-
20
-
21
-
22
- # Load the trained model
23
- model = pickle.load(open("salary_model.pkl", 'rb'))
24
-
25
- # Define prediction function
26
- def predict_salary(country, education, experience, remote):
27
- input_data = pd.DataFrame([[country, education, experience, remote]],
28
- columns=['Country', 'EdLevel', 'YearsCodePro', 'RemoteWork'])
29
- prediction = model.predict(input_data)[0]
30
- return f"Estimated Salary: ${round(prediction, 2)}"
31
-
32
- # Define Gradio app
33
- inputs = [
34
- gr.Dropdown(countries, label="Country"),
35
- gr.Dropdown(["Bachelor’s degree", "Master’s degree", "Post grad", "Less than a Bachelors"], label="Education Level"),
36
- gr.Number(label="Years of Professional Experience"),
37
- gr.Dropdown(["Fully remote", "Hybrid", "In-office"], label="Remote Work Status")
38
- ]
39
-
40
- output = gr.Textbox(label="Predicted Salary")
41
-
42
- app = gr.Interface(fn=predict_salary, inputs=inputs, outputs=output, title="Salary Prediction App")
43
- app.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
 
3
  import pandas as pd
4
+ import joblib
5
  import pickle
6
 
7
+ model = pickle.load(open("PycaretGBR.pkl", 'rb'))
8
+ # model = joblib.load("lr.joblib")
9
+ st.title('Developer Salary Prediction 2024')
10
+ st.write("""### We need some information to predict the salary""")
11
+
12
+ countries = (
13
+ "Australia",
14
+ "Austria",
15
+ "Belgium",
16
+ "Brazil",
17
+ "Canada",
18
+ "Czech Republic",
19
+ "Denmark",
20
+ "France",
21
+ "Germany",
22
+ "India",
23
+ "Israel",
24
+ "Italy",
25
+ "Netherlands",
26
+ "Norway",
27
+ "Poland",
28
+ "Russian Federation",
29
+ "Spain",
30
+ "Sweden",
31
+ "Switzerland",
32
+ "Ukraine"
33
+ "United Kingdom of Great Britain and Northern Ireland",
34
+ "United States of America"
35
+ )
36
+
37
+ education = (
38
+ "Less than a Bachelors",
39
+ "Bachelor’s degree",
40
+ "Master’s degree",
41
+ "Post grad"
42
+ )
43
+
44
+ employment = (
45
+ "Employed, full-time",
46
+ "Independent contractor, freelancer, or self-employed",
47
+ "Student, part-time",
48
+ "Retired",
49
+ "Not employed, but looking for work",
50
+ "Employed, part-time",
51
+ "Student, full-time"
52
+ )
53
+
54
+ country = st.selectbox("Country", countries)
55
+ education = st.selectbox("Education Level", education)
56
+ expericence = st.slider("Years of Experience", 0, 50, 3)
57
+ employment = st.selectbox("Employment Type", employment)
58
+
59
+ columns = ['Country', 'EdLevel', 'YearsCodePro', 'Employment']
60
+
61
+ ok = st.button("Calculate Salary")
62
+ if ok:
63
+ X_new_df = pd.DataFrame([[country,education,expericence,employment]],
64
+ columns = ['Country', 'EdLevel', 'YearsCodePro', 'Employment'])
65
+ print("##########")
66
+ print("##########")
67
+ print("##########")
68
+ print(model)
69
+ print("##########")
70
+ print("##########")
71
+ print("##########")
72
+ salary = model.predict(X_new_df)
73
+
74
+ st.subheader(f"The estimated salary is {salary[0]:.2f} $")\
75
+