Atsadawut's picture
Update app.py
7821c16 verified
import gradio as gr
import joblib
import numpy as np
import pandas as pd
# Load the model and unique brand values
model = joblib.load('model.joblib')
unique_values = joblib.load('unique_values.joblib')
edu = unique_values['Education_Level']
occ = unique_values['Occupation']
loc = unique_values['Location']
emp = unique_values['Employment_Status']
hom = unique_values['Homeownership_Status']
typ = unique_values['Type_of_Housing']
gen = unique_values['Gender']
pri = unique_values['Primary_Mode_of_Transportation']
mar = unique_values['Marital_Status']
# Define the prediction function
def predict(edu, occ, loc, emp, hom, typ, gen, pri, age, num, wor,hou):
# Convert inputs to appropriate types
age = int(age)
num = int(num)
wor = float(wor)
hou - int(hou)
# Prepare the input array for prediction
input_data = pd.DataFrame({
'Age': [age],
'Education_Level': [edu],
'Occupation': [occ],
'Number_of_Dependents': [num],
'Location': [loc],
'Work_Experience': [wor],
'Marital_Status': [mar],
'Employment_Status': [emp],
'Household_Size': [hou],
'Type_of_Housing': [typ],
'Gender': [gen],
'Primary_Mode_of_Transportation': [pri]
})
# Perform the prediction
prediction = model.predict(input_data)
return prediction[0]
# Create the Gradio interface
interface = gr.Interface(
fn=predict,
inputs=[
gr.Dropdown(choices=list(edu), label='Education_Level'),
gr.Dropdown(choices=list(occ), label='Occupation'),
gr.Dropdown(choices=list(loc), label='Location'),
gr.Dropdown(choices=list(emp), label='Employment_Status'),
gr.Dropdown(choices=list(hom), label='Homeownership_Status'),
gr.Dropdown(choices=list(typ), label='Type_of_Housing'),
gr.Dropdown(choices=list(gen), label='Gender'),
gr.Dropdown(choices=list(pri), label='Primary_Mode_of_Transportation'),
gr.Dropdown(choices=list(mar), label='Marital_Status'),
gr.Textbox(label='Age'),
gr.Textbox(label='Number_of_Dependents'),
gr.Textbox(label='Work_Experience'),
gr.Textbox(label='Household_Size')
],
outputs="text",
title="Household Income Predictor",
description="Enter your information to predict your household income."
)
# Launch the app
interface.launch()