developer_test / app.py
Anders-sonderby's picture
Upload app.py
5da9a75 verified
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}")