Spaces:
Build error
Build error
import gradio as gr | |
import pandas as pd | |
from sklearn.preprocessing import LabelEncoder | |
def data_description(desc_type): | |
df = pd.read_csv('emp_experience_data.csv') | |
pd.options.display.max_columns = 25 | |
pd.options.display.max_rows = 10 | |
data_encoded = df.copy(deep=True) | |
categorical_column = ['Attrition', 'Gender', 'BusinessTravel', 'Education', 'EmployeeExperience', 'EmployeeFeedbackSentiments', 'Designation', | |
'SalarySatisfaction', 'HealthBenefitsSatisfaction', 'UHGDiscountProgramUsage', 'HealthConscious', 'CareerPathSatisfaction', 'Region'] | |
label_encoding = LabelEncoder() | |
if desc_type == "Display Data": | |
return df.head() | |
if desc_type == "Describe Data": | |
df_copy = df.copy(deep=True) | |
data_desc = df_copy.describe() | |
data_desc.insert(0, "Description", ["count", "mean", "std", "min", "25%", "50%", "75%", "max"], True) | |
return data_desc | |
if desc_type == "Display Encoding": | |
data = [["Feature", "Mapping"]] | |
for col in categorical_column: | |
data_encoded[col] = label_encoding.fit_transform(data_encoded[col]) | |
le_name_mapping = dict(zip(label_encoding.classes_, label_encoding.transform(label_encoding.classes_))) | |
data.append([col, str(le_name_mapping)]) | |
return data | |
if desc_type == "Display Encoded Data": | |
for col in categorical_column: | |
data_encoded[col] = label_encoding.fit_transform(data_encoded[col]) | |
return data_encoded.head() | |
inputs = [ | |
gr.Dropdown(["Display Data", "Describe Data", "Display Encoding", "Display Encoded Data"], label="Perform Data Actions") | |
] | |
outputs = [gr.DataFrame()] | |
demo = gr.Interface( | |
fn = data_description, | |
inputs = inputs, | |
outputs = outputs, | |
title="Employee-Experience: Data Description", | |
allow_flagging=False | |
) | |
if __name__ == "__main__": | |
demo.launch() |