Spaces:
Sleeping
Sleeping
Create app.y
Browse files
app.y
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the Hugging Face model for income prediction
|
| 5 |
+
model = pipeline("text-classification", model="distilbert-base-uncased-finetuned-sst-2-english")
|
| 6 |
+
|
| 7 |
+
def predict_income(features):
|
| 8 |
+
# Preprocess the input features
|
| 9 |
+
job_title = features['job_title']
|
| 10 |
+
years_of_experience = features['years_of_experience']
|
| 11 |
+
education_level = features['education_level']
|
| 12 |
+
|
| 13 |
+
# Combine the input features into a text string
|
| 14 |
+
input_text = f"Job Title: {job_title}\nYears of Experience: {years_of_experience}\nEducation Level: {education_level}"
|
| 15 |
+
|
| 16 |
+
# Use the Hugging Face model to predict the income
|
| 17 |
+
prediction = model(input_text)[0]
|
| 18 |
+
|
| 19 |
+
# Return the predicted income
|
| 20 |
+
return prediction['label']
|
| 21 |
+
|
| 22 |
+
# Define the input fields for the Gradio interface
|
| 23 |
+
job_title_input = gr.inputs.Textbox(label="Job Title")
|
| 24 |
+
years_of_experience_input = gr.inputs.Number(label="Years of Experience")
|
| 25 |
+
education_level_input = gr.inputs.Dropdown(label="Education Level", choices=["High School", "Bachelor's Degree", "Master's Degree", "PhD"])
|
| 26 |
+
|
| 27 |
+
# Define the output field for the Gradio interface
|
| 28 |
+
income_output = gr.outputs.Textbox(label="Predicted Income")
|
| 29 |
+
|
| 30 |
+
# Create the Gradio interface
|
| 31 |
+
interface = gr.Interface(fn=predict_income,
|
| 32 |
+
inputs=[job_title_input, years_of_experience_input, education_level_input],
|
| 33 |
+
outputs=income_output,
|
| 34 |
+
title="Income Prediction",
|
| 35 |
+
description="Predict income for female and male employees based on job-related features.")
|
| 36 |
+
|
| 37 |
+
# Launch the Gradio interface
|
| 38 |
+
interface.launch()
|