Spaces:
Sleeping
Sleeping
import gradio as gr | |
from transformers import pipeline | |
# Load the Hugging Face model for income prediction | |
model = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english") | |
def predict_income(features): | |
# Preprocess the input features | |
job_title = features['job_title'] | |
years_of_experience = features['years_of_experience'] | |
education_level = features['education_level'] | |
# Combine the input features into a text string | |
input_text = f"Job Title: {job_title}\nYears of Experience: {years_of_experience}\nEducation Level: {education_level}" | |
# Use the Hugging Face model to predict the income | |
prediction = model(input_text)[0] | |
# Print the prediction for debugging | |
print("Prediction:", prediction) | |
# Return the predicted income | |
return prediction['label'] | |
# Define the input fields for the Gradio interface | |
job_title_input = gr.inputs.Textbox(label="Job Title") | |
years_of_experience_input = gr.inputs.Number(label="Years of Experience") | |
education_level_input = gr.inputs.Dropdown(label="Education Level", choices=["High School", "Bachelor's Degree", "Master's Degree", "PhD"]) | |
# Define the output field for the Gradio interface | |
income_output = gr.outputs.Textbox(label="Predicted Income") | |
# Create the Gradio interface | |
interface = gr.Interface(fn=predict_income, | |
inputs=[job_title_input, years_of_experience_input, education_level_input], | |
outputs=income_output, | |
title="Income Prediction", | |
description="Predict income for female and male employees based on job-related features.") | |
# Launch the Gradio interface | |
interface.launch() | |