from flask import Flask, render_template, request import pickle import numpy as np app = Flask(__name__) # Load model and columns model = pickle.load(open("car_price_model.pkl", "rb")) columns = pickle.load(open("model_columns.pkl", "rb")) # @app.route("/") # def home(): # return "Flask is working!" @app.route("/", methods=["GET", "POST"]) def index(): if request.method == "POST": try: present_price = float(request.form["present_price"]) kms_driven = int(request.form["kms_driven"]) owner = int(request.form["owner"]) car_age = int(request.form["car_age"]) fuel_type = request.form["fuel_type"] company = request.form["company"] # Prepare input dictionary input_data = { "kms_driven": kms_driven, "Owner": owner, "car_age": car_age, "company_" + company: 1, "fuel_type_" + fuel_type: 1 } input_vector = np.zeros(len(columns)) for i, col in enumerate(columns): if col in input_data: input_vector[i] = input_data[col] elif col == 'Present_Price': input_vector[i] = present_price predicted_price = model.predict([input_vector])[0] return render_template("index.html", prediction_text=f"Estimated Selling Price: ₹ {predicted_price:,.2f}") except Exception as e: return render_template("index.html", prediction_text=f"Error: {str(e)}") return render_template("index.html", prediction_text="") if __name__ == "__main__": app.run(debug=True,use_reloader=False)