Spaces:
Sleeping
Sleeping
File size: 1,550 Bytes
94bc0d8 80dee1b |
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 |
import gradio as gr
import joblib
from tensorflow.keras.models import load_model
relationship_mapping = {
'Own-child': 3,
'Husband': 0,
'Not-in-family': 1,
'Unmarried': 4,
'Wife': 5,
'Other-relative': 2
}
marital_status_mapping = {
'Never-married': 4,
'Married-civ-spouse': 2,
'Widowed': 6,
'Divorced': 0,
'Separated': 5,
'Married-spouse-absent': 3,
'Married-AF-spouse': 1
}
model_dl = load_model('model_dl_importance.h5')
scaler = joblib.load('scaler.pkl')
def predict_income_dl(relationship, fnlwgt, age, marital_status, model):
rel = relationship_mapping.get(relationship, -1)
mar = marital_status_mapping.get(marital_status, -1)
input_data = [[rel, fnlwgt, age, mar]]
input_data = scaler.transform(input_data)
prediction = model_dl.predict(input_data, verbose=0)
prediction = (prediction > 0.5)
if prediction:
return ">50"
else:
return "<50"
demo = gr.Interface(
fn=predict_income_dl,
inputs=[
gr.Dropdown(choices=list(relationship_mapping.keys()), label="Relationship"),
gr.Text(label="Final Weight"),
gr.Text(label="Age"),
gr.Dropdown(choices=list(marital_status_mapping.keys()), label="Marital Status"),
# input berupa radio button
gr.Radio(
choices=["Random Forest", "Neural Network"],
value="Random Forest",
label="Model",
info="Select model to use"
)
],
outputs="text")
# launch aplikasi
demo.launch(share=True) |