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 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 == "Encode Data": categorical_column = ['Attrition', 'BusinessTravel', 'Gender'] data_encoded = df.copy(deep=True) label_encoding = LabelEncoder() data = [["Feature", "Mapping"]] # Create the pandas DataFrame 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)]) #df_dict = pd.DataFrame(data, columns=['Column', 'Mapping']) return data inputs = [ gr.Dropdown(["Display Data", "Describe Data", "Encode Data"], label="Data Actions") ] outputs = [gr.DataFrame()] demo = gr.Interface( fn = data_description, inputs = inputs, outputs = outputs, title="Data Description", allow_flagging=False, ) if __name__ == "__main__": demo.launch()