QuratUlAin-ai11's picture
Create app.py
eb0e1c4 verified
import joblib
import pandas as pd
import gradio as gr
import numpy as np
import sklearn
model = joblib.load("salary_prediction_model.pkl")
def predict_salary_category(work_year, experience_level, company_size, employment_type, employee_residence, company_location, job_title, country, remote_ratio):
# Create a DataFrame for the new input data
input_data = pd.DataFrame({
'work_year': [work_year],
'experience_level': [experience_level],
'company_size': [company_size],
'employment_type': [employment_type],
'employee_residence': [employee_residence],
'company_location': [company_location],
'job_title': [job_title],
'country': [country],
'remote_ratio': [remote_ratio]
})
# Make predictions using the loaded model
prediction = model.predict(input_data)
# Map the encoded prediction back to the salary label
salary_labels = ['Low', 'Medium-Low', 'High']
return salary_labels[prediction[0]]
# Define Gradio inputs and outputs
inputs = [
gr.Number(label="Work Year", value=2024),
gr.Dropdown(['EN', 'MI', 'SE', 'EX'], label="Experience Level", value='MI'), # Default value must be in the options
gr.Dropdown(['S', 'M', 'L'], label="Company Size", value='M'),
gr.Dropdown(['FT', 'PT', 'CT', 'FL'], label="Employment Type", value='FT'),
gr.Textbox(label="Employee Residence", value=''),
gr.Textbox(label="Company Location", value=''),
gr.Textbox(label="Job Title", value=''),
gr.Textbox(label="Country", value=''),
gr.Number(label="Remote Ratio", value=0)
]
output = gr.Textbox(label="Predicted Salary Category")
# Create the Gradio interface using the loaded model
interface = gr.Interface(
fn=predict_salary_category,
inputs=inputs,
outputs=output,
title="KNN Salary Category Predictor",
description="Enter details to predict the salary category (Low, Medium-Low, High) based on job and company information."
)
# Launch the Gradio interface
interface.launch(debug=True)