Spaces:
Sleeping
Sleeping
import pandas as pd | |
import numpy as np | |
import gradio as gr | |
import joblib | |
# Load the saved model | |
ensemble = joblib.load('ensemble_model.joblib') | |
# Load your data | |
df = pd.read_csv('City_Employee_Payroll__Current__20240915.csv', low_memory=False) | |
def predict_total_pay(gender, job_title, ethnicity): | |
# Your existing prediction function | |
# ... | |
def gradio_predict(gender, ethnicity, job_title): | |
predicted_pay = predict_total_pay(gender, job_title, ethnicity) | |
return f"${predicted_pay:.2f}" | |
# Prepare dropdown options | |
genders = df['GENDER'].dropna().unique().tolist() | |
ethnicities = df['ETHNICITY'].dropna().unique().tolist() | |
job_titles = sorted(df['JOB_TITLE'].dropna().unique().tolist()) | |
# Create Gradio interface | |
iface = gr.Interface( | |
fn=gradio_predict, | |
inputs=[ | |
gr.Dropdown(choices=genders, label="Gender"), | |
gr.Dropdown(choices=ethnicities, label="Ethnicity"), | |
gr.Dropdown(choices=job_titles, label="Job Title") | |
], | |
outputs=gr.Textbox(label="Predicted Total Pay"), | |
title="LA City Employee Pay Predictor", | |
description="Predict the total pay for LA City employees based on gender, ethnicity, and job title." | |
) | |
iface.launch() |