|
from flask import Flask, request, jsonify |
|
import joblib |
|
import pandas as pd |
|
|
|
app = Flask(__name__) |
|
|
|
|
|
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"), |
|
} |
|
scaler = joblib.load("scaler.joblib") |
|
|
|
@app.route("/predict", methods=["POST"]) |
|
def predict(): |
|
try: |
|
|
|
input_data = request.json |
|
df = pd.DataFrame([input_data]) |
|
|
|
|
|
df_scaled = scaler.transform(df) |
|
|
|
|
|
predictions = {} |
|
for target, model in models.items(): |
|
predictions[target] = model.predict(df_scaled)[0] |
|
|
|
return jsonify({"success": True, "predictions": predictions}) |
|
except Exception as e: |
|
return jsonify({"success": False, "error": str(e)}) |
|
|
|
if __name__ == "__main__": |
|
app.run(host="0.0.0.0", port=8000) |
|
|