pushpikaLiyanagama's picture
Update app.py
82af12a verified
raw
history blame
1.26 kB
from typing import List, Dict
import pandas as pd
import numpy as np
import joblib
scaler = joblib.load("scaler.joblib")
models = {
"processing": joblib.load("svm_model_processing.joblib"),
"perception": joblib.load("svm_model_perception.joblib"),
"input": joblib.load("svm_model_input.joblib"),
"understanding": joblib.load("svm_model_understanding.joblib"),
}
class Model:
def __init__(self):
self.scaler = scaler
self.models = models
def __call__(self, inputs: List[List[float]]) -> List[Dict[str, float]]:
feature_names = [
"course overview", "reading file", "abstract materiale",
"concrete material", "visual materials", "self-assessment",
"exercises submit", "quiz submitted", "playing", "paused",
"unstarted", "buffering"
]
outputs = []
for features in inputs:
input_df = pd.DataFrame([features], columns=feature_names)
scaled_input = self.scaler.transform(input_df)
predictions = {}
for target, model in self.models.items():
predictions[target] = model.predict(scaled_input)[0]
outputs.append(predictions)
return outputs
model = Model()