pushpikaLiyanagama commited on
Commit
50f3b8d
1 Parent(s): 124983d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -29
app.py CHANGED
@@ -1,36 +1,41 @@
1
- from typing import List, Dict
2
- import pandas as pd
3
- import numpy as np
4
  import joblib
 
5
 
6
- scaler = joblib.load("scaler.joblib")
 
7
  models = {
8
- "processing": joblib.load("svm_model_processing.joblib"),
9
- "perception": joblib.load("svm_model_perception.joblib"),
10
- "input": joblib.load("svm_model_input.joblib"),
11
- "understanding": joblib.load("svm_model_understanding.joblib"),
12
  }
13
 
14
- class Model:
15
- def __init__(self):
16
- self.scaler = scaler
17
- self.models = models
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- def __call__(self, inputs: List[List[float]]) -> List[Dict[str, float]]:
20
- feature_names = [
21
- "course overview", "reading file", "abstract materiale",
22
- "concrete material", "visual materials", "self-assessment",
23
- "exercises submit", "quiz submitted", "playing", "paused",
24
- "unstarted", "buffering"
25
- ]
26
- outputs = []
27
- for features in inputs:
28
- input_df = pd.DataFrame([features], columns=feature_names)
29
- scaled_input = self.scaler.transform(input_df)
30
- predictions = {}
31
- for target, model in self.models.items():
32
- predictions[target] = model.predict(scaled_input)[0]
33
- outputs.append(predictions)
34
- return outputs
35
 
36
- model = Model()
 
 
1
+ import gradio as gr
 
 
2
  import joblib
3
+ import numpy as np
4
 
5
+ # Load the scaler and models
6
+ scaler = joblib.load('scaler.joblib')
7
  models = {
8
+ "processing": joblib.load('svm_model_processing.joblib'),
9
+ "perception": joblib.load('svm_model_perception.joblib'),
10
+ "input": joblib.load('svm_model_input.joblib'),
11
+ "understanding": joblib.load('svm_model_understanding.joblib'),
12
  }
13
 
14
+ # Define the prediction function
15
+ def predict(user_input):
16
+ # Ensure the input is in the same order as your model expects
17
+ user_input_array = np.array(user_input).reshape(1, -1)
18
+
19
+ # Scale the input using the saved scaler
20
+ user_input_scaled = scaler.transform(user_input_array)
21
+
22
+ # Predict outcomes for all target variables
23
+ predictions = {}
24
+ for target, model in models.items():
25
+ prediction = model.predict(user_input_scaled)
26
+ predictions[target] = prediction[0]
27
+
28
+ return predictions
29
 
30
+ # Define Gradio interface
31
+ interface = gr.Interface(fn=predict,
32
+ inputs=gr.Dataframe(type="numpy", row_count=1, col_count=12,
33
+ headers=['course overview', 'reading file', 'abstract materiale',
34
+ 'concrete material', 'visual materials', 'self-assessment',
35
+ 'exercises submit', 'quiz submitted', 'playing', 'paused',
36
+ 'unstarted', 'buffering']),
37
+ outputs=gr.JSON(),
38
+ live=True)
 
 
 
 
 
 
 
39
 
40
+ # Launch the interface
41
+ interface.launch()