File size: 1,607 Bytes
8a6b3d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import joblib
import numpy as np

# Load the scaler and models
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'),
}

# Define the prediction function
def predict(user_input):
    # Ensure the input is in the same order as your model expects
    user_input_array = np.array(user_input).reshape(1, -1)

    # Scale the input using the saved scaler
    user_input_scaled = scaler.transform(user_input_array)

    # Predict outcomes for all target variables
    predictions = {}
    for target, model in models.items():
        prediction = model.predict(user_input_scaled)
        predictions[target] = prediction[0]

    return predictions

# Define Gradio interface
interface = gr.Interface(fn=predict, 
                         inputs=gr.Dataframe(type="numpy", row_count=1, col_count=12, 
                                             headers=['course overview', 'reading file', 'abstract materiale', 
                                                      'concrete material', 'visual materials', 'self-assessment', 
                                                      'exercises submit', 'quiz submitted', 'playing', 'paused', 
                                                      'unstarted', 'buffering']),
                         outputs=gr.JSON(),
                         live=True)

# Launch the interface
interface.launch(share=True)