Spaces:
Sleeping
Sleeping
Commit Β·
22cbe8d
1
Parent(s): 97f014a
updated new
Browse files
app.py
CHANGED
|
@@ -2,7 +2,6 @@
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import matplotlib.pyplot as plt
|
| 5 |
-
import io
|
| 6 |
|
| 7 |
df = pd.DataFrame()
|
| 8 |
|
|
@@ -83,6 +82,32 @@ def search_employee(query):
|
|
| 83 |
return df[df["Name"].str.lower().str.contains(query.lower())]
|
| 84 |
|
| 85 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
# Build Gradio UI
|
| 87 |
with gr.Blocks() as demo:
|
| 88 |
gr.Markdown("## β¨ Employee Data Analysis Dashboard β¨")
|
|
@@ -94,24 +119,35 @@ with gr.Blocks() as demo:
|
|
| 94 |
with gr.Row():
|
| 95 |
search_box = gr.Textbox(label="π Search Employee")
|
| 96 |
analysis_btn = gr.Button("π Show Analysis")
|
| 97 |
-
|
| 98 |
-
data_table = gr.Dataframe(
|
|
|
|
|
|
|
|
|
|
| 99 |
analysis_output = gr.Markdown()
|
| 100 |
-
|
| 101 |
with gr.Row():
|
| 102 |
salary_btn = gr.Button("π° Salary Chart")
|
| 103 |
performance_btn = gr.Button("π Performance Chart")
|
| 104 |
|
| 105 |
-
# β
Fixed: use "filepath"
|
| 106 |
salary_plot = gr.Image(type="filepath", label="Salary Chart")
|
| 107 |
performance_plot = gr.Image(type="filepath", label="Performance Chart")
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
# Events
|
| 110 |
file_input.change(load_csv, inputs=file_input, outputs=[data_table, status])
|
| 111 |
search_box.submit(search_employee, inputs=search_box, outputs=data_table)
|
| 112 |
analysis_btn.click(show_analysis, inputs=None, outputs=analysis_output)
|
| 113 |
salary_btn.click(salary_chart, inputs=None, outputs=salary_plot)
|
| 114 |
performance_btn.click(performance_chart, inputs=None, outputs=performance_plot)
|
|
|
|
|
|
|
| 115 |
|
| 116 |
if __name__ == "__main__":
|
| 117 |
demo.launch()
|
|
|
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
import matplotlib.pyplot as plt
|
|
|
|
| 5 |
|
| 6 |
df = pd.DataFrame()
|
| 7 |
|
|
|
|
| 82 |
return df[df["Name"].str.lower().str.contains(query.lower())]
|
| 83 |
|
| 84 |
|
| 85 |
+
def show_missing():
|
| 86 |
+
if df.empty:
|
| 87 |
+
return "β οΈ Please load a CSV first!"
|
| 88 |
+
missing = df.isnull().sum()
|
| 89 |
+
percent = (df.isnull().mean() * 100).round(2)
|
| 90 |
+
report = "### π Missing Values Report\n\n"
|
| 91 |
+
for col in df.columns:
|
| 92 |
+
report += f"- **{col}** β {missing[col]} missing ({percent[col]}%)\n"
|
| 93 |
+
return report
|
| 94 |
+
|
| 95 |
+
|
| 96 |
+
def fill_missing():
|
| 97 |
+
global df
|
| 98 |
+
if df.empty:
|
| 99 |
+
return None, "β οΈ Please load a CSV first!"
|
| 100 |
+
|
| 101 |
+
# Fill numeric cols with mean, categorical with mode
|
| 102 |
+
for col in df.columns:
|
| 103 |
+
if df[col].dtype in ["float64", "int64"]:
|
| 104 |
+
df[col] = df[col].fillna(df[col].mean())
|
| 105 |
+
else:
|
| 106 |
+
df[col] = df[col].fillna(df[col].mode()[0] if not df[col].mode().empty else "Unknown")
|
| 107 |
+
|
| 108 |
+
return df, "β
Missing values filled (mean for numeric, mode for categorical)"
|
| 109 |
+
|
| 110 |
+
|
| 111 |
# Build Gradio UI
|
| 112 |
with gr.Blocks() as demo:
|
| 113 |
gr.Markdown("## β¨ Employee Data Analysis Dashboard β¨")
|
|
|
|
| 119 |
with gr.Row():
|
| 120 |
search_box = gr.Textbox(label="π Search Employee")
|
| 121 |
analysis_btn = gr.Button("π Show Analysis")
|
| 122 |
+
|
| 123 |
+
data_table = gr.Dataframe(
|
| 124 |
+
headers=["Name", "Age", "Salary", "Performance Score", "Age Group"],
|
| 125 |
+
label="Employee Data"
|
| 126 |
+
)
|
| 127 |
analysis_output = gr.Markdown()
|
| 128 |
+
|
| 129 |
with gr.Row():
|
| 130 |
salary_btn = gr.Button("π° Salary Chart")
|
| 131 |
performance_btn = gr.Button("π Performance Chart")
|
| 132 |
|
|
|
|
| 133 |
salary_plot = gr.Image(type="filepath", label="Salary Chart")
|
| 134 |
performance_plot = gr.Image(type="filepath", label="Performance Chart")
|
| 135 |
|
| 136 |
+
# π Missing value section
|
| 137 |
+
with gr.Row():
|
| 138 |
+
missing_btn = gr.Button("π Show Missing Values")
|
| 139 |
+
fill_btn = gr.Button("π Fill Missing Values")
|
| 140 |
+
|
| 141 |
+
missing_output = gr.Markdown()
|
| 142 |
+
|
| 143 |
# Events
|
| 144 |
file_input.change(load_csv, inputs=file_input, outputs=[data_table, status])
|
| 145 |
search_box.submit(search_employee, inputs=search_box, outputs=data_table)
|
| 146 |
analysis_btn.click(show_analysis, inputs=None, outputs=analysis_output)
|
| 147 |
salary_btn.click(salary_chart, inputs=None, outputs=salary_plot)
|
| 148 |
performance_btn.click(performance_chart, inputs=None, outputs=performance_plot)
|
| 149 |
+
missing_btn.click(show_missing, inputs=None, outputs=missing_output)
|
| 150 |
+
fill_btn.click(fill_missing, inputs=None, outputs=[data_table, status])
|
| 151 |
|
| 152 |
if __name__ == "__main__":
|
| 153 |
demo.launch()
|