import gradio as gr import joblib # Load your saved model # model = joblib.load("ann_model.joblib") # # Define the prediction function def predict(age, hours, education, capital_gain, capital_loss): # features = [[age, hours, education, capital_gain, capital_loss]] # prediction = model.predict(features) prediction = 1 return "Income >50K" if prediction == 1 else "Income <=50K" # Create the Gradio interface interface = gr.Interface( fn=predict, inputs=[ gr.Slider(18, 90, step=1, label="Age"), gr.Dropdown( ["Private", "Self-emp-not-inc", "Self-emp-inc", "Federal-gov", "Local-gov", "State-gov", "Without-pay", "Never-worked"], label="Workclass" ), gr.Dropdown( ["Bachelors", "Some-college", "11th", "HS-grad", "Prof-school", "Assoc-acdm", "Assoc-voc", "9th", "7th-8th", "12th", "Masters", "1st-4th", "10th", "Doctorate", "5th-6th", "Preschool"], label="Education" ), gr.Dropdown( ["Married-civ-spouse", "Divorced", "Never-married", "Separated", "Widowed", "Married-spouse-absent", "Married-AF-spouse"], label="Marital Status" ), gr.Dropdown( ["Tech-support", "Craft-repair", "Other-service", "Sales", "Exec-managerial", "Prof-specialty", "Handlers-cleaners", "Machine-op-inspct", "Adm-clerical", "Farming-fishing", "Transport-moving", "Priv-house-serv", "Protective-serv", "Armed-Forces"], label="Occupation" ), gr.Dropdown( ["Wife", "Husband", "Own-child", "Unmarried", "Other-relative", "Not-in-family"], label="Relationship" ), gr.Dropdown( ["White", "Black", "Asian-Pac-Islander", "Amer-Indian-Eskimo", "Other"], label="Race" ), gr.Dropdown( ["Male", "Female"], label="Gender" ), gr.Slider(1, 90, step=1, label="Hours Per Week"), gr.Slider(0, 100000, step=100, label="Capital Gain"), gr.Slider(0, 5000, step=50, label="Capital Loss"), gr.Dropdown( ["United-States", "Other"], label="Native Country" ) ], outputs="text", title="Adult Income Predictor" ) # Launch the app interface.launch()