Skip to content

Commit

Permalink
Merge pull request #9 from Montekkundan/main
Browse files Browse the repository at this point in the history
Added Flask app.
  • Loading branch information
Muhammad Anas committed Sep 24, 2022
2 parents 7b159f7 + e90eced commit d5f7594
Show file tree
Hide file tree
Showing 7 changed files with 358 additions and 1 deletion.
3 changes: 3 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Just go through the [Contributing.md](https://github.com/muhammadanas0716/Machin
| Project Name | Type of Project |Wiki of the Project |
|----------------------------------------------------------------------------------------------------------------------------------------------|------------------|--------------------------------------------------------------------------------------------------------------------------|
| [Heart Disease Classification](https://github.com/muhammadanas0716/Machine-Learning-Projects-101/tree/main/Heart%20Disease%20Classification) | `Classification` | [Wiki Link](https://github.com/muhammadanas0716/Machine-Learning-Projects-101/wiki/Heart-Analysis-Classification-Problem)|
| [Used Car Price Prediction](https://github.com/muhammadanas0716/Machine-Learning-Projects-101/tree/main/Heart%20Disease%20Classification) | `Prediction` | [Wiki Link](https://github.com/muhammadanas0716/Machine-Learning-Projects-101/wiki/Heart-Analysis-Classification-Problem)|
| [Used Car Price Prediction](https://github.com/muhammadanas0716/Machine-Learning-Projects-101/tree/main/Used%20Car%20Price%20Prediction) | `Prediction` | [Wiki Link](https://github.com/muhammadanas0716/Machine-Learning-Projects-101/wiki/Heart-Analysis-Classification-Problem)|



Expand Down
81 changes: 81 additions & 0 deletions Used Car Price Prediction/Flask app/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import numpy as np
from flask import Flask, request, jsonify, render_template
import pickle

app = Flask(__name__)
model = pickle.load(open('../RF_price_predicting_model.pkl', 'rb'))


@app.route('/')
def home():
return render_template('index.html')


@app.route('/predict', methods=['POST'])
def predict():
"""
For rendering results on HTML GUI
"""
data = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
price = request.form.get("price")
data[0] = int(price)
distance = request.form.get("distance")
data[1] = int(distance)
owner = int(request.form.get("owner"))
data[2] = owner
seats = float(request.form.get("seats"))
data[3] = seats
mileage = float(request.form.get("mileage"))
data[4] = mileage
engine = float(request.form.get("engine"))
data[5] = engine
power = float(request.form.get("power"))
data[6] = power
location = request.form.get("location")
if location == 'Bangalore':
data[7] = 1
elif location == 'Chennai':
data[8] = 1
elif location == 'Coimbatore':
data[9] = 1
elif location == 'Delhi':
data[10] = 1
elif location == 'Hydrabad':
data[11] = 1
elif location == 'Jaipur':
data[12] = 1
elif location == 'Kochi':
data[13] = 1
elif location == 'Kolkata':
data[14] = 1
elif location == 'Mumbai':
data[15] = 1
elif location == 'Pune':
data[16] = 1
fuel = request.form.get("fuel")
if fuel == "CNG":
pass
elif fuel == "Diesel":
data[17] = 1
elif fuel == "LPG":
data[18] = 1
elif fuel == "Petrol":
data[19] = 1

transmission = int(request.form.get("transmission"))
data[20] = transmission
# v = [int(x) for x in request.form.values()]
# int_features = [2015, 41000, 1, 5.0, 19.67, 1582.0,
# 126.20, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 1]
final_features = [np.array(data)]
# v_f = [np.array(v)]
prediction = model.predict(final_features)

output = round(prediction[0], 2)

return render_template('index.html', prediction_text=' You can sell the car for {} lakhs'.format(output))
# return render_template('index.html', prediction_text=data)


if __name__ == "__main__":
app.run(debug=True)
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
172 changes: 172 additions & 0 deletions Used Car Price Prediction/Flask app/static/css/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
body {
width: 100%;
height: 100%;
font-family: 'Open Sans', sans-serif;
background: #092756;
color: #fff;
font-size: 18px;
text-align: center;
letter-spacing: 1.2px;
background: linear-gradient(to right, #c31432, #240b36);
overflow: hidden;
}

input {
margin-bottom: 10px;
background: rgba(0, 0, 0, 0.3);
border: none;
outline: none;
padding: 10px;
font-size: 13px;
color: #fff;
text-shadow: 1px 1px 1px rgba(0, 0, 0, 0.3);
border: 1px solid rgba(0, 0, 0, 0.3);
border-radius: 4px;
box-shadow: inset 0 -5px 45px rgba(100, 100, 100, 0.2), 0 1px 1px rgba(255, 255, 255, 0.2);
-webkit-transition: box-shadow .5s ease;
-moz-transition: box-shadow .5s ease;
-o-transition: box-shadow .5s ease;
-ms-transition: box-shadow .5s ease;
transition: box-shadow .5s ease;
}

input:focus {
box-shadow: inset 0 -5px 45px rgba(100, 100, 100, 0.4), 0 1px 1px rgba(255, 255, 255, 0.2);
}

form {
display: flex;
flex-direction: column;
}

.bigd {
display: flex;
flex-direction: row;
justify-content: space-evenly;
}

.btn-click {
align-items: center;
margin-top: 60px;
}

.button-49,
.button-49:after {
width: 150px;
height: 76px;
line-height: 78px;
font-size: 20px;
font-family: 'Bebas Neue', sans-serif;
background: linear-gradient(45deg, transparent 5%, #FF013C 5%);
border: 0;
color: #fff;
letter-spacing: 3px;
box-shadow: 6px 0px 0px #00E6F6;
outline: transparent;
position: relative;
user-select: none;
-webkit-user-select: none;
touch-action: manipulation;
}

.button-49:after {
--slice-0: inset(50% 50% 50% 50%);
--slice-1: inset(80% -6px 0 0);
--slice-2: inset(50% -6px 30% 0);
--slice-3: inset(10% -6px 85% 0);
--slice-4: inset(40% -6px 43% 0);
--slice-5: inset(80% -6px 5% 0);
content: 'PREDICTING';
display: block;
position: absolute;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: linear-gradient(45deg, transparent 3%, #00E6F6 3%, #00E6F6 5%, #FF013C 5%);
text-shadow: -3px -3px 0px #F8F005, 3px 3px 0px #00E6F6;
clip-path: var(--slice-0);
}

.button-49:hover:after {
animation: 1s glitch;
animation-timing-function: steps(2, end);
}

@keyframes glitch {
0% {
clip-path: var(--slice-1);
transform: translate(-20px, -10px);
}
10% {
clip-path: var(--slice-3);
transform: translate(10px, 10px);
}
20% {
clip-path: var(--slice-1);
transform: translate(-10px, 10px);
}
30% {
clip-path: var(--slice-3);
transform: translate(0px, 5px);
}
40% {
clip-path: var(--slice-2);
transform: translate(-5px, 0px);
}
50% {
clip-path: var(--slice-3);
transform: translate(5px, 0px);
}
60% {
clip-path: var(--slice-4);
transform: translate(5px, 10px);
}
70% {
clip-path: var(--slice-2);
transform: translate(-10px, 10px);
}
80% {
clip-path: var(--slice-5);
transform: translate(20px, -10px);
}
90% {
clip-path: var(--slice-1);
transform: translate(-10px, 0px);
}
100% {
clip-path: var(--slice-1);
transform: translate(0);
}
}

@media (min-width: 768px) {
.button-49,
.button-49:after {
width: 200px;
height: 86px;
line-height: 88px;
}
}

.select {
padding: 8px 12px;
color: #333333;
background-color: #eeeeee;
border: 1px solid #dddddd;
cursor: pointer;
border-radius: 5px;
appearance: none;
-webkit-appearance: none;
-moz-appearance: none;
}

.select:focus,
.select:hover {
outline: none;
border: 1px solid #bbbbbb;
}

.select option {
background: #fff
}
100 changes: 100 additions & 0 deletions Used Car Price Prediction/Flask app/templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="UTF-8">
<title>Car Price Prediction </title>
<link rel="icon" type="image/png" href="static/assets/favicon-32x32.png">
<link href='https://fonts.googleapis.com/css?family=Pacifico' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Arimo' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Hind:300' rel='stylesheet' type='text/css'>
<link href='https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300' rel='stylesheet' type='text/css'>
<link rel="stylesheet" href="{{ url_for('static', filename='css/style.css') }}">

</head>

<body>
<div class="login">
<h1>Predict Car Price</h1>
<p>Please fill all the fields.</p>

<!-- Main Input For Receiving Query to our ML -->
<form action="{{ url_for('predict')}}" method="post">
<div class="bigd">
<div>
<p>In what year the car was purchased</p>
<input type="text" name="price" placeholder="1990" required="required" />
<p>What is distance completed by the car in Kilometers ?</p>
<input type="text" name="distance" placeholder="0.00" required="required" />
<p>The number of owners the car had previously ?</p>
<input type="radio" name="owner" id="0" value="1" required> First </input<br>
<input type="radio" name="owner" id="1" value="2" required> Second </input<br>
<input type="radio" name="owner" id="2" value="3" required> Third </input<br>
<input type="radio" name="owner" id="2" value="4" required> Fourth & Above </input<br>
<p>Seats in the Car</p>
<select name="seats" id="seats" class="select" required>
<option value="none" selected disabled hidden>Select an Option</option>
<option value="5.0">5 seats</option>
<option value="7.0">7</option>
<option value="8.0">8</option>
<option value="4.0">4</option>
<option value="6.0">6</option>
<option value="2.0">2</option>
<option value="10.0">10</option>
<option value="9.0">9</option>
</select>
<p>Mileage(km/kg)</p>
<input type="text" name="mileage" placeholder="19.67" required/>
</div>
<div>

<p>Engine(CC)</p>
<input type="text" name="engine" placeholder="19.67" required />
<p>Power(bhp)</p>
<input type="text" name="power" placeholder="19.67" required />
<p>Location</p>
<select name="location" id="location" class="select" required>
<option value="none" selected disabled hidden>Select an Option</option>
<option value="Bangalore">Bangalore</option>
<option value="Chennai">Chennai</option>
<option value="Coimbatore">Coimbatore</option>
<option value="Delhi">Delhi</option>
<option value="Hydrabad">Hydrabad</option>
<option value="Jaipur">Jaipur</option>
<option value="Kochi">Kochi</option>
<option value="Kolkata">Kolkata</option>
<option value="Mumbai">Mumbai</option>
<option value="Pune">Pune</option>
</select>
<p>Fuel type</p>
<input type="radio" name="fuel" id="0" value="CNG" required> CNG </input<br>
<input type="radio" name="fuel" id="1" value="Diesel" required> Diesel </input<br>
<input type="radio" name="fuel" id="2" value="LPG" required> LPG </input<br>
<input type="radio" name="fuel" id="3" value="Petrol" required> Petrol </input<br>
<br>
<p>Transmission</p>
<select name="transmission" id="transmission" class="select" required>
<option value="none" selected disabled hidden>Select an Option</option>
<option value="1">Manual</option>
<option value="0">Automatic</option>
</select>
<br>

</div>
</div>
<div class="btn-click">

<button class="button-49" role="button" type="submit">Predict</button>


</div>
</form>

<br> {{ prediction_text }}

</div>


</body>

</html>
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pandas
matplotlib
seaborn
sklearn
flask

0 comments on commit d5f7594

Please sign in to comment.