Spaces:
Running
Running
| from flask import Flask, render_template, request | |
| import pandas as pd | |
| import joblib | |
| app = Flask(__name__) | |
| model = joblib.load("car_price_model.pkl") | |
| def predict(): | |
| if request.method == "POST": | |
| try: | |
| data = { | |
| 'Brand': request.form['brand'], | |
| 'model': request.form['model'], | |
| 'Year': int(request.form['year']), | |
| 'kmDriven': float(request.form['kmDriven'].replace(',', '').replace(' km', '')), | |
| 'Transmission': request.form['transmission'], | |
| 'Owner': request.form['owner'], | |
| 'FuelType': request.form['fueltype'], | |
| } | |
| data['Age'] = 2025 - data['Year'] # Replace with dynamic year if needed | |
| input_df = pd.DataFrame([data]) | |
| prediction = model.predict(input_df)[0] | |
| result = f"Estimated Price: ₹{int(prediction):,}" | |
| except Exception as e: | |
| result = f"Error: {e}" | |
| return render_template("index.html", result=result) | |
| return render_template("index.html", result=None) | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860) | |