Janesh1 commited on
Commit
2a1f8a3
·
verified ·
1 Parent(s): 6ad8664

Upload app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import mlflow
3
+ import mlflow.sklearn
4
+ import pandas as pd
5
+ import numpy as np
6
+ from sklearn.preprocessing import LabelEncoder
7
+
8
+ # Load the trained model (assuming it's saved in MLflow)
9
+ logged_model = '/'
10
+
11
+ # Load model
12
+ model = mlflow.sklearn.load_model(logged_model)
13
+
14
+ # Define categorical features and their distinct values
15
+ categorical_features = ['employment_type', 'job_category', 'experience_level',
16
+ 'employee_residence', 'remote_ratio', 'company_location', 'company_size']
17
+
18
+ distinct_values = {
19
+ 'experience_level': ['Senior-level/Expert','Mid-level/Intermediate', 'Entry-level/Junior',
20
+ 'Executive-level/Director'], # Replace with actual distinct values
21
+ 'employment_type': ['Full-time', 'Contractor', 'Freelancer', 'Part-time'], # Replace with actual distinct values
22
+ 'employee_residence': ['ES', 'US', 'CA', 'DE', 'GB', 'NG', 'IN', 'HK', 'PT', 'NL', 'CH', 'CF', 'FR', 'AU',
23
+ 'FI', 'UA', 'IE', 'IL', 'GH', 'AT', 'CO', 'SG', 'SE', 'SI', 'MX', 'UZ', 'BR', 'TH',
24
+ 'HR', 'PL', 'KW', 'VN', 'CY', 'AR', 'AM', 'BA', 'KE', 'GR', 'MK', 'LV', 'RO', 'PK',
25
+ 'IT', 'MA', 'LT', 'BE', 'AS', 'IR', 'HU', 'SK', 'CN', 'CZ', 'CR', 'TR', 'CL', 'PR',
26
+ 'DK', 'BO', 'PH', 'DO', 'EG', 'ID', 'AE', 'MY', 'JP', 'EE', 'HN', 'TN', 'RU', 'DZ',
27
+ 'IQ', 'BG', 'JE', 'RS', 'NZ', 'MD', 'LU', 'MT'], # Replace with actual distinct values
28
+ 'remote_ratio': ['Full-Remote', 'On-Site', 'Half-Remote'], # Replace with actual distinct values
29
+ 'company_location': ['ES', 'US', 'CA', 'DE', 'GB', 'NG', 'IN', 'HK', 'NL', 'CH', 'CF', 'FR', 'FI', 'UA',
30
+ 'IE', 'IL', 'GH', 'CO', 'SG', 'AU', 'SE', 'SI', 'MX', 'BR', 'PT', 'RU', 'TH', 'HR',
31
+ 'VN', 'EE', 'AM', 'BA', 'KE', 'GR', 'MK', 'LV', 'RO', 'PK', 'IT', 'MA', 'PL', 'AL',
32
+ 'AR', 'LT', 'AS', 'CR', 'IR', 'BS', 'HU', 'AT', 'SK', 'CZ', 'TR', 'PR', 'DK', 'BO',
33
+ 'PH', 'BE', 'ID', 'EG', 'AE', 'LU', 'MY', 'HN', 'JP', 'DZ', 'IQ', 'CN', 'NZ', 'CL',
34
+ 'MD', 'MT'], # Replace with actual distinct values
35
+ 'company_size': ['LARGE', 'SMALL', 'MEDIUM'], # Replace with actual distinct values
36
+ 'job_category': ['Other', 'Machine Learning', 'Data Science', 'Data Engineering',
37
+ 'Data Architecture', 'Management'] # Replace with actual distinct values
38
+ }
39
+
40
+ # Load the label encoders for each categorical feature
41
+ encoders = {feature: LabelEncoder().fit(values) for feature, values in distinct_values.items()}
42
+
43
+ # Streamlit app
44
+ st.title("Salary Prediction")
45
+
46
+ # User input
47
+ user_input = {}
48
+ for feature in categorical_features:
49
+ # user_input[feature] = st.selectbox(f"Select {feature}", distinct_values[feature])
50
+ user_input[feature] = st.selectbox(f"Select {feature}",distinct_values[feature])
51
+
52
+ # Encode the user input
53
+ encoded_input = [encoders[feature].transform([user_input[feature]])[0] for feature in categorical_features]
54
+
55
+ # Prediction
56
+ if st.button("Predict Salary Range"):
57
+ encoded_input = np.array(encoded_input).reshape(1, -1)
58
+ prediction = model.predict(encoded_input)
59
+
60
+ # Decoding the prediction (if the output is encoded)
61
+ salary_labels = ['low', 'low-mid', 'mid', 'mid-high', 'high', 'very-high', 'Top']
62
+ # st.write(f"Predicted Salary Range: {salary_labels[prediction[0]]}")
63
+ st.write(f"Predicted Salary Range: {prediction}")
64
+