File size: 1,770 Bytes
5da9a75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import pandas as pd
import joblib
import os

# Make Streamlit write configs locally instead of root
os.environ["STREAMLIT_HOME"] = os.path.join(os.getcwd(), ".streamlit")

# --- Load the model ---
script_dir = os.path.dirname(__file__)
model_path = os.path.join(script_dir, "salary_model.pkl")  # your saved model

st.title("💼 AI Salary Prediction App")
st.write("This tool predicts a developer's estimated salary based on their background and experience.")

try:
    model_pipeline = joblib.load(model_path)
    st.success("✅ Model loaded successfully!")
except Exception as e:
    st.error(f"❌ Error loading the model: {e}")
    st.stop()

# --- User input section ---
st.sidebar.header("Input your details")

age = st.sidebar.slider("Age", 18, 65, 30)
years_code_pro = st.sidebar.slider("Years of professional coding experience", 0, 40, 5)
country = st.sidebar.selectbox("Country", ["Denmark", "Germany", "Croatia", "Portugal", "Italy", "Netherlands"])
education = st.sidebar.selectbox("Education level", [
    "Bachelor’s degree",
    "Master’s degree (M.A., M.S., M.Eng., MBA, etc.)",
    "Doctoral degree",
    "Less than Bachelor’s"
])
remote = st.sidebar.selectbox("Work arrangement", ["Remote", "Hybrid", "On-site"])

# --- Create a DataFrame for prediction ---
input_data = pd.DataFrame({
    "age_group": [age],
    "years_code_pro": [years_code_pro],
    "country": [country],
    "ed_level": [education],
    "remote_work": [remote]
})

# --- Predict salary ---
if st.button("Predict Salary"):
    try:
        predicted_salary = model_pipeline.predict(input_data)[0]
        st.subheader(f"💰 Predicted Salary: €{predicted_salary:,.0f}")
    except Exception as e:
        st.error(f"Error making prediction: {e}")