Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -21,32 +21,6 @@ class FastAIWrapper(BaseEstimator, RegressorMixin):
|
|
| 21 |
df = pd.read_csv('City_Employee_Payroll__Current__20240915.csv', low_memory=False)
|
| 22 |
ensemble = joblib.load('ensemble_model.joblib')
|
| 23 |
|
| 24 |
-
def predict_total_pay(gender, job_title, ethnicity):
|
| 25 |
-
# Create a sample input DataFrame
|
| 26 |
-
sample = pd.DataFrame({
|
| 27 |
-
'GENDER': [gender],
|
| 28 |
-
'JOB_TITLE': [job_title],
|
| 29 |
-
'ETHNICITY': [ethnicity],
|
| 30 |
-
})
|
| 31 |
-
|
| 32 |
-
# Fill in other required features (you may need to adjust this based on your model's requirements)
|
| 33 |
-
sample['EMPLOYMENT_TYPE'] = df['EMPLOYMENT_TYPE'].mode().iloc[0]
|
| 34 |
-
sample['JOB_STATUS'] = df['JOB_STATUS'].mode().iloc[0]
|
| 35 |
-
sample['MOU'] = df['MOU'].mode().iloc[0]
|
| 36 |
-
sample['DEPARTMENT_NO'] = df['DEPARTMENT_NO'].mode().iloc[0]
|
| 37 |
-
sample['PAY_YEAR'] = df['PAY_YEAR'].max()
|
| 38 |
-
sample['REGULAR_PAY'] = df['REGULAR_PAY'].mean()
|
| 39 |
-
sample['OVERTIME_PAY'] = df['OVERTIME_PAY'].mean()
|
| 40 |
-
sample['ALL_OTHER_PAY'] = df['ALL_OTHER_PAY'].mean()
|
| 41 |
-
|
| 42 |
-
# Calculate derived features
|
| 43 |
-
sample['PAY_RATIO'] = sample['REGULAR_PAY'] / (sample['OVERTIME_PAY'] + sample['ALL_OTHER_PAY'] + 1)
|
| 44 |
-
sample['TOTAL_NON_REGULAR_PAY'] = sample['OVERTIME_PAY'] + sample['ALL_OTHER_PAY']
|
| 45 |
-
|
| 46 |
-
# Make prediction
|
| 47 |
-
prediction = ensemble.predict(sample)[0]
|
| 48 |
-
return prediction
|
| 49 |
-
|
| 50 |
def predict_total_pay(gender, job_title, ethnicity):
|
| 51 |
# Function to predict total pay based on input parameters
|
| 52 |
# Parameters:
|
|
@@ -120,6 +94,10 @@ def predict_total_pay(gender, job_title, ethnicity):
|
|
| 120 |
# Return the predicted total pay
|
| 121 |
return prediction
|
| 122 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
# Prepare dropdown options
|
| 124 |
genders = df['GENDER'].dropna().unique().tolist()
|
| 125 |
ethnicities = df['ETHNICITY'].dropna().unique().tolist()
|
|
@@ -127,7 +105,7 @@ job_titles = sorted(df['JOB_TITLE'].dropna().unique().tolist())
|
|
| 127 |
|
| 128 |
# Create Gradio interface
|
| 129 |
iface = gr.Interface(
|
| 130 |
-
fn=
|
| 131 |
inputs=[
|
| 132 |
gr.Dropdown(choices=genders, label="Gender"),
|
| 133 |
gr.Dropdown(choices=ethnicities, label="Ethnicity"),
|
|
@@ -138,4 +116,5 @@ iface = gr.Interface(
|
|
| 138 |
description="Predict the total pay for LA City employees based on gender, ethnicity, and job title."
|
| 139 |
)
|
| 140 |
|
|
|
|
| 141 |
iface.launch()
|
|
|
|
| 21 |
df = pd.read_csv('City_Employee_Payroll__Current__20240915.csv', low_memory=False)
|
| 22 |
ensemble = joblib.load('ensemble_model.joblib')
|
| 23 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 24 |
def predict_total_pay(gender, job_title, ethnicity):
|
| 25 |
# Function to predict total pay based on input parameters
|
| 26 |
# Parameters:
|
|
|
|
| 94 |
# Return the predicted total pay
|
| 95 |
return prediction
|
| 96 |
|
| 97 |
+
def gradio_predict(gender, ethnicity, job_title):
|
| 98 |
+
predicted_pay = predict_total_pay(gender, job_title, ethnicity)
|
| 99 |
+
return f"${predicted_pay:.2f}"
|
| 100 |
+
|
| 101 |
# Prepare dropdown options
|
| 102 |
genders = df['GENDER'].dropna().unique().tolist()
|
| 103 |
ethnicities = df['ETHNICITY'].dropna().unique().tolist()
|
|
|
|
| 105 |
|
| 106 |
# Create Gradio interface
|
| 107 |
iface = gr.Interface(
|
| 108 |
+
fn=gradio_predict,
|
| 109 |
inputs=[
|
| 110 |
gr.Dropdown(choices=genders, label="Gender"),
|
| 111 |
gr.Dropdown(choices=ethnicities, label="Ethnicity"),
|
|
|
|
| 116 |
description="Predict the total pay for LA City employees based on gender, ethnicity, and job title."
|
| 117 |
)
|
| 118 |
|
| 119 |
+
# Launch the interface
|
| 120 |
iface.launch()
|