Atsadawut commited on
Commit
642df24
·
verified ·
1 Parent(s): 877abdb

Upload 4 files

Browse files
Files changed (4) hide show
  1. app.py +73 -0
  2. model.joblib +3 -0
  3. requirements.txt +4 -0
  4. unique_values.joblib +3 -0
app.py ADDED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import joblib
3
+ import numpy as np
4
+ import pandas as pd
5
+
6
+ # Load the model and unique brand values
7
+ model = joblib.load('model.joblib')
8
+ unique_values = joblib.load('unique_values.joblib')
9
+ edu = unique_values['Education_Level']
10
+ occ = unique_values['Occupation']
11
+ loc = unique_values['Location']
12
+ emp = unique_values['Employment_Status']
13
+ hom = unique_values['Homeownership_Status']
14
+ typ = unique_values['Type_of_Housing']
15
+ gen = unique_values['Gender']
16
+ pri = unique_values['Primary_Mode_of_Transportation']
17
+
18
+
19
+
20
+ # Define the prediction function
21
+ def predict(edu, occ, loc, emp, hom, typ, gen, pri, age, num, wor,hou):
22
+ # Convert inputs to appropriate types
23
+ age = int(age)
24
+ num = int(num)
25
+ wor = float(wor)
26
+ hou - int(hou)
27
+
28
+ # Prepare the input array for prediction
29
+ input_data = pd.DataFrame({
30
+ 'Age': [age],
31
+ 'Education_Level': [edu],
32
+ 'Occupation': [occ],
33
+ 'Number_of_Dependents': [num],
34
+ 'Location': [loc],
35
+ 'Work_Experience': [wor],
36
+ 'Marital_Status': [mar],
37
+ 'Employment_Status': [emp],
38
+ 'Household_Size': [hou],
39
+ 'Type_of_Housing': [typ],
40
+ 'Gender': [gen],
41
+ 'Primary_Mode_of_Transportation': [pri]
42
+ })
43
+
44
+ # Perform the prediction
45
+ prediction = model.predict(input_data)
46
+
47
+ return prediction[0]
48
+
49
+ # Create the Gradio interface
50
+ interface = gr.Interface(
51
+ fn=predict,
52
+ inputs=[
53
+ gr.Dropdown(choices=list(edu), label='Education_Level'),
54
+ gr.Dropdown(choices=list(occ), label='Occupation'),
55
+ gr.Dropdown(choices=list(loc), label='Location'),
56
+ gr.Dropdown(choices=list(emp), label='Employment_Status'),
57
+ gr.Dropdown(choices=list(hom), label='Homeownership_Status'),
58
+ gr.Dropdown(choices=list(typ), label='Type_of_Housing'),
59
+ gr.Dropdown(choices=list(gen), label='Gender'),
60
+ gr.Dropdown(choices=list(pri), label='Primary_Mode_of_Transportation'),
61
+ gr.Textbox(label='Age'),
62
+ gr.Textbox(label='Number_of_Dependents'),
63
+ gr.Textbox(label='Work_Experience'),
64
+ gr.Textbox(label='Household_Size')
65
+
66
+ ],
67
+ outputs="text",
68
+ title="Household Income Predictor",
69
+ description="Enter your information to predict your household income."
70
+ )
71
+
72
+ # Launch the app
73
+ interface.launch()
model.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:0e862da8368f3ba6dcdf52ed748b31d27b2d1b0882e56fc26801206c514c7d17
3
+ size 488685
requirements.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ joblib
2
+ pandas
3
+ scikit-learn==1.3.2
4
+ xgboost==2.1.1
unique_values.joblib ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:21057c1b75b14016577d9b531190b5f6b13eb7c514112b50b5da1b219d97d0b4
3
+ size 2921