Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import pandas as pd
|
2 |
+
import numpy as np
|
3 |
+
import gradio as gr
|
4 |
+
import joblib
|
5 |
+
|
6 |
+
# Load the saved model
|
7 |
+
ensemble = joblib.load('ensemble_model.joblib')
|
8 |
+
|
9 |
+
# Load your data
|
10 |
+
df = pd.read_csv('City_Employee_Payroll__Current__20240915.csv', low_memory=False)
|
11 |
+
|
12 |
+
def predict_total_pay(gender, job_title, ethnicity):
|
13 |
+
# Your existing prediction function
|
14 |
+
# ...
|
15 |
+
|
16 |
+
def gradio_predict(gender, ethnicity, job_title):
|
17 |
+
predicted_pay = predict_total_pay(gender, job_title, ethnicity)
|
18 |
+
return f"${predicted_pay:.2f}"
|
19 |
+
|
20 |
+
# Prepare dropdown options
|
21 |
+
genders = df['GENDER'].dropna().unique().tolist()
|
22 |
+
ethnicities = df['ETHNICITY'].dropna().unique().tolist()
|
23 |
+
job_titles = sorted(df['JOB_TITLE'].dropna().unique().tolist())
|
24 |
+
|
25 |
+
# Create Gradio interface
|
26 |
+
iface = gr.Interface(
|
27 |
+
fn=gradio_predict,
|
28 |
+
inputs=[
|
29 |
+
gr.Dropdown(choices=genders, label="Gender"),
|
30 |
+
gr.Dropdown(choices=ethnicities, label="Ethnicity"),
|
31 |
+
gr.Dropdown(choices=job_titles, label="Job Title")
|
32 |
+
],
|
33 |
+
outputs=gr.Textbox(label="Predicted Total Pay"),
|
34 |
+
title="LA City Employee Pay Predictor",
|
35 |
+
description="Predict the total pay for LA City employees based on gender, ethnicity, and job title."
|
36 |
+
)
|
37 |
+
|
38 |
+
iface.launch()
|