pushpikaLiyanagama commited on
Commit
511630e
1 Parent(s): ecc3892

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +70 -70
app.py CHANGED
@@ -1,70 +1,70 @@
1
- # app.py
2
-
3
- import joblib
4
- import pandas as pd
5
- import gradio as gr
6
-
7
- # Load the scaler and models
8
- scaler = joblib.load("models/scaler.joblib")
9
- models = {
10
- "processing": joblib.load("models/svm_model_processing.joblib"),
11
- "perception": joblib.load("models/svm_model_perception.joblib"),
12
- "input": joblib.load("models/svm_model_input.joblib"),
13
- "understanding": joblib.load("models/svm_model_understanding.joblib")
14
- }
15
-
16
- def predict(course_overview, reading_file, abstract_materiale, concrete_material, visual_materials,
17
- self_assessment, exercises_submit, quiz_submitted, playing, paused, unstarted, buffering):
18
- try:
19
- input_data = {
20
- "course_overview": [course_overview],
21
- "reading_file": [reading_file],
22
- "abstract_materiale": [abstract_materiale],
23
- "concrete_material": [concrete_material],
24
- "visual_materials": [visual_materials],
25
- "self_assessment": [self_assessment],
26
- "exercises_submit": [exercises_submit],
27
- "quiz_submitted": [quiz_submitted],
28
- "playing": [playing],
29
- "paused": [paused],
30
- "unstarted": [unstarted],
31
- "buffering": [buffering]
32
- }
33
-
34
- input_df = pd.DataFrame(input_data)
35
- input_scaled = scaler.transform(input_df)
36
-
37
- predictions = {}
38
- for target, model in models.items():
39
- pred = model.predict(input_scaled)
40
- predictions[target] = int(pred[0])
41
-
42
- return predictions
43
-
44
- except Exception as e:
45
- return {"error": str(e)}
46
-
47
- # Define Gradio interface
48
- iface = gr.Interface(
49
- fn=predict,
50
- inputs=[
51
- gr.inputs.Number(label="Course Overview"),
52
- gr.inputs.Number(label="Reading File"),
53
- gr.inputs.Number(label="Abstract Materiale"),
54
- gr.inputs.Number(label="Concrete Material"),
55
- gr.inputs.Number(label="Visual Materials"),
56
- gr.inputs.Number(label="Self Assessment"),
57
- gr.inputs.Number(label="Exercises Submit"),
58
- gr.inputs.Number(label="Quiz Submitted"),
59
- gr.inputs.Number(label="Playing"),
60
- gr.inputs.Number(label="Paused"),
61
- gr.inputs.Number(label="Unstarted"),
62
- gr.inputs.Number(label="Buffering")
63
- ],
64
- outputs="json",
65
- title="SVM Multi-Target Prediction",
66
- description="Enter the feature values to get predictions for processing, perception, input, and understanding."
67
- )
68
-
69
- if __name__ == "__main__":
70
- iface.launch()
 
1
+ # app.py
2
+
3
+ import joblib
4
+ import pandas as pd
5
+ import gradio as gr
6
+
7
+ # Load the scaler and models
8
+ scaler = joblib.load("models/scaler.joblib")
9
+ models = {
10
+ "processing": joblib.load("models/svm_model_processing.joblib"),
11
+ "perception": joblib.load("models/svm_model_perception.joblib"),
12
+ "input": joblib.load("models/svm_model_input.joblib"),
13
+ "understanding": joblib.load("models/svm_model_understanding.joblib")
14
+ }
15
+
16
+ def predict(course_overview, reading_file, abstract_materiale, concrete_material, visual_materials,
17
+ self_assessment, exercises_submit, quiz_submitted, playing, paused, unstarted, buffering):
18
+ try:
19
+ input_data = {
20
+ "course_overview": [course_overview],
21
+ "reading_file": [reading_file],
22
+ "abstract_materiale": [abstract_materiale],
23
+ "concrete_material": [concrete_material],
24
+ "visual_materials": [visual_materials],
25
+ "self_assessment": [self_assessment],
26
+ "exercises_submit": [exercises_submit],
27
+ "quiz_submitted": [quiz_submitted],
28
+ "playing": [playing],
29
+ "paused": [paused],
30
+ "unstarted": [unstarted],
31
+ "buffering": [buffering]
32
+ }
33
+
34
+ input_df = pd.DataFrame(input_data)
35
+ input_scaled = scaler.transform(input_df)
36
+
37
+ predictions = {}
38
+ for target, model in models.items():
39
+ pred = model.predict(input_scaled)
40
+ predictions[target] = int(pred[0])
41
+
42
+ return predictions
43
+
44
+ except Exception as e:
45
+ return {"error": str(e)}
46
+
47
+ # Define Gradio interface using the latest syntax
48
+ iface = gr.Interface(
49
+ fn=predict,
50
+ inputs=[
51
+ gr.Number(label="Course Overview"),
52
+ gr.Number(label="Reading File"),
53
+ gr.Number(label="Abstract Materiale"),
54
+ gr.Number(label="Concrete Material"),
55
+ gr.Number(label="Visual Materials"),
56
+ gr.Number(label="Self Assessment"),
57
+ gr.Number(label="Exercises Submit"),
58
+ gr.Number(label="Quiz Submitted"),
59
+ gr.Number(label="Playing"),
60
+ gr.Number(label="Paused"),
61
+ gr.Number(label="Unstarted"),
62
+ gr.Number(label="Buffering")
63
+ ],
64
+ outputs=gr.JSON(),
65
+ title="SVM Multi-Target Prediction",
66
+ description="Enter the feature values to get predictions for processing, perception, input, and understanding."
67
+ )
68
+
69
+ if __name__ == "__main__":
70
+ iface.launch()