Spaces:
Sleeping
Sleeping
File size: 3,392 Bytes
6ad8664 |
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 |
import streamlit as st
import mlflow
import mlflow.sklearn
import pandas as pd
import numpy as np
from sklearn.preprocessing import LabelEncoder
# Load the trained model (assuming it's saved in MLflow)
logged_model = 'E:/IIT JODHPUR/Trimester 3/MLops/Assign_2/mlruns/0/9620c00ca64348909cae21cafb606321/artifacts/Gradient Boosting'
# Load model
model = mlflow.sklearn.load_model(logged_model)
# Define categorical features and their distinct values
categorical_features = ['employment_type', 'job_category', 'experience_level',
'employee_residence', 'remote_ratio', 'company_location', 'company_size']
distinct_values = {
'experience_level': ['Senior-level/Expert','Mid-level/Intermediate', 'Entry-level/Junior',
'Executive-level/Director'], # Replace with actual distinct values
'employment_type': ['Full-time', 'Contractor', 'Freelancer', 'Part-time'], # Replace with actual distinct values
'employee_residence': ['ES', 'US', 'CA', 'DE', 'GB', 'NG', 'IN', 'HK', 'PT', 'NL', 'CH', 'CF', 'FR', 'AU',
'FI', 'UA', 'IE', 'IL', 'GH', 'AT', 'CO', 'SG', 'SE', 'SI', 'MX', 'UZ', 'BR', 'TH',
'HR', 'PL', 'KW', 'VN', 'CY', 'AR', 'AM', 'BA', 'KE', 'GR', 'MK', 'LV', 'RO', 'PK',
'IT', 'MA', 'LT', 'BE', 'AS', 'IR', 'HU', 'SK', 'CN', 'CZ', 'CR', 'TR', 'CL', 'PR',
'DK', 'BO', 'PH', 'DO', 'EG', 'ID', 'AE', 'MY', 'JP', 'EE', 'HN', 'TN', 'RU', 'DZ',
'IQ', 'BG', 'JE', 'RS', 'NZ', 'MD', 'LU', 'MT'], # Replace with actual distinct values
'remote_ratio': ['Full-Remote', 'On-Site', 'Half-Remote'], # Replace with actual distinct values
'company_location': ['ES', 'US', 'CA', 'DE', 'GB', 'NG', 'IN', 'HK', 'NL', 'CH', 'CF', 'FR', 'FI', 'UA',
'IE', 'IL', 'GH', 'CO', 'SG', 'AU', 'SE', 'SI', 'MX', 'BR', 'PT', 'RU', 'TH', 'HR',
'VN', 'EE', 'AM', 'BA', 'KE', 'GR', 'MK', 'LV', 'RO', 'PK', 'IT', 'MA', 'PL', 'AL',
'AR', 'LT', 'AS', 'CR', 'IR', 'BS', 'HU', 'AT', 'SK', 'CZ', 'TR', 'PR', 'DK', 'BO',
'PH', 'BE', 'ID', 'EG', 'AE', 'LU', 'MY', 'HN', 'JP', 'DZ', 'IQ', 'CN', 'NZ', 'CL',
'MD', 'MT'], # Replace with actual distinct values
'company_size': ['LARGE', 'SMALL', 'MEDIUM'], # Replace with actual distinct values
'job_category': ['Other', 'Machine Learning', 'Data Science', 'Data Engineering',
'Data Architecture', 'Management'] # Replace with actual distinct values
}
# Load the label encoders for each categorical feature
encoders = {feature: LabelEncoder().fit(values) for feature, values in distinct_values.items()}
# Streamlit app
st.title("Salary Prediction")
# User input
user_input = {}
for feature in categorical_features:
# user_input[feature] = st.selectbox(f"Select {feature}", distinct_values[feature])
user_input[feature] = st.selectbox(f"Select {feature}",distinct_values[feature])
# Encode the user input
encoded_input = [encoders[feature].transform([user_input[feature]])[0] for feature in categorical_features]
# Prediction
if st.button("Predict Salary Range"):
encoded_input = np.array(encoded_input).reshape(1, -1)
prediction = model.predict(encoded_input)
# Decoding the prediction (if the output is encoded)
salary_labels = ['low', 'low-mid', 'mid', 'mid-high', 'high', 'very-high', 'Top']
# st.write(f"Predicted Salary Range: {salary_labels[prediction[0]]}")
st.write(f"Predicted Salary Range: {prediction}")
|