Spaces:
Sleeping
Sleeping
File size: 1,700 Bytes
062cb64 197cc17 062cb64 197cc17 062cb64 197cc17 aadfb95 197cc17 062cb64 aadfb95 062cb64 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 | import pandas as pd
import numpy as np
import gradio as gr
import plotly.express as px
def process_file(file_obj):
if file_obj is None:
return "Please upload a dataset.", None, None
try:
if file_obj.name.endswith(".xlsx"):
df = pd.read_excel(file_obj)
else:
df = pd.read_csv(file_obj)
except Exception as e:
return f"Error reading file: {e}", None, None
# Clean
df = df.dropna(how="all")
required = {"CourseName","NPS","CompletionRate","LearnerSatisfaction","ContentQuality"}
if not required.issubset(df.columns):
return "Dataset missing expected columns (NPS, CompletionRate, etc.)", None, None
# Compute QualityScore
nps_norm = (df["NPS"].astype(float) + 100) / 2
score = 0.3*nps_norm + 0.3*(df["CompletionRate"].astype(float)*100) \
+ 0.2*(df["LearnerSatisfaction"].astype(float)/5*100) \
+ 0.2*df["ContentQuality"].astype(float)
df["QualityScore"] = score.round(1)
bar = px.bar(df, x="CourseName", y="QualityScore", title="Course Quality Score")
heat = px.imshow(df[["NPS","CompletionRate","LearnerSatisfaction","ContentQuality"]].T,
x=df["CourseName"], aspect="auto", title="Metrics Heatmap")
return "Dataset processed successfully!", df, bar, heat
demo = gr.Interface(
fn=process_file,
inputs=gr.File(label="Upload CSV/XLSX"),
outputs=[
gr.Textbox(label="Status"), # for messages
gr.Dataframe(label="Cleaned Data"),
gr.Plot(label="Quality Score Bar"),
gr.Plot(label="Metrics Heatmap")
],
title="Course Quality Tracker"
)
if __name__ == "__main__":
demo.launch()
|