pushpikaLiyanagama's picture
Update app.py
07e7492 verified
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)