Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -8,7 +8,6 @@ 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)
|
|
@@ -17,26 +16,27 @@ def process_file(file_obj):
|
|
| 17 |
except Exception as e:
|
| 18 |
return f"Error reading file: {e}", None, None
|
| 19 |
|
| 20 |
-
#
|
| 21 |
df = df.dropna(how="all")
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 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"),
|
|
|
|
| 8 |
if file_obj is None:
|
| 9 |
return "Please upload a dataset.", None, None
|
| 10 |
|
|
|
|
| 11 |
try:
|
| 12 |
if file_obj.name.endswith(".xlsx"):
|
| 13 |
df = pd.read_excel(file_obj)
|
|
|
|
| 16 |
except Exception as e:
|
| 17 |
return f"Error reading file: {e}", None, None
|
| 18 |
|
| 19 |
+
# Clean
|
| 20 |
df = df.dropna(how="all")
|
| 21 |
+
|
| 22 |
+
# Check required columns
|
| 23 |
+
required = {"CourseName","NPS","CompletionRate","LearnerSatisfaction","ContentQuality"}
|
| 24 |
+
if not required.issubset(df.columns):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
return "Dataset missing expected columns (NPS, CompletionRate, etc.)", None, None
|
| 26 |
|
| 27 |
+
# Compute QualityScore
|
| 28 |
+
nps_norm = (df["NPS"].astype(float) + 100) / 2
|
| 29 |
+
score = 0.3*nps_norm + 0.3*(df["CompletionRate"].astype(float)*100) \
|
| 30 |
+
+ 0.2*(df["LearnerSatisfaction"].astype(float)/5*100) \
|
| 31 |
+
+ 0.2*df["ContentQuality"].astype(float)
|
| 32 |
+
df["QualityScore"] = score.round(1)
|
| 33 |
+
|
| 34 |
+
bar = px.bar(df, x="CourseName", y="QualityScore", title="Course Quality Score")
|
| 35 |
+
heat = px.imshow(df[["NPS","CompletionRate","LearnerSatisfaction","ContentQuality"]].T,
|
| 36 |
+
x=df["CourseName"], aspect="auto", title="Metrics Heatmap")
|
| 37 |
+
|
| 38 |
+
return df, bar, heat
|
| 39 |
+
|
| 40 |
demo = gr.Interface(
|
| 41 |
fn=process_file,
|
| 42 |
inputs=gr.File(label="Upload CSV/XLSX"),
|