Spaces:
Sleeping
Sleeping
Upload 7 files
Browse files- Dockerfile +9 -0
- app.py +32 -0
- car_price_model.pkl +3 -0
- requirements.txt +4 -0
- static/style.css +43 -0
- templates/base.html +14 -0
- templates/index.html +93 -0
Dockerfile
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
COPY . .
|
| 5 |
+
|
| 6 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 7 |
+
|
| 8 |
+
EXPOSE 7860
|
| 9 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, render_template, request
|
| 2 |
+
import pandas as pd
|
| 3 |
+
import joblib
|
| 4 |
+
|
| 5 |
+
app = Flask(__name__)
|
| 6 |
+
model = joblib.load("car_price_model.pkl")
|
| 7 |
+
|
| 8 |
+
@app.route("/", methods=["GET", "POST"])
|
| 9 |
+
def predict():
|
| 10 |
+
if request.method == "POST":
|
| 11 |
+
try:
|
| 12 |
+
data = {
|
| 13 |
+
'Brand': request.form['brand'],
|
| 14 |
+
'model': request.form['model'],
|
| 15 |
+
'Year': int(request.form['year']),
|
| 16 |
+
'kmDriven': float(request.form['kmDriven'].replace(',', '').replace(' km', '')),
|
| 17 |
+
'Transmission': request.form['transmission'],
|
| 18 |
+
'Owner': request.form['owner'],
|
| 19 |
+
'FuelType': request.form['fueltype'],
|
| 20 |
+
}
|
| 21 |
+
data['Age'] = 2025 - data['Year'] # Replace with dynamic year if needed
|
| 22 |
+
input_df = pd.DataFrame([data])
|
| 23 |
+
prediction = model.predict(input_df)[0]
|
| 24 |
+
result = f"Estimated Price: ₹{int(prediction):,}"
|
| 25 |
+
except Exception as e:
|
| 26 |
+
result = f"Error: {e}"
|
| 27 |
+
return render_template("index.html", result=result)
|
| 28 |
+
|
| 29 |
+
return render_template("index.html", result=None)
|
| 30 |
+
|
| 31 |
+
if __name__ == "__main__":
|
| 32 |
+
app.run(host="0.0.0.0", port=7860)
|
car_price_model.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7909bb4293651757fa045142c7d9f2eb6db3b9d55c2f6f8a73b4518b886cbce5
|
| 3 |
+
size 63307082
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Flask
|
| 2 |
+
pandas
|
| 3 |
+
scikit-learn
|
| 4 |
+
joblib
|
static/style.css
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
body {
|
| 2 |
+
font-family: Arial, sans-serif;
|
| 3 |
+
background-color: #f3f3f3;
|
| 4 |
+
color: #333;
|
| 5 |
+
padding: 2rem;
|
| 6 |
+
}
|
| 7 |
+
|
| 8 |
+
.container {
|
| 9 |
+
background: #fff;
|
| 10 |
+
padding: 2rem;
|
| 11 |
+
border-radius: 8px;
|
| 12 |
+
max-width: 600px;
|
| 13 |
+
margin: auto;
|
| 14 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 15 |
+
}
|
| 16 |
+
|
| 17 |
+
label {
|
| 18 |
+
display: block;
|
| 19 |
+
margin: 10px 0;
|
| 20 |
+
}
|
| 21 |
+
|
| 22 |
+
input, select {
|
| 23 |
+
width: 100%;
|
| 24 |
+
padding: 0.5rem;
|
| 25 |
+
margin-top: 5px;
|
| 26 |
+
}
|
| 27 |
+
|
| 28 |
+
button {
|
| 29 |
+
padding: 0.7rem 1.5rem;
|
| 30 |
+
background-color: #2ecc71;
|
| 31 |
+
color: white;
|
| 32 |
+
border: none;
|
| 33 |
+
border-radius: 4px;
|
| 34 |
+
cursor: pointer;
|
| 35 |
+
}
|
| 36 |
+
|
| 37 |
+
.result {
|
| 38 |
+
margin-top: 20px;
|
| 39 |
+
padding: 1rem;
|
| 40 |
+
background-color: #dff0d8;
|
| 41 |
+
color: #3c763d;
|
| 42 |
+
border-radius: 5px;
|
| 43 |
+
}
|
templates/base.html
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<title>Car Price Predictor</title>
|
| 6 |
+
<link rel="stylesheet" href="{{ url_for('static', filename='style.css') }}">
|
| 7 |
+
</head>
|
| 8 |
+
<body>
|
| 9 |
+
<div class="container">
|
| 10 |
+
<h1>🚗 Car Price Predictor</h1>
|
| 11 |
+
{% block content %}{% endblock %}
|
| 12 |
+
</div>
|
| 13 |
+
</body>
|
| 14 |
+
</html>
|
templates/index.html
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{% extends "base.html" %}
|
| 2 |
+
{% block content %}
|
| 3 |
+
<form method="post">
|
| 4 |
+
<!-- Brand Dropdown -->
|
| 5 |
+
<label>Brand:
|
| 6 |
+
<select name="brand" id="brand" required onchange="updateModelOptions()">
|
| 7 |
+
<option value="">-- Select Brand --</option>
|
| 8 |
+
<option value="Honda">Honda</option>
|
| 9 |
+
<option value="Maruti">Maruti</option>
|
| 10 |
+
<option value="Hyundai">Hyundai</option>
|
| 11 |
+
<option value="Tata">Tata</option>
|
| 12 |
+
<option value="Toyota">Toyota</option>
|
| 13 |
+
<option value="Mahindra">Mahindra</option>
|
| 14 |
+
<option value="Kia">Kia</option>
|
| 15 |
+
<option value="Skoda">Skoda</option>
|
| 16 |
+
<option value="Renault">Renault</option>
|
| 17 |
+
<option value="Ford">Ford</option>
|
| 18 |
+
</select>
|
| 19 |
+
</label><br>
|
| 20 |
+
|
| 21 |
+
<!-- Model Dropdown (changes based on brand) -->
|
| 22 |
+
<label>Model:
|
| 23 |
+
<select name="model" id="model" required>
|
| 24 |
+
<option value="">-- Select Model --</option>
|
| 25 |
+
</select>
|
| 26 |
+
</label><br>
|
| 27 |
+
|
| 28 |
+
<label>Year: <input type="number" name="year" required></label><br>
|
| 29 |
+
<label>Kilometers Driven: <input type="text" name="kmDriven" required></label><br>
|
| 30 |
+
<label>Transmission:
|
| 31 |
+
<select name="transmission">
|
| 32 |
+
<option>Manual</option>
|
| 33 |
+
<option>Automatic</option>
|
| 34 |
+
</select>
|
| 35 |
+
</label><br>
|
| 36 |
+
<label>Owner:
|
| 37 |
+
<select name="owner">
|
| 38 |
+
<option>first</option>
|
| 39 |
+
<option>second</option>
|
| 40 |
+
<option>third</option>
|
| 41 |
+
<option>fourth</option>
|
| 42 |
+
<option>fourth & above</option>
|
| 43 |
+
</select>
|
| 44 |
+
</label><br>
|
| 45 |
+
<label>Fuel Type:
|
| 46 |
+
<select name="fueltype">
|
| 47 |
+
<option>Petrol</option>
|
| 48 |
+
<option>Diesel</option>
|
| 49 |
+
<option>CNG</option>
|
| 50 |
+
<option>Electric</option>
|
| 51 |
+
<option>Hybrid</option>
|
| 52 |
+
</select>
|
| 53 |
+
</label><br>
|
| 54 |
+
<button type="submit">Predict</button>
|
| 55 |
+
</form>
|
| 56 |
+
|
| 57 |
+
{% if result %}
|
| 58 |
+
<div class="result">{{ result }}</div>
|
| 59 |
+
{% endif %}
|
| 60 |
+
<script>
|
| 61 |
+
const brandModelMap = {
|
| 62 |
+
"Honda": ["City", "Civic", "Amaze", "Jazz"],
|
| 63 |
+
"Maruti": ["Baleno", "Swift", "Alto", "Dzire"],
|
| 64 |
+
"Hyundai": ["i10", "i20", "Creta", "Verna"],
|
| 65 |
+
"Tata": ["Tiago", "Nexon", "Altroz", "Harrier"],
|
| 66 |
+
"Toyota": ["Innova", "Fortuner", "Glanza", "Etios"],
|
| 67 |
+
"Mahindra": ["XUV500", "Scorpio", "Thar", "Bolero"],
|
| 68 |
+
"Kia": ["Seltos", "Sonet", "Carens"],
|
| 69 |
+
"Skoda": ["Rapid", "Octavia", "Slavia"],
|
| 70 |
+
"Renault": ["Kwid", "Duster", "Triber"],
|
| 71 |
+
"Ford": ["Figo", "Ecosport", "Endeavour"]
|
| 72 |
+
};
|
| 73 |
+
|
| 74 |
+
function updateModelOptions() {
|
| 75 |
+
const brandSelect = document.getElementById("brand");
|
| 76 |
+
const modelSelect = document.getElementById("model");
|
| 77 |
+
const selectedBrand = brandSelect.value;
|
| 78 |
+
|
| 79 |
+
// Clear existing options
|
| 80 |
+
modelSelect.innerHTML = '<option value="">-- Select Model --</option>';
|
| 81 |
+
|
| 82 |
+
if (brandModelMap[selectedBrand]) {
|
| 83 |
+
brandModelMap[selectedBrand].forEach(model => {
|
| 84 |
+
const option = document.createElement("option");
|
| 85 |
+
option.value = model;
|
| 86 |
+
option.textContent = model;
|
| 87 |
+
modelSelect.appendChild(option);
|
| 88 |
+
});
|
| 89 |
+
}
|
| 90 |
+
}
|
| 91 |
+
</script>
|
| 92 |
+
|
| 93 |
+
{% endblock %}
|