from flask import Flask, request, render_template, jsonify import joblib import numpy as np app = Flask(__name__) # Load the trained model and scaler (update paths as necessary) model = joblib.load("model_rf.joblib") scaler = joblib.load("scaler.joblib") @app.route("/") def home(): return render_template("index.html") @app.route("/predict", methods=["POST"]) def predict(): try: # Expecting form data from the HTML template CGPA = float(request.form.get("CGPA")) Internships = int(request.form.get("Internships")) Projects = int(request.form.get("Projects")) Workshops_Certifications = int(request.form.get("Workshops_Certifications")) AptitudeTestScore = float(request.form.get("AptitudeTestScore")) SoftSkillRating = float(request.form.get("SoftSkillRating")) ExtracurricularActivities = request.form.get("ExtracurricularActivities") PlacementTraining = request.form.get("PlacementTraining") SSC_Marks = float(request.form.get("SSC_Marks")) HSC_Marks = float(request.form.get("HSC_Marks")) # Convert categorical fields to numerical extra_act = 1 if ExtracurricularActivities.lower() == "yes" else 0 placement_training = 1 if PlacementTraining.lower() == "yes" else 0 # Construct feature vector features = [ CGPA, Internships, Projects, Workshops_Certifications, AptitudeTestScore, SoftSkillRating, extra_act, placement_training, SSC_Marks, HSC_Marks, ] # Scale features and make prediction features_scaled = scaler.transform(np.array(features).reshape(1, -1)) prediction = model.predict(features_scaled) result = "Placed" if prediction[0] == 1 else "Not Placed" return render_template("index.html", prediction=result) except Exception as e: return render_template("index.html", prediction=f"Error: {e}") if __name__ == "__main__": app.run(host="0.0.0.0", port=7860, debug=True)