pushpikaLiyanagama
commited on
Commit
•
939b304
1
Parent(s):
1196564
Update app.py
Browse files
app.py
CHANGED
@@ -1,41 +1,36 @@
|
|
1 |
-
import
|
2 |
import joblib
|
3 |
-
import
|
4 |
|
5 |
-
|
6 |
-
|
|
|
7 |
models = {
|
8 |
-
"processing": joblib.load(
|
9 |
-
"perception": joblib.load(
|
10 |
-
"input": joblib.load(
|
11 |
-
"understanding": joblib.load(
|
12 |
}
|
|
|
13 |
|
14 |
-
|
15 |
-
def predict(
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
user_input_scaled = scaler.transform(user_input_array)
|
21 |
|
22 |
-
|
23 |
-
|
24 |
-
for target, model in models.items():
|
25 |
-
prediction = model.predict(user_input_scaled)
|
26 |
-
predictions[target] = prediction[0]
|
27 |
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
|
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 |
-
|
41 |
-
|
|
|
1 |
+
from flask import Flask, request, jsonify
|
2 |
import joblib
|
3 |
+
import pandas as pd
|
4 |
|
5 |
+
app = Flask(__name__)
|
6 |
+
|
7 |
+
# Load models and scaler
|
8 |
models = {
|
9 |
+
"processing": joblib.load("svm_model_processing.joblib"),
|
10 |
+
"perception": joblib.load("svm_model_perception.joblib"),
|
11 |
+
"input": joblib.load("svm_model_input.joblib"),
|
12 |
+
"understanding": joblib.load("svm_model_understanding.joblib"),
|
13 |
}
|
14 |
+
scaler = joblib.load("scaler.joblib")
|
15 |
|
16 |
+
@app.route("/predict", methods=["POST"])
|
17 |
+
def predict():
|
18 |
+
try:
|
19 |
+
# Parse input data from JSON
|
20 |
+
input_data = request.json
|
21 |
+
df = pd.DataFrame([input_data])
|
|
|
22 |
|
23 |
+
# Scale the data
|
24 |
+
df_scaled = scaler.transform(df)
|
|
|
|
|
|
|
25 |
|
26 |
+
# Make predictions for all target variables
|
27 |
+
predictions = {}
|
28 |
+
for target, model in models.items():
|
29 |
+
predictions[target] = model.predict(df_scaled)[0]
|
30 |
|
31 |
+
return jsonify({"success": True, "predictions": predictions})
|
32 |
+
except Exception as e:
|
33 |
+
return jsonify({"success": False, "error": str(e)})
|
|
|
|
|
|
|
|
|
|
|
|
|
34 |
|
35 |
+
if __name__ == "__main__":
|
36 |
+
app.run(host="0.0.0.0", port=8000)
|