File size: 3,112 Bytes
1fedaae
5e4ed5c
abbb9cd
1fedaae
 
14120f0
1fedaae
 
 
abbb9cd
1fedaae
abbb9cd
 
1fedaae
 
abbb9cd
1fedaae
cae4728
1fedaae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cae4728
1fedaae
 
 
 
 
 
 
 
 
 
 
111a05b
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
import gradio as gr
import tensorflow as tf
import numpy as np

# Load the pickled model
model = tf.keras.models.load_model("census.h5")

# Define the function for making predictions
def salarybracket(age, workclass, education, education_num, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country):
    inputs = np.array([[age, workclass, education, education_num, marital_status, occupation, relationship, race, gender, capital_gain, capital_loss, hours_per_week, native_country]])
    prediction = model.predict(inputs)
    prediction_value = prediction[0][0]  # Assuming the prediction is a scalar
    result = "Income_bracket lesser than or equal to 50K" if prediction_value <= 0.5 else "Income_bracket greater than 50K"
    return f"Income_bracket Prediction: {prediction_value} \n\nResult: {result}"

    
# Create the Gradio interface
salarybracket_ga = gr.Interface(fn=salarybracket, 
                               inputs = [
                                            gr.Number(13.0, 84.0, label="Age: [13 to 84]"),
                                            gr.Number(1.0, 28.0, label="workclass: [1 to 28]"),
                                            gr.Number(10.0, 32.0, label="education: [10 to 32]"),
                                            gr.Number(0.0, 11.0, label="education_num: [0 to 11]"),
                                            gr.Number(0.0, 1.0, label="marital_status: [0 or 1]"),
                                            gr.Number(0.0, 37.0, label="occupation: [0 to 37]"),
                                            gr.Number(0.0, 37.0, label="relationship: [0 to 37]"),
                                            gr.Number(0.0, 1.0, label="race: [0 or 1]"),
                                            gr.Number(0.0, 30.0, label="gender: [0 to 30]"),
                                            gr.Number(0.0, 1.0, label="capital_gain: [0 or 1]"),
                                            gr.Number(0.0, 19.0, label="capital_loss: [0.0  19.0]"),
                                            gr.Number(0.0, 1.0, label="hours_per_week: [0 or 1]"),
                                            gr.Number(0.0, 1.0, label="native_country: [0 or 1]"),
                                        ],
                                outputs="text", title="Salary Bracket Prediction", 
                               examples = [
                                            [75,0,0,6,6,0,2,1,0,0,0,1,3,0,0],
                                            [25,4,11,9,2,13,2,4,0,0,0,48,38,1,1],
                                            [29,4,1,7,4,3,3,2,1,0,0,40,14,0,0],
                                            [51,5,12,14,2,4,0,4,1,15024,0,50,38,1,1],
                                            [66,0,15,10,2,0,0,4,1,0,1825,40,38,1,1],
                                        ],
                                description="Predicting Income_bracket Prediction Using Machine Learning",
                                theme='dark'
                               )

salarybracket_ga.launch(share=True,debug=True)