# app.py import joblib import pandas as pd import gradio as gr # Load the scaler and models scaler = joblib.load("models/scaler.joblib") models = { "processing": joblib.load("models/svm_model_processing.joblib"), "perception": joblib.load("models/svm_model_perception.joblib"), "input": joblib.load("models/svm_model_input.joblib"), "understanding": joblib.load("models/svm_model_understanding.joblib") } def predict(course_overview, reading_file, abstract_materiale, concrete_material, visual_materials, self_assessment, exercises_submit, quiz_submitted, playing, paused, unstarted, buffering): try: input_data = { "course_overview": [course_overview], "reading_file": [reading_file], "abstract_materiale": [abstract_materiale], "concrete_material": [concrete_material], "visual_materials": [visual_materials], "self_assessment": [self_assessment], "exercises_submit": [exercises_submit], "quiz_submitted": [quiz_submitted], "playing": [playing], "paused": [paused], "unstarted": [unstarted], "buffering": [buffering] } input_df = pd.DataFrame(input_data) input_scaled = scaler.transform(input_df) predictions = {} for target, model in models.items(): pred = model.predict(input_scaled) predictions[target] = int(pred[0]) return predictions except Exception as e: return {"error": str(e)} # Define Gradio interface iface = gr.Interface( fn=predict, inputs=[ gr.inputs.Number(label="Course Overview"), gr.inputs.Number(label="Reading File"), gr.inputs.Number(label="Abstract Materiale"), gr.inputs.Number(label="Concrete Material"), gr.inputs.Number(label="Visual Materials"), gr.inputs.Number(label="Self Assessment"), gr.inputs.Number(label="Exercises Submit"), gr.inputs.Number(label="Quiz Submitted"), gr.inputs.Number(label="Playing"), gr.inputs.Number(label="Paused"), gr.inputs.Number(label="Unstarted"), gr.inputs.Number(label="Buffering") ], outputs="json", title="SVM Multi-Target Prediction", description="Enter the feature values to get predictions for processing, perception, input, and understanding." ) if __name__ == "__main__": iface.launch()