File size: 1,074 Bytes
939b304 7a2af10 939b304 5aee938 939b304 5aee938 939b304 5aee938 939b304 5aee938 939b304 b4231e5 939b304 b4231e5 939b304 7a2af10 939b304 7a2af10 939b304 |
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 |
from flask import Flask, request, jsonify
import joblib
import pandas as pd
app = Flask(__name__)
# Load models and scaler
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:
# Parse input data from JSON
input_data = request.json
df = pd.DataFrame([input_data])
# Scale the data
df_scaled = scaler.transform(df)
# Make predictions for all target variables
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)
|