|
import gradio as gr |
|
import joblib |
|
import numpy as np |
|
import pandas as pd |
|
|
|
|
|
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'] |
|
|
|
|
|
|
|
|
|
def predict(edu, occ, loc, emp, hom, typ, gen, pri, age, num, wor,hou): |
|
|
|
age = int(age) |
|
num = int(num) |
|
wor = float(wor) |
|
hou - int(hou) |
|
|
|
|
|
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] |
|
}) |
|
|
|
|
|
prediction = model.predict(input_data) |
|
|
|
return prediction[0] |
|
|
|
|
|
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." |
|
) |
|
|
|
|
|
interface.launch() |
|
|