Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import io
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import numpy as np
|
| 4 |
+
import gradio as gr
|
| 5 |
+
import plotly.express as px
|
| 6 |
+
|
| 7 |
+
def process_file(file_obj):
|
| 8 |
+
if file_obj is None:
|
| 9 |
+
return "Please upload a dataset.", None, None
|
| 10 |
+
|
| 11 |
+
# Read file (CSV or Excel)
|
| 12 |
+
try:
|
| 13 |
+
if file_obj.name.endswith(".xlsx"):
|
| 14 |
+
df = pd.read_excel(file_obj)
|
| 15 |
+
else:
|
| 16 |
+
df = pd.read_csv(file_obj)
|
| 17 |
+
except Exception as e:
|
| 18 |
+
return f"Error reading file: {e}", None, None
|
| 19 |
+
|
| 20 |
+
# Auto-clean: drop empty rows, normalize numeric columns
|
| 21 |
+
df = df.dropna(how="all")
|
| 22 |
+
for col in df.select_dtypes(include="object").columns:
|
| 23 |
+
df[col] = df[col].str.strip()
|
| 24 |
+
|
| 25 |
+
# Example: compute a QualityScore if columns exist
|
| 26 |
+
if {"NPS","CompletionRate","LearnerSatisfaction","ContentQuality"}.issubset(df.columns):
|
| 27 |
+
nps_norm = (df["NPS"].astype(float) + 100) / 2
|
| 28 |
+
score = 0.3*nps_norm + 0.3*(df["CompletionRate"].astype(float)*100) \
|
| 29 |
+
+ 0.2*(df["LearnerSatisfaction"].astype(float)/5*100) \
|
| 30 |
+
+ 0.2*df["ContentQuality"].astype(float)
|
| 31 |
+
df["QualityScore"] = score.round(1)
|
| 32 |
+
|
| 33 |
+
bar = px.bar(df, x="CourseName", y="QualityScore", title="Course Quality Score")
|
| 34 |
+
heat = px.imshow(df[["NPS","CompletionRate","LearnerSatisfaction","ContentQuality"]].T,
|
| 35 |
+
x=df["CourseName"], aspect="auto", title="Metrics Heatmap")
|
| 36 |
+
return df, bar, heat
|
| 37 |
+
else:
|
| 38 |
+
return "Dataset missing expected columns (NPS, CompletionRate, etc.)", None, None
|
| 39 |
+
|
| 40 |
+
demo = gr.Interface(
|
| 41 |
+
fn=process_file,
|
| 42 |
+
inputs=gr.File(label="Upload CSV/XLSX"),
|
| 43 |
+
outputs=[gr.Dataframe(), gr.Plot(), gr.Plot()],
|
| 44 |
+
title="Course Quality Tracker"
|
| 45 |
+
)
|
| 46 |
+
|
| 47 |
+
if __name__ == "__main__":
|
| 48 |
+
demo.launch()
|