File size: 1,708 Bytes
7318a93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
4356f0f
 
 
7318a93
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
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()