File size: 2,396 Bytes
642df24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48c5659
642df24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7821c16
642df24
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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()